User:Nihiltres/vector.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:Nihiltres/vector.css. |
//DEFINE STUFF IN ITS OWN LITTLE HIERARCHY HERE (hierarchy currently messy, needs cleanup, but better than raw code floating around)
nothingthree = {
util: {
linkFix: function(id, text) {
// Tab name fixer, originally copied from User:Anomie/fix-tab-text.js, credit to Anomie :)
/* A simple javascript function to change the text in various tabs at the top of the
* page.
*/
var el=document.getElementById(id);
if (!el) return;
for(el=el.firstChild; el && el.nodeName!='A'; el=el.nextSibling);
if(!el) return;
while(el.firstChild) el.removeChild(el.firstChild);
el.appendChild(document.createTextNode(text));
}, //end linkfix
cookie: { //These cookie functions are copied from [[User:Quarl/cookie.js]], which as of the copy had only been edited by Quarl.
set: function(name, value, days, path) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} //end if
else {var expires = "";}
// use path="" for no path; path=null defaults to root
if (path == null) {path = "/";}
if (path) {path = "; path="+path;}
else {path = "";}
document.cookie = name + "=" + value + expires + path;
}, //end set
get: function(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) {return c.substring(nameEQ.length,c.length);}
} //end for
return null;
}, //end get
erase: function(name) {
createCookie(name,"",-1);
} //end erase
} //end cookie
}, //end util
tabAdd: {
log: function() {
//Adds a link to the log of actions performed by the user
addPortletLink('p-personal','/wiki/Special:Log?user=' + wgUserName,'Log','pt-log','Log of your non-edit actions','',document.getElementById('pt-mycontris'));
if (wgPageName == "Special:Log" && document.getElementById('mw-log-user').value == wgUserName) {document.getElementById('pt-log').className='active';}
}, //end log
sandbox: function() {
//Adds a link to the user's very own sandbox page, where the sandbox is equivalent to [[Special:MyPage/Sandbox]].
addPortletLink('p-personal','/wiki/User:' + wgUserName +'/Sandbox','Sandbox','pt-sandbox','Your sandbox','',document.getElementById('pt-preferences'));
if (wgPageName == 'User:' + wgUserName + '/Sandbox') {document.getElementById('pt-sandbox').className='active'; }
}, //end sandbox
purge: function() {
//Adds a link to purge the current page.
if (wgCanonicalNamespace != 'Special') {
addPortletLink('p-cactions', wgServer + wgScript + '?title=' + encodeURI(wgPageName) + '&action=purge', 'Purge', 'ca-purge', 'Purge the server cache of this page', null, (document.getElementById('ca-watch') ? document.getElementById('ca-watch') : document.getElementById('ca-unwatch')));
} //end if
// if (wgAction == "purge") {document.getElementById('ca-purge').className='selected';}
// above is disabled as it doesn't make sense in Vector, but I *should* write some stuff so that it works when it's in p-views.
} //end purge
}, //end tabAdd
watchMediawikiSpaceEdits: function() {
if (wgCanonicalNamespace == 'MediaWiki' && wgAction == "edit") {document.getElementById('wpWatchthis').checked = true;}
}, //end watchMediawikiSpaceEdits
tabMove: {
core: function(id, followingElement) { //THIS BIT IS REALLY, REALLY UGLY. I want to use the Usability team one as soon as I can make it work properly.
var itemToBeMoved = document.getElementById(id);
if (!itemToBeMoved || !document.getElementById("p-views") ) return;
document.getElementById("p-views").getElementsByTagName("ul")[0].insertBefore(document.getElementById(id), document.getElementById(followingElement));
itemToBeMoved.firstChild.innerHTML = "<span>" + itemToBeMoved.firstChild.innerHTML + "</span>"; //so that it looks pretty… :|
}, //end core
protection: function() {
//if the page is protected, show the unprotect button; serves also as an indicator for protection, indicating the value in the title. Disabled on iPod as generally unhelpful there.
if ( (wgRestrictionEdit.concat( wgRestrictionMove )).length > 0 && !(navigator.userAgent.match(/iPhone/i)) && !(navigator.userAgent.match(/iPod/i))) {
nothingthree.tabMove.core("ca-unprotect", "ca-history");
if ( wgRestrictionEdit.length > 0 ) {
var EditRestrictionString = "edit: [" + wgRestrictionEdit.join(", ") + "]";
}
else {
var EditRestrictionString = "";
}
if ( wgRestrictionMove.length > 0 ) {
var MoveRestrictionString = "move: [" + wgRestrictionMove.join(", ") + "]";
}
else {
var MoveRestrictionString = "";
}
var RestrictionStringsArray = new Array();
if (EditRestrictionString != "") {
RestrictionStringsArray.push(EditRestrictionString)
}
if (MoveRestrictionString != "") {
RestrictionStringsArray.push(MoveRestrictionString)
}
document.getElementById("ca-unprotect").firstChild.title = ("Unprotect this page (" + RestrictionStringsArray.join(", ") + ")");
}
}, //end protection
deletion: function() {
if (document.getElementsByClassName("ambox-speedy").length >= 1 || document.getElementsByClassName("ambox-delete").length >= 1 || document.getElementsByClassName("ombox-speedy").length >= 1 || document.getElementsByClassName("ombox-delete").length >= 1 || document.getElementsByClassName("imbox-speedy").length >= 1 || document.getElementsByClassName("imbox-delete").length >= 1 || document.getElementsByClassName("cmbox-speedy").length >= 1 || document.getElementsByClassName("cmbox-delete").length >= 1 || document.getElementsByClassName("tmbox-speedy").length >= 1 || document.getElementsByClassName("tmbox-delete").length >= 1 ) {
nothingthree.tabMove.core("ca-delete", "ca-history");
}
else {
if (document.getElementsByClassName("redirectText").length == false) return;
if (document.getElementsByClassName("redirectText").item(0).firstChild.href.search("redlink=1") != -1) {
nothingthree.tabMove.core("ca-delete", "ca-history");
var cadeletelinks = document.getElementById("ca-delete").getElementsByTagName("a");
if (cadeletelinks.length != 1) return;
cadeletelinks.item(0).href = cadeletelinks.item(0).href + "&wpReason=%5B%5BWP%3ACSD%23G8%7CG8%5D%5D%3A%20Redirect%20to%20a%20deleted%20page";
} //end if
} //end else
}, //end deletion
}, //end tabMove
sidebar: {
collapse: function() {
var ct = document.getElementById("content");
var ln = document.getElementById("left-navigation");
var pn = document.getElementById("panel");
var hb = document.getElementById("head-base");
var ft = document.getElementById("footer");
if (!ct || !ln || !pn || !hb || !ft) return;
pn.style.display = "none";
ct.style.marginLeft = "0";
hb.style.marginLeft = "0";
ft.style.marginLeft = "0";
ln.style.left = "1em";
if (!document.getElementById("ca-sidebar")) {return;}
else {
var cs = document.getElementById("ca-sidebar");
cs.firstChild.href = "javascript:nothingthree.sidebar.expand()"
} //end else
}, //end expand
expand: function() {
var ct = document.getElementById("content");
var ln = document.getElementById("left-navigation");
var pn = document.getElementById("panel");
var hb = document.getElementById("head-base");
var ft = document.getElementById("footer");
if (!ct || !ln || !pn || !hb || !ft) return;
pn.style.display = "block";
ct.style.marginLeft = "10em";
hb.style.marginLeft = "10em";
ft.style.marginLeft = "10em";
ln.style.left = "10em";
if (!document.getElementById("ca-sidebar")) {return;}
else {
var cs = document.getElementById("ca-sidebar");
cs.firstChild.href = "javascript:nothingthree.sidebar.collapse()"
} //end else
}, //end collapse
toggleTab: function() {
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) return;
addPortletLink('p-cactions', 'javascript:nothingthree.sidebar.collapse()', 'Toggle sidebar', 'ca-sidebar', 'Hide or show the sidebar', null, 'ca-purge');
}
}, //end sidebar
tops: {
hide: function() {
var cul = document.getElementById("bodyContent").getElementsByTagName("ul")[0];
var cli = cul.getElementsByTagName("li");
var lin = 0;
for (lin=0; lin < cli.length; lin++) {
if (cli[lin].innerHTML.indexOf('<span class="mw-uctop">') != -1) {
cli[lin].style.visibility = "hidden";
} //end if
} //end for
nothingthree.util.cookie.set("sideBarCollapsed", "collapsed", "365", null);
if (!document.getElementById("ca-tops")) {return;}
else {
document.getElementById("ca-tops").firstChild.href = "javascript:nothingthree.tops.show()";
}
}, //end hide
show: function() {
var cul = document.getElementById("bodyContent").getElementsByTagName("ul")[0];
var cli = cul.getElementsByTagName("li");
var lin = 0;
for (lin=0; lin < cli.length; lin++) {
if (cli[lin].innerHTML.indexOf('<span class="mw-uctop">') != -1) {
cli[lin].style.visibility = "visible";
} //end if
} //end for
nothingthree.util.cookie.set("sideBarCollapsed", "expanded", "365", null);
if (!document.getElementById("ca-tops")) {return;}
else {
document.getElementById("ca-tops").firstChild.href = "javascript:nothingthree.tops.hide()";
}
}, //end show
toggleTab: function() {
if (document.body.className.indexOf("page-Special_Contributions") != -1 && !navigator.userAgent.match(/iPhone/i) && !navigator.userAgent.match(/iPod/i)) {
addPortletLink('p-cactions', 'javascript:nothingthree.tops.hide()', 'Toggle (top) entries', 'ca-tops', 'Hide or show the (top) entries', null, 'ca-sidebar');
} //end if
}, //end toggleTab
remember: function() {
if (nothingthree.util.cookie.get("sideBarCollapsed") == "collapsed") {nothingthree.tops.hide}
} //end remember
} //end tops
} //end nothingthree
//ENABLE STUFF FOR USE HERE
addOnloadHook(function() {
//First, fix some links, using linkFix
nothingthree.util.linkFix('pt-preferences', 'Preferences');
nothingthree.util.linkFix('pt-watchlist', 'Watchlist');
nothingthree.util.linkFix('pt-mytalk', 'Talk');
nothingthree.util.linkFix('pt-mycontris', 'Contributions');
//Second, add the tabs as desired
nothingthree.tabAdd.log();
nothingthree.tabAdd.sandbox();
nothingthree.tabAdd.purge();
//Some miscellaneous additions… try to get these into better sections next time this is fixed!
nothingthree.watchMediawikiSpaceEdits();
nothingthree.tabMove.protection();
nothingthree.tabMove.deletion();
nothingthree.sidebar.toggleTab();
nothingthree.tops.toggleTab();
nothingthree.tops.remember();
});