User:Anomie/reftooltip.js
From Wikipedia, the free encyclopedia
If a message on your talk page led you here, please be wary of who left it. Code that you insert on this page could contain malicious content capable of compromising your account. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. If this is a .js page, the code will be executed when previewing the page.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
/* Script to footnote text to the tooltips on footnote links. Adapted from http://en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_%28proposals%29&diff=171682254&oldid=171670562 If you want to use this script, simply add the following line to your monobook.js: importScript('User:Anomie/reftooltip.js'); // Linkback: [[User:Anomie/reftooltip.js]] (Please keep the comment so I can see how many people use this). */ function RefTooltips(){ // Get list of footnote links (they all have class: 'reference') var r=getElementsByClassName(document.body, "SUP", "reference"); var a, r, n; for(var i=r.length-1; i>=0; i--){ if(a=r[i].getElementsByTagName("a")[0]){ if(n=document.getElementById(a.href.substr(a.href.indexOf("#")+1))){ n=n.textContent || n.innerText || ""; // Strip the "^" linkback indicator if(n.substr(0,2)=='^ ') n=n.substr(2); // Multiply used refs have letters for each use. Strip them too, or at least the first 701 of them. loop: do { for(var c1=97; c1<123; c1++){ if(n.charCodeAt(0)!=c1 || n.charAt(1)!=' ') break loop; n=n.substr(2); } for(var c1=97; c1<123; c1++){ for(var c2=97; c2<123; c2++){ if(n.charCodeAt(0)!=c1 || n.charCodeAt(1)!=c2 || n.charAt(2)!=' ') break loop; n=n.substr(3); } } } while(false); a.title=n; } } } } if(doneOnloadHook) RefTooltips(); //if imported dynamically else addOnloadHook(RefTooltips);