User:Mathwizard1232/monobook.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 can be added at User:Mathwizard1232/monobook.css. |
//<pre><nowiki>
//Functions to manage strings
function Insert(str, pos, newstr)
{
return (str.substr(0,pos) + newstr + str.substr(pos));
}
function Delete(str, pos, length)
{
if (pos + length < str.length)
{
return (str.substr(0,pos) + str.substr(pos+length));
}
else
{
return str.substr(0,pos);
}
}
function DeleteOne(str, pos)
{
return Delete(str, pos, 1)
}
function replace(str,txt,replace)
{
while(str.indexOf(txt)!=-1)
{
str = str.replace(txt,replace);
}
return str;
}
function FindPrev(str, txt, pos)
{
pos--;
while (pos > -1)
{
var Char = str.substr(pos,1);
if (Char == txt)
{
return pos;
}
pos--;
}
return -1;
}
//Functions for finding page information
function title()
{
return document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free'));
}
function article()
{
return document.title.substring(8, document.title.lastIndexOf(' - Wikipedia, the free'));
}
function reversetitle()
{
var str = article();
var pos = str.lastIndexOf(' ');
var last = str.substr(pos+1);
var first = str.substring(0,pos);
return last + "," + first;
}
function ImageTitle()
{
var Title = article();
for (var i = 0; i < Title.length; i++)
{
if ((Title.substr(i,1) == '.') || (Title.substr(i,1) == ' '))
{
Title = Delete(Title, i)
}
}
return Title
}
//Senator functions
function party()
{
var endpos = document.editform.wpTextbox1.value.indexOf(" to the United States Senate");
var startpos = FindPrev(document.editform.wpTextbox1.value, " ", endpos);
return document.editform.wpTextbox1.value.substring(startpos+1,endpos);
}
function state()
{
var pos = document.editform.wpTextbox1.value.indexOf('a Senator from ');
var end = document.editform.wpTextbox1.value.indexOf(';');
var state = document.editform.wpTextbox1.value.substring(pos+15,end);
return state;
}
//Functions for adding buttons
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);
na.accesskey = key;
var pref = 'alt-';
if(((clientPC.indexOf('AppleWebKit')!=-1) && (clientPC.indexOf('spoofer')==-1)) || navigator.userAgent.toLowerCase().indexOf( 'mac' ) != -1 ) pref = 'control-';
if(clientPC.indexOf('opera')!=-1) pref = 'shift-esc-';
if(key && title) na.title = title + ' [' + pref + key + ']';
else if(title) na.title = title;
else if(key) na.title = '[' + pref + key + ']';
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);
}
//Functions for editing
function addText(text)
{
document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + text;
}
function addTextTop(text)
{
document.editform.wpTextbox1.value = text + document.editform.wpTextbox1.value;
}
function addSummary(text)
{
document.editform.wpSummary.value = text
}
//Functions for modifying page for Senator Conversion
function CongressConvert()
{
var str = document.editform.wpTextbox1.value;
var pos = -1;
while (str.indexOf("Congress", pos) != -1)
{
var midpos = str.indexOf("Congress", pos) - 2;
var startpos1 = str.lastIndexOf("(",midpos);
var startpos2 = str.lastIndexOf(" ",midpos);
var startpos;
if (startpos1 < startpos2)
{
startpos = startpos2;
}
else
{
startpos = startpos1;
}
startpos++;
var currpos = midpos + 10;
//window.alert("Up to found point: " + str.substring(0,currpos));
//window.alert(str.substring(startpos,currpos));
var link = "[[" + str.substring(startpos,midpos) + " United States Congress|" + str.substring(startpos,currpos) + "]]"
str = Delete(str,startpos,currpos-startpos)
str = Insert(str,startpos,link)
pos = startpos + link.length
}
document.editform.wpTextbox1.value = str;
}
function Convert(text)
{
//Add links, convert names
text = replace(text,"Wis.","Wisconsin");
text = replace(text,"Md.","Maryland");
text = replace(text,"Mo.","Missouri");
text = replace(text,"Wash.","Washington");
text = replace(text,"Pa.","Pennsylvania");
//CongressConvert();
return text;
}
function doStart() //Main function that creates the template for Senators
{
/*if (document.editform.wpTextbox1.value != "")
{
window.alert('Data found, template not added.');
}
else
{*/
var Bio = document.editform.wpTextbox1.value;
document.editform.wpTextbox1.value = Convert(Bio);
//window.alert(article());
addText('\n[[Image:' +ImageTitle() + '|thumb|right|'+article()+']]' + "\n");
addText("'''" + article() + "'''" + " was an [[American]] [[politician]]. A [[" + party() + " Party (United States)|" + party() + "]],");
addText(" he served as a [[United States Senator]] from [[" + state() + "]].\n");
addText("==Early Life==\n\n==Political Career==\n\n==Sources==\n* {{CongBio|}}\n");
addText("{{start box}}\n{{U.S. Senator box\n\n")
addText("|state = state()\n\n|class = \n|before=[[]]\n|after=[[]]\n|alongside=[[]]\n|years – }}\n")
addText("{{end box}}\n");
addText("{{US-politician-stub}}");
addText("[[Category: births|" + reversetitle() + "]]\n");
addText("[[Category: deaths|" + reversetitle() + "]]\n");
addText("[[Category:United States Senators from " +state() + "|" + reversetitle() + "]]\n");
document.editform.wpSummary.value = 'Created for [[WP:USC]]';
//window.alert('Adding template.');
//}
}
//Quick proposed deletion
function doProd()
{
var reason=prompt("Please enter reason for prod.")
if (reason != null && reason != "")
{
addTextTop("{{prod|" + reason + "}}\n\n")
addSummary("[[WP:PROD|Proposed Deletion]]")
document.editform.submit()
}
}
//Functions for making buttons, loading, making flow go where I want at the start
function addStart()
{
addTab("Javascript:doStart()", "Start Senator Page", "ca-start", "Creates an outline for a page for a former Senator.", "");
akeytt();
}
function GoEdit(tag)
{
location.href = 'http://en.wikipedia.org/w/index.php?title=' + title() + '&action=edit&other=' + tag;
}
function doGoProd()
{
GoEdit('StartProd');
}
function doGoStart()
{
location.href = 'http://en.wikipedia.org/w/index.php?title=' + title() + '&action=edit&other=StartSen';
}
function GoStart()
{
addTab("Javascript:doGoStart()", "Start Senator Page", "ca-start", "Creates an outline for a page for a former Senator.", "");
}
function GoProd()
{
addTab("Javascript:doGoProd()", "Tag Prod", "ca-prod", "Tags article for proposed deletion (for non-controversial)", "");
}
function addProd()
{
addTab("Javascript:doProd()", "Tag Prod", "ca-prod", "Tags article for proposed deletion (for non-controversial)", "");
}
function CheckStart() //Checks for parameters sent to start various tasks
{
var end = location.href.substr(location.href.lastIndexOf('=edit'));
if (end == '=edit')
return;
else if (end == '=edit&other=StartSen')
{
doStart();
}
else if (end == '=edit&other=StartProd')
{
doProd();
}
else
{
//window.alert('Unrecognized command: ' + end);
}
}
//Loads initial boxes depending on current window
if (document.title.indexOf("Editing ") == 0)
{
addOnloadHook(addStart);
addOnloadHook(addProd);
}
else
{
//addOnloadHook(GoProd);
//addOnloadHook(GoStart);
}
if (document.title.indexOf("Editing ") == 0)
{
addOnloadHook(CheckStart);
}
//</nowiki></pre>