User:Kernigh sockpuppet/monobook.js
Jump to navigation
Jump to search
Note: After saving, 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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
// <pre>
/*
* Monobook script of Kernigh sockpuppet at NetHackWiki - public domain
*
* ATTENTION! Do not copy to MediaWiki:Monobook.js without
* configuring correct main page and changing ca-nstab-user
* to ca-nstab-main.
*/
// customise the script here
scr = new Object();
scr.wikiName = "NetHackWiki"; // from title bar
scr.frontPageName = "User:Jayt/Sandbox/Main Page"; // from title bar
scr.frontPagePhp = "User:Jayt/Sandbox/Main_Page"; // from index.php?title=
/*
* Monobook "front page" formatting script
* by Kernigh - public domain
*
* The purpose of this script is remove the heading from
* the wiki's front page and to rename the article tab.
*/
// is this article being the named page?
function isNamedPage( wikiName, pageName ) {
return document && document.title && document.title.indexOf &&
document.title.indexOf( pageName + " - " + wikiName ) == 0;
}
// use DOM to remove siteSub, firstHeading
function removeFirstHeading() {
if( document && document.getElementById && document.getElementsByTagName ) {
var h1s = document.getElementsByTagName( "h1" );
var siteSub = document.getElementById( "siteSub" );
if( h1s && h1s.item ) {
var firstHeading = h1s.item(0);
if( firstHeading && firstHeading.parentNode && firstHeading.parentNode.removeChild )
firstHeading.parentNode.removeChild( firstHeading );
}
if( siteSub && siteSub.parentNode && siteSub.parentNode.removeChild )
siteSub.parentNode.removeChild( siteSub );
}
}
if( isNamedPage( scr.wikiName, scr.frontPageName ) )
addOnloadHook( removeFirstHeading );
// does the article tab go to the named page?
function isNearNamedPage( wikiName, pageName ) {
if( isNamedPage( wikiName, pageName ) ) return true;
if( isNamedPage( wikiName, "Talk:" + pageName ) ) return true;
// else check the title= argument in the url
if( document && document.URL ) {
var url = document.URL + "&";
return url.indexOf( "?title=" + scr.frontPagePhp + "&" ) > -1 ||
url.indexOf( "?title=Talk:" + scr.frontPagePhp + "&" ) > -1 ||
url.indexOf( "&title=" + scr.frontPagePhp + "&" ) > -1 ||
url.indexOf( "&title=Talk:" + scr.frontPagePhp + "&" ) > -1;
}
return false;
}
// use DOM to rename "article" tab to "front page"
function formatFrontPageTab() {
if( document && document.getElementById ) {
var mainTab = document.getElementById( "ca-nstab-user" );
if( document.createTextNode && mainTab && mainTab.firstChild ) {
var frontPageLink = mainTab.firstChild;
var frontPageText = document.createTextNode("front page");
if( frontPageLink.replaceChild && frontPageLink.firstChild )
frontPageLink.replaceChild( frontPageText, frontPageLink.firstChild );
}
}
}
if ( isNearNamedPage( scr.wikiName, scr.frontPageName ) )
addOnloadHook( formatFrontPageTab );