User:Dnessett/Template/Bref/Clean Back Links.js
Jump to navigation
Jump to search
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
- Konqueror: simply click the Reload button, or press F5;
- Opera users may need to completely clear their cache in Tools→Preferences.
Warning: Malicious code can compromise your account. Page preview will cause your web browser to execute this page's content as code under some skins, including Monobook. If you have any questions about any code you plan to add, you can ask at the appropriate reading room. |
Documentation for this script can be added at User:Dnessett/Template/Bref/Clean Back Links. |
// Helper Javascript code that removes backlinks and upper arrows from <references/> formated data.
// Useful for text that calls the Bref template, since in that case backlinks point to display:none text.
var brefElementNodeType = 1;
function BrefHideBackLinks()
{
// Create array of all Tags with classname "references" and tagName "ol"
var brefAllReferencesTags = new Array();
brefAllReferencesTags = getElementsByClassName(document.body, "ol","references");
//Loop through list elements, blanking text in all child nodes other than <cite> and <span>
for (var i in brefAllReferencesTags)
{
var brefRefList = brefAllReferencesTags[i].childNodes;
for (var j in brefRefList)
{
// Leave embedded text between citation entries alone
if (brefRefList[j].nodeType == brefElementNodeType)
{
var brefRefListEntry = brefRefList[j].childNodes;
for (var k = brefRefListEntry.length - 1; k >= 0; --k)
{
// Only retain the <cite> and <span> tag text. Handle IE as well as other browsers
if (brefRefListEntry[k].nodeType != brefElementNodeType || (brefRefListEntry[k].tagName != "CITE" && brefRefListEntry[k].tagName != "SPAN"))
{
if (brefRefListEntry[k].innerText) // IE inner node
{
brefRefListEntry[k].innerText = "";
}
else if( brefRefListEntry[k].nodeName && brefRefListEntry[k].nodeName == "#text")
{ // IE list entry text
brefRefListEntry[k].nodeValue = "";
}
else if (brefRefListEntry[k].textContent)
{ // Others
brefRefListEntry[k].textContent = "";
}
}
}
}
}
}
}
//
// hook BrefHideBackLinks
//
addOnloadHook
(
function ()
{
BrefHideBackLinks();
}
);