Jump to content

User:DatRoot/Scripts/TopSection.js

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by DatRoot (talk | contribs) at 14:28, 22 November 2007 (Created page with '* Script to add edit link to top section. * Modified from [[User:Alex_Smotrov/edittop.js]]: if (wgAction == 'view' && wgNamespaceNumber >=0) addOnloadHook(...'). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
/*
 * Script to add edit link to top section.
 * Modified from [[User:Alex_Smotrov/edittop.js]]
 */

if (wgAction == 'view' && wgNamespaceNumber >=0) addOnloadHook(function()
{
    var h2s = document.getElementsByTagName('H2');
    var h2 = h2s[0];
    if (!h2) return;
    if (h2.parentNode.id == 'toctitle') h2 = h2s[1];
    if (!h2) return;
    var span = h2.firstChild;
    if (!span || span.className != 'editsection') return;
    var zero = span.cloneNode(true);
    var parent = document.getElementById("bodyContent");
    parent.insertBefore(zero, parent.firstChild);
    var a = zero.getElementsByTagName('A')[0];
    a.title = a.title.replace(/:.*$/,': 0');
    a.setAttribute('href', a.href.replace(/&section=1/,'&section=0'));
});