Jump to content

User:Mathwizard1232/monobook.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Mathwizard1232 (talk | contribs) at 17:32, 14 February 2006. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre><nowiki>

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 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;
}

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 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;
}

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);
}

function addText(text)
{
	document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + text;
}

function Convert(text)
{
	//Add links, convert names
	text = replace(text,"Wis.","Wisconsin");
	text = replace(text,"Md.","Maryland");
	return text;
}

function doStart()
{
	/*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:|thumb|right|Caption Here]]' + "\n");
		addText("'''" + article() + "'''" + "was an [[American]] [[politician]]. A [[" + party() + " Party (United States)|" + party() + " Party]],");
		addText(" he served as a [[United States Senator]] from " + state() + ".\n");
		addText("==Early Life==\n\n==Political Life==\n\n==Sources==\n{{CongBio|}}\n\n");
		addText("{{start box}}\n\n{{succession box | before=[[]] | title=[[List of United States Senators from |United States Senator (Class ) from ]] | years=[[]]&ndash; | after=}}\n\n");
		addText("{{end box}}\n\n");
		addText("[[Category: births|]]\n");
		addText("[[Category: deaths|]]\n");
		addText("[[Category:United States Senators from |]]\n");
		addText("{{politician-stub}}");
		document.editform.wpSummary.value = 'Created for [[WP:USC]]';
		//window.alert('Adding template.');
	//}
}

function addStart() 
{
  addTab("Javascript:doStart()", "Start Senator Page", "ca-start", "Creates an outline for a page for a former Senator.", "");
  akeytt();
}

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 CheckStart() 
{
	var end = location.href.substr(location.href.lastIndexOf('=edit',100));
	if (end == '=edit')
		return;
	else if (end == '=edit&other=StartSen')
	{
		doStart();
	}
	else
	{
		//window.alert('Unrecognized command: ' + end);
	}
}

if (document.title.indexOf("Editing ") == 0)
{
	addOnloadHook(addStart);
}
else
{
	//addOnloadHook(GoStart);
}

if (document.title.indexOf("Editing ") == 0)
{
	addOnloadHook(CheckStart);
}
//</nowiki></pre>