Jump to content

User:Ll0l00l/gadget-gif-hider.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// hide gifs after mouse-out from image box. return mouse to image for unhide it.
// -- User:ll0l00l 2010-06-05T22:32:36 
// ver 1.1
if ( wgNamespaceNumber >= 0 )
addOnloadHook(function() {
  var gifhiderid=new Number(0);
  if ( wgNamespaceNumber != 0 ) return;
  var ids = ['wikiPreview','bodyContent','mw_contentholder','article'];
  for (var j = 0;j<ids.length;j++)
  {
  var el = document.getElementById( ids[j] );
  if (el)
    {
      var el2 = el.getElementsByTagName( 'a' );
      for (var i=0;i<el2.length;i++)
        {
          if (el2[i].className.match("image"))
            { 
              if (el2[i].href.match('.gif'))
                {
                  gifhiderid++;
                  var innerHTMLtmp = el2[i].innerHTML;
                  var ss = document.createElement('script');
                  ss.type = 'text/javascript';
                  var scr = 'function mouseOver_gifhider'+gifhiderid.toString()+'(){document.getElementById("gifhiderid'+gifhiderid.toString()+'").src ="'+el2[i].getElementsByTagName('img')[0].src+'";}function mouseOut_gifhider'+gifhiderid.toString()+'(){document.getElementById("gifhiderid'+gifhiderid.toString()+'").src ="http://upload.wikimedia.org/wikipedia/commons/d/d2/Blank.png";};';
                  ss.text = scr;
                  var hh = document.getElementsByTagName('head')[0];
                  hh.appendChild(ss);
                  innerHTMLtmp = innerHTMLtmp.replace('<img ','<script type="text/javascript"></script> <img id="gifhiderid'+gifhiderid.toString()+'" onmouseover="mouseOver_gifhider'+gifhiderid.toString()+'();return false"onmouseout="mouseOut_gifhider'+gifhiderid.toString()+'();return true" ');
                  el2[i].innerHTML = innerHTMLtmp;
                }
            }
        }
    }
  }
  return;
});