User:Astronouth7303/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.
var ArticlePath = '/wiki';
var ScriptPath = '/w/index.php';
// Copied from Wikiwyg
function getArticleName()
{
var loc = document.location;
var havetitle = false;
var rtn = "";
// Check to see of loc.pathname is ScriptPath+'/index.php'. If it is, then we must use the query string
if ( loc.pathname == (ScriptPath) ) {
var query = loc.search;
try {
rtn = query.match(/[&?]title=([^&]+)/)[1];
} catch(er) {
// No query, or title doesn't exist
return 'Main_Page';
}
} else {
// We're using the conical name
var arti = '';
// Not using a trailing slash below because it may not exist
if (loc.pathname.indexOf(ArticlePath) == 0) {
// Using pretty URLs
arti = loc.pathname.substring(ArticlePath.length, loc.pathname.length);
} else if (loc.pathname.indexOf(ScriptPath) == 0) {
// Using less pretty URLs
arti = loc.pathname.substring(ScriptPath.length, loc.pathname.length);
} else {
return 'Main_Page';
}
if (arti.indexOf('/') == 0) {
arti = arti.substring(1, arti.length);
} else {
return 'Main_Page';
}
rtn = arti;
}
return unescape(rtn);
}
function addTab(id, after, caption, url) {
if (!document.getElementById(id)) {
var edit = document.getElementById(after);
if (!edit) return; //If the previous tab doesn't exist, don't add this one
var editparent = edit.parentNode;
//+
var aseclinkcaption = document.createTextNode(caption)
//'<a href="/index.php?title=User_talk:Astronouth7303&action=edit&section=new">'
var aseclink = document.createElement('a');
aseclink.setAttribute('href',url);
var addsectionlinkcaption = aseclink.appendChild(aseclinkcaption);
//'<li id="ca-addsection">'
var asec = document.createElement('li');
asec.setAttribute('id',id);
var addsectionlink = asec.appendChild(aseclink);
var addsection = editparent.insertBefore(asec,edit.nextSibling);
}
}
function addEditSection() {
var arti = getArticleName();
addTab("ca-editfirst" , 'ca-edit', '0', ScriptPath+"?title="+escape(arti)+"&action=edit§ion=0");
addTab("ca-addsection", 'ca-edit', '+', ScriptPath+"?title="+escape(arti)+"&action=edit§ion=new");
}
if (window.addEventListener) window.addEventListener("load",addEditSection,false);
else if (window.attachEvent) window.attachEvent("onload",addEditSection);