மீடியாவிக்கி:Gadget-TwoColumn.js
//&lt;source lang=&quot;javascript&quot;&gt;
 /* TwoColumns, version [0.0.5]
 Documentation: Wikipedia:WikiProject User scripts/Scripts/TwoColumns
 */
 
 if (mw.config.get('wgAction') == 'view' &amp;&amp; mw.config.get('wgCanonicalNamespace')=='')  $(fr_format)
 
 var fr_columns;
 var imgRegExp= /(thumb|frame)/i;
 var trashNodes;
 function fr_format() {
      fr_addButton();
      fr_columns=fr_getCookie ('fr_columns'); if (! (0&lt;1*fr_columns)) fr_columns=1;
      trashNodes=new Array;
      if (fr_columns==1) return;
      var bodyContent= document.getElementById('bodyContent');
      if (! bodyContent || ! bodyContent.innerHTML || bodyContent.innerHTML=='') return;
 
      var allNodes=bodyContent.childNodes;
      var group=new Array, node, groupArea=0;
      for (var i = allNodes.length-1; 0 &lt;= i; i--) {
        node=allNodes[i];
        var pre= node.tagName==&quot;PRE&quot; || (node.tagName==&quot;DIV&quot; &amp;&amp; node.childNodes[1] &amp;&amp; node.childNodes[1].tagName=='PRE') 
        if (node.nodeValue &amp;&amp; node.nodeValue.substr(0,1)==&quot;\n&quot;) {
 
 //       } else if (node.tagName==&quot;p&quot; || node.tagName==&quot;P&quot; || node.tagName==&quot;ul&quot; || node.tagName==&quot;UL&quot; ) {
        } else if (node.tagName &amp;&amp; node.tagName.substr(0,1) !=&quot;H&quot; &amp;&amp; node.tagName.substr(0,5) !=&quot;TABLE&quot; &amp;&amp; node.tagName.substr(0,5) !=&quot;SCRIPT&quot; &amp;&amp; node.style.MozColumnCount&lt;=0 &amp;&amp; ! pre) { //everything but H
          group.push(node);
          groupArea += node.clientHeight * node.clientWidth;
        } else {
           if (node.tagName &amp;&amp; node.tagName.substr(0,1) ==&quot;H&quot;) {
             var prevNode=node;
             var count=0;
             do {
               do {
                 prevNode=prevNode.previousSibling;count++;
               } while (prevNode &amp;&amp; (prevNode.clientHeight==0 || prevNode.clientHeight=== undefined));
               if (prevNode &amp;&amp; prevNode.className &amp;&amp; imgRegExp.test(prevNode.className)) {
                 group.push(prevNode); i=i-count;count=0;
                 groupArea += prevNode.clientHeight * prevNode.clientWidth;
               }
             } while (prevNode &amp;&amp; prevNode.className &amp;&amp; imgRegExp.test(prevNode.className))
          }
          if (0&lt;group.length) fr_layoutDiv (group, groupArea);
          group=new Array; groupArea=0;
        }
      }
      
      for (var i=trashNodes.length-1; 0&lt;=i;i--) {
       trashNodes[i].parentNode.removeChild(trashNodes[i]);
      }
 }
 
 function fr_layoutDiv (aGroup, groupArea) {
   var contentWidth=aGroup[0].parentNode.clientWidth;
   if (groupArea &lt; 100 * contentWidth) return;
   var start=0, stop=aGroup.length-1;
   var pieces=Math.round(groupArea / (window.innerHeight * contentWidth)+0.5);
   var targetArea=groupArea/ pieces; 
   var targetHeight= (pieces==1) ? window.innerHeight : targetArea / contentWidth;
   var divArea=0, first=true, imgHeight=0;
   for (var i = stop; 0 &lt;= i; i--) {
      if (aGroup[i].className &amp;&amp; imgRegExp.test(aGroup[i].className)) {
        imgHeight +=aGroup[i].clientHeight;
      }
     divArea += aGroup[i].clientHeight * aGroup[i].clientWidth;
     if (targetArea &lt; divArea || targetHeight &lt; imgHeight) { 
       fr_createDiv(aGroup, i+1,stop,fr_columns,first); 
       first=false;
       stop=i; 
        if (aGroup[i].className &amp;&amp; imgRegExp.test(aGroup[i].className)) {
          imgHeight =aGroup[i].clientHeight;
        } else {
          imgHeight =0;
        }
       divArea = aGroup[i].clientHeight * aGroup[i].clientWidth;
     }
   }
   if (0&lt;=stop) {
     divArea=0;
     for (i=stop; 0&lt;=i;i--) {
       divArea += aGroup[i].clientHeight * aGroup[i].clientWidth;
     }
     if (100 * contentWidth &lt; divArea) fr_createDiv(aGroup,0,stop,fr_columns,first);
   }
 }
 
 
 function fr_createDiv(aGroup, start, stop, columns, noHR) { // start, stop: inclusive, (counting in the Group !), e.g. 0..3
   if (stop&lt;start) return;
   var newDiv = document.createElement('div');
   newDiv.style.MozColumnCount=columns;
   newDiv.style.MozColumnGap='2em';
   newDiv.style.textAlign='justify';
   var tooBig=false;
   for (var i = stop; start &lt;= i; i--) { // first append the thumb
       if (imgRegExp.test(aGroup[i].className)) {
         newNode=aGroup[i].cloneNode(true);
         newDiv.appendChild(newNode);
         if (imgRegExp.test(aGroup[i].className) &amp;&amp; aGroup[i].parentNode.clientWidth / columns &lt; newNode.clientWidth) {
           tooBig=true;
         }
       }
   }
   for (var i = stop; start &lt;= i; i--) {
       if (!imgRegExp.test(aGroup[i].className)) {
         newNode=aGroup[i].cloneNode(true);
         newDiv.appendChild(newNode)
       }
   }
   if (window.innerHeight &lt; newDiv.clientHeight || tooBig /* window.innerHeight-10 &lt; imgHeight */) { // safety valve: too big 
      return;
   }
   aGroup[start].parentNode.insertBefore(newDiv,aGroup[start]);
   if (!noHR) {
       var HR=document.createElement('HR');
       newDiv.parentNode.insertBefore(HR,newDiv);
   }
   for (var i = stop; start &lt;= i; i--) { 
       trashNodes.push(aGroup[i]); //newDiv.parentNode.removeChild(aGroup[i])
   }
 }
 
 // Button to increment the number of columns
 
 function fr_addButton () {
     var node = document.getElementById('p-personal');
     if ( !node ) return null;
     node = node.getElementsByTagName( &quot;ul&quot; )[0];
     if ( !node ) return null;
 
     var link = document.createElement( &quot;img&quot; );
   link.src= '//upload.wikimedia.org/wikipedia/commons/f/f5/FastReader_logo.PNG';
     link.appendChild( document.createTextNode( &quot;விரைவுப் படிப்பான்&quot; ) );
     link.onclick = function() {fr_next()};
 
     var item = document.createElement( &quot;li&quot; );
     item.appendChild( link );
 
     link.setAttribute( &quot;title&quot;, 'விரைவுப் படிப்பான்' );
 
     node.appendChild( item );  // IE compatibility (?)
 }
 
 function fr_next() {
   fr_columns= fr_columns % 2 +1;
   fr_setCookie('fr_columns', fr_columns);
   document.location.reload();
 };
 
 // Cookie routines to save the number of columns
 
 function fr_getCookie (cookieName) {
 
     var cookie = ' ' + document.cookie;
     var search = ' ' + cookieName + '=';
     var cookieValue = '';
     var offset = 0;
     var end = 0;
     offset = cookie.indexOf(search);
     if (offset != -1) {
         offset += search.length;
         end = cookie.indexOf(';', offset)
         if (end == -1) {
             end = cookie.length;
         }
         cookieValue = cookie.substring(offset, end);
         cookieValue = cookieValue.replace(/\\+/g, ' ');
         cookieValue = decodeURIComponent(cookieValue);
     }
     return(cookieValue);
 }
 
 function fr_setCookie (name, value) {
     var cookie = name + '=' + encodeURIComponent(value);
     var cookieExpire = new Date();
     expires = cookieExpire.setTime(cookieExpire.getTime() + 30 * 24 * 60 * 60 * 1000);
     expires = cookieExpire.toUTCString();
     cookie += '; expires=' + expires;
     document.cookie = cookie;
     return;
 }