User:GorillaWarfare/monobook.js

From Wikipedia, the free encyclopedia

If a message on your talk page led you here, please be wary of who left it. The code below could contain malicious content capable of compromising your account; if your account appears to be compromised, it will be blocked. If you are unsure whether the code is safe, you can ask at the appropriate village pump.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
importScript('Wikipedia:WikiProject User scripts/Scripts/qPreview');
 
importScript('Wikipedia:WikiProject User scripts/Scripts/Easy db');
 
importScript('Wikipedia:WikiProject User scripts/Scripts/afd helper');
 
importScript('Wikipedia:WikiProject User scripts/Scripts/welcome new user');
 
 
importScript('User:Lupin/popups.js');
 
importScript('Wikipedia:WikiProject User scripts/Scripts/User contribs tabs');
 
importScript('Wikipedia:WikiProject User scripts/Scripts/Status switcher');
 
importScript('Wikipedia:WikiProject User scripts/Scripts/Easy db');
 
importScript("User:Lupin/recent2.js");
 
// install [[User:Cacycle/wikEd]] in-browser text editor
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Cacycle/wikEd.js'
+ '&action=raw&ctype=text/javascript"></' + 'script>');
 
importScript('Wikipedia:WikiProject User scripts/Scripts/CleanupTab.js');
 
importScript('Wikipedia:WikiProject User scripts/Scripts/Revert tools');
 
 
 
////////////////////////////////////////////////////////////////
// =-=-=- HELPER FUNCTIONS -=-=-=-
function addlilink(tabs, url, name, id, title, key)
{
//check for duplicates
if (document.getElementById(id)){return;}
//cologne blue bypass
if (document.getElementById('quickbar'))
{
if (document.getElementById('quickbar') && document.getElementById('quickbar').getElementsByTagName('h6')[0])
{
addquickbarlink(url, name, id, title, 'Edit');
}
if (document.getElementById('footer') && !document.getElementById('bodyContent'))
{
addfooterlink(url, name, id, title);
}
return;
}
//monobook
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 insertAfter(parent, node, referenceNode) {
parent.insertBefore(node, referenceNode.nextSibling);
}
 
function prependChild(parent, node) {
parent.insertBefore(node, parent.firstChild);
}
 
function addToolboxLink(url, name, id, key)
{
if (document.getElementById('p-tb'))
{var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];}
addlilink(tb, url, name, id, key);
}
 
function addTab(url, name, id, title, key)
{
//monobook
if (document.getElementById('p-cactions'))
{var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];}
//cologneblue
else {
if (document.getElementById('quickbar'))
{var tabs = document.getElementById('quickbar').getElementsByTagName('h6')[2];}
if (document.getElementById('footer'))
{var tabs = document.getElementById('footer').getElementsByTagName('td')[0];}
return addquickbarlink(url, name, id, 'Edit');
}
return addlilink(tabs, url, name, id, title, key);
}
 
///////////////
//cologneblue tab/link adder
function addquickbarlink(url, name, id, title, header)
{
var header = '<h6>' + header + '</h6>';
var tabs = document.getElementById('quickbar'); 
if (tabs.innerHTML.indexOf(header) ==-1)
{return;}
var add_html = '<strong><a id="' + id + '" title="' + title + '" href="' + url + '">' + name + '</a></strong><br />';
var section_html = tabs.innerHTML.split(header)[1].split('<h6>')[0];
var next_section = '<h6>' + tabs.innerHTML.split(header)[1].split('<h6>')[1].split('</h6>')[0] + '</h6>';
tabs.innerHTML = tabs.innerHTML.split(header)[0] + header + section_html + add_html + next_section + tabs.innerHTML.split(next_section)[1];
}
 
function addfooterlink(url, name, id, title)
{
var tabs = document.getElementById('footer').getElementsByTagName('td')[1]; 
var add_html = '<strong><a href="' + url + '" title="' + title + '" id="' + id + '">' + name + '</a></strong>';
tabs.innerHTML = add_html + ' | ' + tabs.innerHTML;
}
///////////////
 
function addLink(where, url, name, id, title, key, after){
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);
var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
if(after) {
	tabs.insertBefore(li,document.getElementById(after));
} else {
	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;
}
/////////////////////////////////////////////
 
/**** Add generic tab ****/
 
function addlilink_simple(tabs, url, name, id){
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.id = id;
li.appendChild(na);
tabs.appendChild(li);
return li;
}
 
function addlimenu(tabs, name, id)
{
var na = document.createElement('a');
na.href = '#';
var mn = document.createElement('ul');
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.id = id;
li.className = 'tabmenu';
li.appendChild(na);
li.appendChild(mn);
tabs.appendChild(li);
return li;
}
 
/////////
//These are simplier versions of the above, except they add the links on top, not on botton
function addnavbox_link(URL,Name,ID)
{
//cologne blue bypass
if (document.getElementById('quickbar') && document.getElementById('quickbar').getElementsByTagName('h6')[0])
{
var tabs = document.getElementById('quickbar'); 
addquickbarlink(URL, Name, ID, Name, 'Browse');
return;
}
//monobook
var portlet = document.getElementById('p-navigation');
var links = portlet.getElementsByTagName('ul')[0];
links.innerHTML += '<li id="' + ID + '"><a href="' + URL + '">' + Name + '</a></li>';
}
//////////
 
function URLEncoding(input)
{
var encodedInputString=escape(input);
encodedInputString=encodedInputString.replace(/\+/g, "%2B");
encodedInputString=encodedInputString.replace(/\//g,"%2F");  
encodedInputString=encodedInputString.replace(/&/g,"%26");     
var outputurl=encodedInputString;
return outputurl;
}
 
function toRegExp(what)
{
what = what.replace(/\\/g,"\\\\");
what = what.replace(/\(/g,"\\(").replace(/\)/g,"\\)");
what = what.replace(/\{/g,"\\{").replace(/\}/g,"\\}");
what = what.replace(/\[/g,"\\[").replace(/\]/g,"\\]");
what = what.replace(/\|/g,"\\|");
what = what.replace(/\./g,"\\.");
what = what.replace(/\$/g,"\\$");
what = what.replace(/\+/g,"\\+");
what = what.replace(/\^/g,"\\^");
what = what.replace(/\?/g,"\\?");
what = what.replace(/\*/g,"\\*");
what = what.replace(/\//g,"\\/");
return what;
}
 
if (document.implementation.createDocument)
{var gml_xmlparser = new DOMParser();}
 
function standard_XMLParse(string) 
{
if (document.implementation.createDocument)
{
return gml_xmlparser.parseFromString(string, "text/xml");
} 
else if (window.ActiveXObject) 
{
string = string.replace(/<body .*\"ns-(.*)\">/, '<body class="ns-$1">');
rer = string.match(/<h1 .*<\/h1>/)[0].replace(/&/g, '&');
if (rer) {string = string.replace(/<h1 .*<\/h1>/, rer);}
var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM");
gml_xmldoc.async = false;
ret = gml_xmldoc.loadXML(string);
myErr = gml_xmldoc.parseError;
		if (myErr.errorCode || !ret)
{
			showError("Error: " + ERROR_XML + myErr.reason);
			return null;
		}
		return gml_xmldoc.documentElement
}
return null;
}
 
function HTTPClient()
{
var xml_http = false;
if(window.XMLHttpRequest)
xml_http = new XMLHttpRequest();
else if (IE){
try{
xml_http = new ActiveXObject("Msxml2.XMLHTTP")
} catch (e){
try{
xml_http = new ActiveXObject("Microsoft.XMLHTTP")
} catch (e){}
}
}
	if (!xml_http) showError(ERROR_XML);
return xml_http
};
 
 
 
 
// Helper tools
document.write('<script type="text/javascript" src="' 
+ 'http://en.wikipedia.org/w/index.php?title=User:Voice_of_All/Addtabs/monobook.js' 
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
 
importScript('User:VoA/monobook.js');
 
//[[Category:Wikipedians who use RC script]]
 
// UTC clock
document.write('<script type="text/javascript" src="' 
+ 'http://en.wikipedia.org/w/index.php?title=User:Voice_of_All/UTCclock.js' 
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//
//
 
//<pre><nowiki>
//note: this script MUST be added to the end of your monobook at all times.
//so when you add a new script to the end of your monobook, re-order them so this one is on the bottom.
addOnloadHook(function() {
	if(!document.getElementById('wpSummary') || document.getElementById('wpSummary').value != '' || !document.getElementById('wpTextbox1')) return;
	var my_value;
	if(wgCanonicalNamespace == 'User_talk') {
		if(wgPageName.indexOf('/') == -1 && wgTitle.split('/')[0] != wgUserName) 
			my_value = 'Respond to '+wgTitle;
		else if(wgPageName.indexOf('archive') != -1 && wgTitle.split('/')[0] != wgUserName) 
			my_value = 'Reviving archive';
		else if(wgPageName.indexOf('archive') != -1 && wgTitle.split('/')[0] == wgUserName)
			my_value = 'Archiving...';
		else if(wgPageName.indexOf('/') == -1 && wgTitle.split('/')[0] == wgUserName) 
			my_value = 'Reply';
		else
			my_value = 'minor edit';
	} else if(wgCanonicalNamespace == 'User') {
		if(wgTitle.split('/')[0] == wgUserName)
			my_value = 'fixing';
		else
			my_value = 'fixing a minor mistake';
 
		             //note: leave as "Project". thats how mediawiki outputs it
	} else if(wgCanonicalNamespace == 'Project'||wgCanonicalNamespace == 'Project_talk') {
		if((/\w+ for deletion/i).test(wgTitle))
			my_value = 'Add my opinion';
		else if((/requests for adminship/i).test(wgTitle))
			my_value = 'Support';
		else if((/administrator.s noticeboard/i).test(wgTitle)) 
			my_value = 'Reply';
		else if((/administrator intervention against vandalism/i).test(wgTitle))
			my_value = 'Reporting user';
		else
			my_value = 'Reply';
	} else {
		my_value = 'minor edit';
	}
	document.getElementById('wpSummary').value = my_value;
	document.getElementById('wpSummary').onfocus = function() {
		if(this.value != my_value) return;
		this.selectionStart = 0;
		this.selectionEnd = this.value.length;
	}
});
//</nowiki></pre>
 
//Load IP info. Written by GeorgeMoney using Wizardry Dragon's API
var data_ipinfo = new Object();
function ip_callback(data) {
data_ipinfo = data;
}
try { 
var ip_regex = /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/;
if(ip_regex.test(wgTitle)
||ip_regex.test(location.href.split('/')[location.href.split('/').length - 1].split('?')[0])
||ip_regex.test(location.href.split('target=')[1].split('&')[0])
) {
var ip_use = ip_regex.test(wgTitle)?wgTitle:location.href.replace(/^.*?(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*?$/, '$1');
document.write('<script src="http://hemlock.knams.wikimedia.org/~wizardrydragon/lookup_hostmask.php?ip='+ip_use+'&format=json&lang='+wgContentLanguage+'&callback=ip_callback"></script>');
document.write(
'<style type="text/css">'+
'.ip-info {'+
'border: 3px solid red;'+
'padding: 5px;'+
'background: honeydew'+
'}'+
'.ip-info li {'+
'margin-left: 2em;'+
'}'+
'</style>');
addOnloadHook(function() {
var tbs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
addlilink(tbs, "javascript:/*void(load_ipinfo()); */void(get_ipinfo());", "ip info", 'ca-ipinfo', 'Get ip info');
});
function iterate_data(newdiv, dat) {
for(var x in dat) {
if(typeof dat[x] == 'object') {
iterate_data(newdiv, dat[x]);
} else {
newdiv.innerHTML += '<li><b>'+x+'</b>: '+dat[x]+'</li>\n';
}
}
}
function load_ipinfo() {
var script = document.createElement('script');
script.src = 'http://hemlock.knams.wikimedia.org/~wizardrydragon/lookup_hostmask.php?ip='+ip_use+'&format=json&lang='+wgContentLanguage+'&callback=ip_callback';
document.getElementsByTagName('head')[0].appendChild(script);
}
function get_ipinfo() {
var newdiv = document.createElement('div');
newdiv.className = 'ip-info';
newdiv.id = 'ip-info';
newdiv.innerHTML = 'IP info for '+ip_use+' <small>(retrieved from <a href="http://hemlock.knams.wikimedia.org/~wizardrydragon/lookup_hostmask.php?ip='+ip_use+'&lang='+wgContentLanguage+'">http://hemlock.knams.wikimedia.org/~wizardrydragon/lookup_hostmask.php?ip='+ip_use+'&lang='+wgContentLanguage+'</a></small>)<br>';
newdiv.innerHTML += '<ul>';
iterate_data(newdiv, data_ipinfo);
newdiv.innerHTML += '</ul>';
document.getElementById('content').insertBefore(newdiv, document.getElementById('content').getElementsByTagName('h1')[0].nextSibling);
document.getElementById('ca-ipinfo').firstChild.innerHTML = 'Collapse IP info';
document.getElementById('ca-ipinfo').firstChild.href = 'javascript:void(hide_ipinfo())';
}
function hide_ipinfo() {
document.getElementById('ca-ipinfo').firstChild.innerHTML = 'ip info';
document.getElementById('ca-ipinfo').firstChild.href = 'javascript:void(show_ipinfo())';
document.getElementById('ip-info').style.display = 'none';
}
function show_ipinfo() {
document.getElementById('ca-ipinfo').firstChild.innerHTML = 'Collapse IP info';
document.getElementById('ca-ipinfo').firstChild.href = 'javascript:void(hide_ipinfo())';
document.getElementById('ip-info').style.display = 'block';
}
}
} catch(e) {  }
 
//Auto welcome user script written by GeorgeMoney
if(welcome == undefined) {
//If you would like to make your own config you have 2 options:
//1:Copy the entire code to your monobook and change the config
//2:Copy everything, from this line until you see 'end config', into your monobook.js, and include the module to your monobook via an import function
 
var welcome={};welcome.edit={};welcome.link={};welcome.link.tab={};welcome.link.newUserLog={};welcome.link.redLinkTalk={};welcome.options={};
 
//config
welcome.edit.summary = "Welcome to Wikipedia!";
welcome.edit.text = "{{sub" + "st:User:GeorgeMoney/Welcome}}" + "\n" + "~~" + "~~";
welcome.edit.textAnon = "{{sub" + "st:Welcomeip}}" + "\n" + "~~" + "~~";
welcome.edit.button = 'wpSave';
 
welcome.link.newUserLog.defaultColor = "blue";
welcome.link.newUserLog.clickedColor = "green";
welcome.link.newUserLog.text = "[welcome]";
 
welcome.link.redLinkTalk.defaultColor = "blue";
welcome.link.redLinkTalk.clickedColor = "green";
welcome.link.redLinkTalk.text = "[welcome]";
welcome.link.redLinkTalk.blink = false;
 
welcome.link.tab.text = "welcome!";
welcome.link.tab.accessKey = 'a';
 
welcome.options.newUserLogaddReloadButton = true;
welcome.options.newUserLogEnabled = true;
welcome.options.redLinkTalkEnabled = true;
welcome.options.addTab = true;
welcome.options.askIfPageIsNotBlank = true;
welcome.options.maxLinks = 1000;
welcome.options.warnIfOverMaxLinks = false;
 
//end config
 
}
//main script
if(welcome.options.newUserLogEnabled && (/Special(%3A|:)Log(\/newusers$|(.*?&|\?)type=newusers)/i).test(window.location.href)) {
if(window.location.hash != "") window.location.hash = "";
else {
addOnloadHook(function() {
var lis = document.getElementById('bodyContent').getElementsByTagName('ul')[0].getElementsByTagName('li');
for (var i=0; i<lis.length; i++) {
var li = lis[i];
var url = li.firstChild.nextSibling.nextSibling.nextSibling.href;
var charao = (url.indexOf('?') != -1)?'&':'?';
url += charao+"autowelcome=true"
var link = document.createElement('a');
link.appendChild(document.createTextNode(welcome.link.newUserLog.text));
link.style.color = welcome.link.newUserLog.defaultColor;
monclick = function() {
//this.style = { };
this.style.textDecoration = 'none';
this.style.color = welcome.link.newUserLog.clickedColor;
var n = parseInt(this.name.split('_')[2]);
var newhref = "#anchor_welcome_"+(n+1);
this.onmouseover = function() { return false; }
this.onfocus = function() { return false; }
this.onclick = function() { 
window.open(this.href); 
this.onclick = function() { return false; }; 
return false; 
}
this.onmousedown = function() { return false; }
this.onmouseup = function() { return false; }
this.onmouseout = function() { 
//var n = parseInt(this.name.split('_')[2]);
//var newhref = "#anchor_welcome_"+(n+1);
//this.href /**/+= '&hasdone=true'; //newhref;
//this.href=newhref;
this.href = "javascript:void(0);";
this.onmouseout = function() {
return false;
}
};
//this.href = newhref;
//this.tagName = 'SPAN';
//this.innerHTML = 'welcomed';
this.style.cursor = "default";
};
//link.onfocus = monclick;
link.onmouseup = monclick;
link.href = url;
link.id = "id_welcome_"+i;
link.name = "anchor_welcome_"+i;
li.appendChild(link);
}
 
if(welcome.options.newUserLogaddReloadButton) {
var h1 = document.getElementsByTagName('h1')[0];
var button = document.createElement('input');
button.onclick = function() { 
if(window.location.hash != "") 
window.location.hash = "";
location.reload();
}
button.value = "reload";
button.type = "button";
h1.parentNode.insertBefore(button, h1.nextSibling);
}
});
}
}
 
if(welcome.options.redLinkTalkEnabled && !((/Special(%3A|:)Log(\/newusers$|(.*?&|\?)type=newusers)/i).test(window.location.href)) && ( ( (wgNamespaceNumber > -1 && wgNamespaceNumber % 2 != 0) || (wgCanonicalNamespace == "Wikipedia"||wgCanonicalNamespace == 'Special') ) || !wgIsArticle )) {
addOnloadHook(function() {
var alinks = document.getElementById('bodyContent').getElementsByTagName('a');
if(alinks.length > welcome.options.maxLinks) {
if(welcome.options.warnIfOverMaxLinks)
var ok_to_go = confirm("This page has over "+welcome.options.maxLinks+" links.\n"
+"Searching for red links to add welcome links might take a while and freeze your"
+" browser\nTo continue and add welcome links, press ok.");
else var ok_to_go = false;
} else var ok_to_go = true;
if(!ok_to_go) return;
for(var i=0, j=0; i<alinks.length; i++) {
var lin = alinks[i];
if(lin.className == "new" && (/User([_ ]talk)?:/i).test(lin.href) && lin.href.substr('http://en.wikipedia.org/w/index.php?title='.length).indexOf('/') == -1) {
var url = lin.href;
url = url.replace('User:', 'User_talk:');
var charao = (url.indexOf('?') != -1)?'&':'?';
url += charao+"autowelcome=true"
var nlin = document.createElement('a');
nlin.appendChild(document.createTextNode(welcome.link.redLinkTalk.text));
nlin.style.color = welcome.link.redLinkTalk.defaultColor;
monclick = function() {
this.style.textDecoration = 'none';
this.style.color = welcome.link.redLinkTalk.clickedColor;
var n = parseInt(this.name.split('_')[2]);
var newhref = "#anchor_welcome_"+(n+1);
this.onmouseover = function() { return false; }
this.onfocus = function() { return false; }
this.onclick = function() { 
window.open(this.href); 
this.onclick = function() { return false; }; 
return false; 
}
this.onmousedown = function() { return false; }
this.onmouseup = function() { return false; }
this.onmouseout = function() { 
//var n = parseInt(this.name.split('_')[2]);
//var newhref = "#anchor_welcome_"+(n+1);
//this.href /**/+= '&hasdone=true'; //newhref;
//this.href=newhref;
this.href = "javascript:void(0);";
this.onmouseout = function() {
return false;
}
};
//this.href = newhref;
//this.tagName = 'SPAN';
//this.innerHTML = 'welcomed';
this.style.cursor = "default";
};
nlin.onmouseup = monclick;
nlin.href = url;
nlin.id = "id_welcome_"+j;
nlin.name = "anchor_welcome_"+j;
if(welcome.link.redLinkTalk.blink) nlin.style.textDecoration = 'blink';
 
try { //alert(lin+lin.href+lin.className+lin.innerHTML+lin.nextSibling);
if(lin.nextSibling) {
lin.parentNode
.insertBefore(
nlin, 
lin.nextSibling
);
} else { 
lin.parentNode
.appendChild(
nlin
);
 
}
j++;
} catch(e) {
//alert(lin+lin.href+lin.className+lin.innerHTML+lin.nextSibling);
//alert(e.toString());
}
}
}
});
}
 
if(welcome.options.addTab && ( wgCanonicalNamespace == 'User' || wgCanonicalNamespace == 'User_talk' ) ) {
addOnloadHook(function() {
try {
var href = document.getElementById('ca-edit').firstChild.href;
var charao = (href.indexOf('?') != -1)?'&':'?';
href += charao+"autowelcome=true";
if(wgCanonicalNamespace == 'User') href = href.replace(/User:/i, 'User_talk:');
var tbs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
addlilink(tbs, href, welcome.link.tab.text, 'ca-welcome', 'Welcome '+wgTitle, welcome.link.tab.accessKey);
} catch(e) { }
});
}
 
if(window.location.href.indexOf('autowelcome=true') != -1
&&window.location.href.indexOf('action=edit') == -1) {
window.location.href += '&action=edit';
}
 
if(window.location.href.indexOf('action=edit') != -1 
&& window.location.href.indexOf('autowelcome=true') != -1) {
if(window.location.href.indexOf('hasdone=true') != -1) {
location.href = location.href.split('action=edit')[0]
.split('autowelcome=true')[0];
} else {
addOnloadHook(function() {
var text = document.getElementById('wpTextbox1').value;
if(welcome.options.askIfPageIsNotBlank && text != '') {
var oktogo = confirm("There was other text detected on this page\nWould you like to continue with the welcome?");
} else var oktogo = true;
var newtext = text + '\n';
if((/\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/).test(wgPageName))
newtext += welcome.edit.textAnon;
else 
newtext += welcome.edit.text;
document.getElementById('wpTextbox1').value = newtext;
document.getElementById('wpSummary').value = welcome.edit.summary;
if(!oktogo) return;
document.getElementById(welcome.edit.button).click();
});
}
}
 
//
//