User:Nichalp/monobook.js
// Useful stuff from Wikipedia:WikiProject_User_scripts
function addToolboxLink(url, name, id){
var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
addlilink(tb, url, name, id);
}
function addlilink(tabs, url, name, id, title, key){
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
if(id) li.id = id;
li.appendChild(na);
tabs.appendChild(li);
if(id) {
if(key && title) ta[id] = [key, title];
else if(key) ta[id] = [key, ''];
else if(title) ta[id] = ['', title];
}
// re-render the title and accesskeys from existing code in wikibits.js
akeytt();
return li;
}
function addTab(url, name, id, title, key){
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
addlilink(tabs, url, name, id, title, key);
}
function addPurge(){
ta['ca-purge'] = ['g', 'Purge the internal cache for this page'];
var x = document.getElementById('ca-history');
if(!x) return;
if(x.children) x = x.children[0].href;
else x = x.childNodes[0].href;
addTab(x.replace(/=history/, "=purge"), 'purge', 'ca-purge');
akeytt();
}
// culled from User:Lupin/popups.js
function nichalp_articleFromURL(h) {
if (typeof h != 'String') h=String(h);
h=decodeURI(h);
var m=RegExp('[^:]*://en\\.wikipedia\\.org/(wiki/|w/index\\.php\\?title=)([^&?]*)').exec(h);
if(m===null) return null;
return m[2];
}
function nichalp_isIpUser(user) {
return RegExp('(User:)?' +
'((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}' +
'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])')
.test(user);
}
function nichalp_removeAnchor(article) {
// is there a #? if not, we're done
var i=article.indexOf('#');
if (i == -1) return article;
return article.substring(0,i);
}
function nichalp_userName(article) {
var i=article.indexOf('User');
var j=article.indexOf(':');
if (i != 0 || j == -1) return null;
var k=article.indexOf('/');
if (k==-1) return article.substring(j+1);
else return article.substring(j+1,k);
}
// do it
function nichalp_customLinks() {
addPurge();
var article=nichalp_articleFromURL(document.location.href);
if (!article) return;
var user=nichalp_userName(article);
if(!user) return;
user=nichalp_removeAnchor(user);
if (!nichalp_isIpUser(user)) {
addToolboxLink('http://tools.wikimedia.de/~interiot/cgi-bin/Tool1/wannabe_kate?username='+user+'&site=en.wikipedia.org', user+"'s edit count", 'toolbox_katestool');
}
var special='http://en.wikipedia.org/w/index.php?title=Special:';
addToolboxLink(special + 'Log&user='+user, user+"'s log", 'toolbox_userlog');
addToolboxLink(special + 'Blockip&ip='+user, 'Block '+user, 'toolbox_blockuser');
addToolboxLink(special + 'Special:Ipblocklist&action=unblock&ip='+user, 'Unblock '+user, 'toolbox_unblockuser');
addToolboxLine(special + 'Special:PrefixIndex');
}
// make it all happen on page load
if (window.addEventListener) window.addEventListener("load",nichalp_customLinks,false);
else if (window.attachEvent) window.attachEvent("onload",nichalp_customLinks);
else {
window._old_nichalp_onload = window.onload;
window.onload = function() { window._old_nichalp_onload(); nichalp_customLinks(); }
}
// This will add an [edit] link at the top of all pages except preview pages and the main page
// by User:Pile0nades
// Add an [edit] link to pages
$(function () {
// if this is preview page or generated page, stop
if(
document.getElementById("wikiPreview") ||
document.getElementById("histlegend") ||
document.getElementById("difference") ||
document.getElementById("watchdetails") ||
document.getElementById("ca-viewsource") ||
window.location.href.indexOf("/wiki/Special:") != -1
) {
if(window.location.href.indexOf("&action=edit§ion=0") != -1) {
document.getElementById("wpSummary").value = "/* Intro */ ";
}
return;
};
// get the page title
var pageTitle = wgPageName;
// create div and set innerHTML to link
var divContainer = document.createElement("div");
divContainer.innerHTML = '
';// insert divContainer into the DOM below the h1
if(window.location.href.indexOf("&action=edit") == -1) {
document.getElementById("content").insertBefore(divContainer, document.getElementsByTagName("h1")[0]);
}
});
//
//Helper tools
mw.loader.load(
'https://en.wikipedia.org/w/index.php?title=User:Voice_of_All/Addtabs/monobook.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s');
//END
//
RfAshowlinks = 'true';
//
function jssubmitclose()
{
var form = document.getElementById('editform');
form.submit();
}
//archive recent promotions
function cratfinish()
{
if (location.href.search(/&jsaction=[SF]RFAunlist&target=/) !=-1)
{
var name = unescape(location.href.split('&target=')[1].split('&target2=')[0]);
var user = unescape(location.href.split('&target2=')[1]);
var listing = "{{" + name + "}}\n----";
var txt=document.editform.wpTextbox1;
if (txt.value.indexOf(listing) == -1){alert('RfA already removed.'); return;}
txt.value = txt.value.replace(listing,'');
alert(name + ' unlisted.');
if (location.href.indexOf('&jsaction=SRFAunlist') !=-1)
{
document.editform.wpSummary.value = "RfA closed, " + user + " promoted.";
}
else if (location.href.indexOf('&jsaction=FRFAunlist') !=-1)
{
document.editform.wpSummary.value = "RfA closed, no consensus to promote " + user + ".";
}
}
//add to recent promotion list
else if (location.href.indexOf('&jsaction=RFAsucadd&target') != -1)
{
var target = unescape(location.href.split('&target=')[1].split('&')[0]);
var name = '{{' + target + '}}' + '\n' + '----';
var txt = document.editform.wpTextbox1;
if (txt.value.indexOf('==Most recent successful nominations==') == -1) return;
var RFA_list = txt.value.split('==Most recent successful nominations==')[1];
var RFAs = RFA_list.match(/\{\{Wikipedia:Requests for adminship\/.+\}\}\n----/ig);
var lastRfA = RFAs[RFAs.length-1];
//remove last RfA
RFA_list=RFA_list.replace(lastRfA,'');
//add new one
txt.value = '==Most recent successful nominations==' + '\n' + name + RFA_list;
document.editform.wpSummary.value += 'Adding "' + target + '".';
//jssubmitclose();
}
//add to recent failure list
else if (location.href.indexOf('&jsaction=RFAfailadd&target=') != -1)
{
addTab("javascript:Alpha_userwait2()", "(Add)", "ca-add", "Add", "");
alert('Add "[NEW]" to the proper alphabetical location and press (add).');
var to_add = unescape(location.href.split('&target=')[1].split('&')[0]);
var name = to_add.split('')[1].split('')[0];
document.editform.wpSummary.value += 'Adding "' + name + '".';
}
}
//
var Alpha_user_done = 0;
function Alpha_userwait2()
{
var to_add = unescape(location.href.split('&target=')[1].split('&')[0]) + '\n';
var name = to_add.split('')[1].split('')[0];
if (Alpha_user_done == 1){alert('Already added.'); return;}
if (document.editform.wpTextbox1.value.indexOf('[NEW]') != -1){Alpha_user_done=1;}
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value.replace('[NEW]',to_add);
}
function CHUlinks()
{
if(document.title.indexOf("Editing Wikipedia:Changing username (section)") == 0)
{
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
addlimenu(tabs, 'Rename results', 'chclosefunc');
var chclosefunc = document.getElementById('chclosefunc').getElementsByTagName('ul')[0];
//Rename results
addlilink(chclosefunc, 'javascript:Cng_UName(1)', 'done', '');
addlilink(chclosefunc, 'javascript:Cng_UName(2)', 'not done', '');
}
}
//
var Cng_UNamealready = 0;
function Cng_UName(type)
{
if (type == 1 && Cng_UNamealready != 1)
{
Cng_UNamealready=1;
document.editform.wpTextbox1.value += "\n" + ":{{done}} Done. ~~~~";
document.editform.wpSummary.value += "Complete.";
}
else if (type == 2 && Cng_UNamealready != 1)
{
Cng_UNamealready=1;
document.editform.wpTextbox1.value += "\n" + ":That username already exists. Please follow the instructions at the top of the page to select an unregistered username. ~~~~";
document.editform.wpSummary.value += ":{{not done}} Username already exists.";
}
}
//navdivs
var hide_rfa_div = '
';var hide_rfa_div2 = '
';function crathide()
{
if (location.href.search(/&oldid=|&diff=|&action=[^p]/) !=-1) return;
if (!RfAshowlinks){RfAshowlinks = 'false'}
if (wgTitle != "Requests for adminship" || wgNamespaceNumber != 4 || RfAshowlinks != 'true') return;
//kill table of contents
//if (document.getElementById('toc')) document.getElementById('toc').innerHTML = '';
var rawhtml = document.getElementById('bodyContent').innerHTML;
newhtml = rawhtml.replace(/(
$1' + hide_rfa_div + '');
newhtml = newhtml.replace(/(