window.refresh_interval = window.refresh_interval || 30;
var scaleboxes = function() {
  var mult = window.innerHeight / document.body.clientHeight;
  if (mult >= 1) return;
  mult = mult + ((1 - mult) / 4);
  var x = document.querySelectorAll('div.scalable a.outer');
  for (var i = 0; i < x.length; i++) {
    var y = x[i];
    y.style.width = Math.floor(200 * mult) + "px";
    y.style.height = Math.floor(120 * mult) + "px";
  }
  x = document.querySelectorAll('div.scalable a.outer div.inner');
  for (var i = 0; i < x.length; i++) {
    var y = x[i];
    y.style.height = Math.floor(120 * mult) + "px";
    y.style.lineHeight = Math.floor(120 * mult / 4) + "px";
    y.style.fontSize = Math.floor(120 * mult / 6) + "px";
  }
};
var scaletext = function() {
  var x = document.querySelectorAll('div.scalable .inner > span > span')
  for (var i = 0; i < x.length; i++) {
    var y = x[i];
    var z = y.parentNode
    var multi = (z.offsetWidth * 0.8) / y.offsetWidth
    if (multi < 1) {
      y.style.fontSize = (multi * 100) + '%'
    }
  }
};
var onerror = function() {
  document.body.innerHTML = '<div class="time">' + Date() + ' (<span id="countdown">' + refresh_interval + '</span>)</div><h1>ERROR</h1>';
};
var onsuccess = function(request) {
  var doc = document.implementation.createHTMLDocument("example");
  doc.documentElement.innerHTML = request.response;
  document.head.innerHTML=doc.head.innerHTML;
  document.body.innerHTML=doc.body.innerHTML;
  scaleboxes()
  scaletext();
};
setInterval(function() {
  var request = new XMLHttpRequest();
  request.open('GET', location.href, true);
  request.onload = function() {
    if (request.status >= 200 && request.status < 400) {
      onsuccess(request);
    } else {
      onerror();
    }
  };
  request.onerror = onerror;
  request.send();
}, refresh_interval * 1000);
setInterval(function() {
  var el = document.getElementById('countdown');
  if(el) {
    var counter = parseInt(el.innerText, 10);
    el.innerText = counter - 1;
  }
}, 1000);
scaleboxes()
scaletext();

@@ -93,16 +93,29 @@
  mult = 
+1.0;%0A  while(
 window.i
@@ -125,17 +125,17 @@
 rHeight 
-/
+%3C
  documen
@@ -157,69 +157,37 @@
 ight
-;%0A  if (mult %3E= 1) return;%0A  mult = mult + ((1 - mult) / 4);%0A
+) %7B%0A    mult = mult * 0.95%0A  
   va
@@ -239,24 +239,26 @@
  a.outer');%0A
+  
   for (var i
@@ -280,32 +280,34 @@
 gth; i++) %7B%0A    
+  
 var y = x%5Bi%5D;%0A  
@@ -296,32 +296,34 @@
   var y = x%5Bi%5D;%0A
+  
     y.style.widt
@@ -349,32 +349,34 @@
 * mult) + %22px%22;%0A
+  
     y.style.heig
@@ -411,22 +411,60 @@
 + %22px%22;%0A
+  
   %7D%0A  
+%7D%0A%0A  setTimeout(function()%7B%0A    var 
 x = docu
@@ -522,16 +522,18 @@
 er');%0A  
+ 
+ 
 for (var
@@ -553,32 +553,34 @@
 .length; i++) %7B%0A
+  
     var y = x%5Bi%5D
@@ -581,24 +581,26 @@
 = x%5Bi%5D;%0A    
+  
 y.style.heig
@@ -631,32 +631,34 @@
 lt) + %22px%22;%0A    
+ 
+ 
 y.style.lineHeig
@@ -697,24 +697,26 @@
 + %22px%22;%0A    
+  
 y.style.font
@@ -761,44 +761,17 @@
 x%22;%0A
+  
   %7D%0A
-%7D;%0Avar scaletext = function() %7B%0A
+%0A  
   va
@@ -839,16 +839,18 @@
  span')%0A
+  
   for (v
@@ -876,24 +876,26 @@
 gth; i++) %7B%0A
+  
     var y = 
@@ -900,24 +900,26 @@
 = x%5Bi%5D;%0A    
+  
 var z = y.pa
@@ -927,16 +927,18 @@
 entNode%0A
+  
     var 
@@ -983,16 +983,18 @@
 etWidth%0A
+  
     if (
@@ -1008,24 +1008,26 @@
  1) %7B%0A      
+  
 y.style.font
@@ -1057,21 +1057,35 @@
 '%25'%0A    
+  
 %7D%0A  
+ 
-%7D
+ %7D%0A  %7D, 10);
 %0A%7D;%0Avar 
@@ -1515,23 +1515,8 @@
 s()%0A
-  scaletext();%0A
 %7D;%0As
@@ -2030,16 +2030,64 @@
  1000);%0A
+%0Awindow.addEventListener(%22load%22, function() %7B%0A  
 scalebox
@@ -2095,17 +2095,8 @@
 s()%0A
-scaletext(
+%7D
 );%0A

Improve box/text scaling code