User:Ms2ger/monobook.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
The accompanying .css page for this skin is at User:Ms2ger/monobook.css. |
// Even/odd classes for sortable tables
ts_alternate_row_colors = true;
// Extra buttons
// function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode)
// Simplified edit section 0 ([[User:ais523/editsection0tab.js]])
function addLeadSectionEditTab() {
var hist = document.getElementById("ca-history");
if (hist) {
addPortletLink(
"p-cactions",
mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=edit§ion=0",
"0",
"ca-edit-0",
"Edit the lead section of this page",
"o",
hist
);
}
}
// Null edit tab ([[User:Happy-melon/global.js]])
function addNullEditTab() {
addPortletLink(
'p-cactions',
mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + encodeURIComponent(mw.config.get('wgPageName')) + '&action=edit&nulledit=true',
'null',
'p-null',
'Null edit this page'
);
}
// Purge
function addPurgeTab() {
var plinks = document.getElementsByClassName('purgelink');
if (plinks) {
while (plinks[0]) {
plinks[0].parentNode.removeChild(plinks[0]); // Hide all purgelinks
}
}
var print = document.getElementById('t-print');
if (print) {
print.getElementsByTagName("a")[0].accessKey = ""; // Get rid of the "p" accesskey
}
var editlead = document.getElementById("ca-edit-0");
if (editlead) {
addPortletLink(
"p-cactions",
mw.config.get('wgServer')+mw.config.get('wgScript')+"?title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=purge",
"Purge",
"ca-purge",
"Purge this page's cache",
"p",
editlead
);
}
}
// Logs
function addLogsTab() {
var nexttab = document.getElementById("ca-move") || document.getElementById("ca-history");
if (nexttab) {
addPortletLink(
"p-cactions",
mw.config.get('wgServer')+mw.config.get('wgScript')+"?title=Special:Log&page="+encodeURIComponent(mw.config.get('wgPageName')),
"Logs",
"ca-logs",
"View logs for this page",
null,
nexttab
);
}
}
function addUnthumbTab() {
var title = mw.config.get('wgPageName');
var imagetitle = title;
imagetitle = imagetitle.substring(imagetitle.indexOf(':') + 1); // strip off "Image:" namespace
// Add an "unthumb" link. For Image:123px-Foo, links to Image:Foo.
if (imagetitle.match(/^\d+px-/)) {
// imagetitle = imagetitle.substring(imagetitle.indexOf("px-") + 3);
bigimagetitle = imagetitle.replace(/^\d+px-/, '');
addPortletLink(
"p-cactions",
"/wiki/Image:" + bigimagetitle,
"unthumb",
"ca-unthumb",
"unthumb this image",
"",
document.getElementById("ca-watch")
);
}
}
function addRandomTemplate() {
addPortletLink(
"p-navigation",
mw.config.get('wgServer')+mw.config.get('wgScript')+"?title=Special:Random/Template",
"Random template",
"n-randomtemplate",
"Load a random template",
"",
document.getElementById("n-randompage")
);
}
// Collapse within {{WikiProjectBanners}}
function collapseWPs() {
if (!document.querySelector || !document.querySelectorAll)
return;
var wpbs = document.querySelectorAll('.wpbs');
if (!wpbs || !wpbs.length)
return;
for (var i = 0, il = wpbs.length; i < il; i++)
wpbs[i].className += " mbox-inside";
var tables = document.querySelectorAll('.wpbs>tbody>tr>td[class=""]>table.wpb');
if (!tables)
return;
for (var j = 0, jl = tables.length; j < jl; j++) {
var header = tables[j].querySelector('.wpb-header>th')
if (!header)
continue;
collapseTable(tables[j].getAttribute("id").substring(16));
var leftButton = document.createElement( "span" );
leftButton.style.cssFloat = "left"; // Real browsers
leftButton.style.styleFloat = "left"; // IE
leftButton.style.fontWeight = "normal";
leftButton.style.textAlign = "left";
leftButton.style.width = "6em";
leftButton.appendChild( document.createTextNode( "\u00a0" ) ); // nbsp
header.insertBefore( leftButton, header.childNodes[0] );
}
appendCSS('.wpbs>tbody>tr{display:table-row!important} .wpbs>tbody>tr>td[class=""]>table.wpb>tbody>tr.wpb-header{display:table-row}');
}
function infoboxes() {
if (!document.querySelectorAll)
return;
var maxwidth
= 0.5 * parseInt(getComputedStyle(document.getElementById("bodyContent"),
null).width,
10);
for (var i = 0, list = document.querySelectorAll(".infobox"), l = list.length;
i < l;
++i) {
if (parseInt(getComputedStyle(list[i], null).width, 10) > maxwidth)
list[i].className += "fullwidth";
}
}
function createMatrix() {
var ns = "http://www.w3.org/2000/svg";
var filter = document.createElementNS(ns, "filter");
filter.id = "gray-filter";
var matrix = document.createElementNS(ns, "feColorMatrix");
matrix.setAttribute("values",
"0.3333 0.3333 0.3333 0 0 \
0.3333 0.3333 0.3333 0 0 \
0.3333 0.3333 0.3333 0 0 \
0 0 0 1 0");
document.body
.appendChild(document.createElementNS(ns, "svg"))
.appendChild(filter)
.appendChild(matrix);
}
addOnloadHook(createMatrix);
addOnloadHook(collapseWPs);
// install [[User:Cacycle/wikEd]] in-browser text editor
// importScript("User:Cacycle/wikEd.js");
addOnloadHook(addLeadSectionEditTab);
addOnloadHook(addPurgeTab);
addOnloadHook(addLogsTab);
addOnloadHook(addUnthumbTab);
addOnloadHook(addRandomTemplate);
addOnloadHook(function() { setTimeout(infoboxes, 500); });
if(wgNamespaceNumber != -1 && wgArticleId != 0)
addOnloadHook(addNullEditTab);