User:Greenpickle/monobook.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
document.write('<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEdDiff.js&action=raw&ctype=text/javascript&"></script>\n<script type="text/javascript" src="http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js&action=raw&ctype=text/javascript"></script>');
include = false;
RCNSTList = ['User', 'User talk', 'User blog', 'User blog talk', 'User blog comment', 'User blog comment talk', 'User avatar log', 'User creation log'];
RCNSTPageListInclude = [];
RCNSTPageListExclude = [];
RCNSTbeforecheckboxes = '<span id="rcnst"><hr />\n';
RCNSTaftercheckboxes = '</span>';
RCNSTbeforecheckbox = '';
RCNSTaftercheckbox = '\n';
document.write('<script type="text/javascript" src="http://pikminwiki.com/index.php?title=User:Greenpickle/rcnst.js&action=raw&ctype=text/javascript"></script>');
function getElementsByClassName (cls, node) {
if (node === undefined) node = document;
var result = [];
var pool = node.getElementsByTagName("*");
var re = new RegExp('\\b' + cls + '\\b');
for (var i = 0; i < pool.length; i++)
if (re.test(pool[i].className)) result.push(pool[i]);
return result;
}
function switchableCreateTab (label, isAnchor, i, j) {
var tab = document.createElement('li');
var child;
if (isAnchor) {
child = document.createElement('a');
child.setAttribute('href', '#');
child.setAttribute('onclick', 'switchableSetVisible(' + i + ', ' + j + ');');
} else child = document.createElement('strong');
child.appendChild(document.createTextNode(label));
tab.appendChild(child);
return tab;
}
function switchableGetVisible (i) {
var visible = switchable[i].getAttribute('visiblesection');
if (visible) visible = parseInt(visible);
if (visible === null || isNaN(visible)) {
visible = 0;
switchable[i].setAttribute('visiblesection', visible.toString());
}
return visible;
}
function switchableUpdateVisible (i) {
if (isNaN(parseInt(i))) {
// update all switchables if no valid number given
for (var i = 0; i < switchable.length; i++)
switchableUpdateVisible(i);
} else {
var visible = switchableGetVisible(i);
var sections = switchable[i].sections;
var p = switchable[i].tabContainer;
var currentTab;
for (var j = 0; j < sections.length; j++) {
if (j == visible) {
// change 'show' link
currentTab = switchableCreateTab(sections[j].sectionName, false);
currentTab.j = j;
p.replaceChild(currentTab, p.tabs[j]);
// show section if hidden
if (sections.hidden[j] !== undefined) {
switchable[i].appendChild(sections[j]);
sections.hidden[j] = undefined;
}
} else {
// change 'show' link
if (p.currentTab !== undefined && p.currentTab.j == j)
p.replaceChild(p.tabs[j], p.currentTab);
// hide section if visible
if (sections.hidden[j] === undefined)
sections.hidden[j] = switchable[i].removeChild(sections[j]);
}
}
if (currentTab !== undefined) p.currentTab = currentTab;
}
}
function switchableSetVisible (i, j) {
switchable[i].setAttribute('visiblesection', j);
switchableUpdateVisible(i);
}
// initial show/hide
function initialiseSwitchable () {
// get the elements we care about
switchable = getElementsByClassName('switchable');
for (var i = 0; i < switchable.length; i++) {
var sections = getElementsByClassName('switch', switchable[i]);
sections.hidden = Array(sections.length);
switchable[i].sections = sections;
// create show/hide anchors
var tabContainer = document.createElement('ul');
switchable[i].appendChild(tabContainer);
switchable[i].tabContainer = tabContainer;
tabContainer.tabs = [];
for (var j = 0; j < sections.length; j++) {
// re-append section to place it after links
switchable[i].appendChild(sections[j]);
// use section's name if it has one
var sectionName = sections[j].getAttribute('sectionname');
if (!sectionName) sectionName = j.toString();
sections[j].sectionName = sectionName;
// create anchor
var tab = switchableCreateTab(sectionName, true, i, j);
tabContainer.appendChild(tab);
tabContainer.tabs.push(tab);
}
}
this.switchable = switchable;
switchableUpdateVisible();
}
if (window.addEventListener !== undefined)
window.addEventListener('load', initialiseSwitchable, false);
else if (window.attachEvent !== undefined)
window.attachEvent('onload', initialiseSwitchable);
else window.onload = initialiseSwitchable;