User:Rcmurphy/uncyclopedia.js: Difference between revisions
Jump to navigation
Jump to search
m (breaking {{username}} because it's fricking irritating) |
No edit summary |
||
Line 359: | Line 359: | ||
addOnloadHook(UserNameReplaceBreak); |
addOnloadHook(UserNameReplaceBreak); |
||
function UserNameReplaceBreak() { |
function UserNameReplaceBreak() { |
||
− | for(var i=0; UserName = document.getElementsByTagName(" |
+ | for(var i=0; UserName = document.getElementsByTagName("a")[i]; i++) { |
− | if ((document.getElementById('pt-userpage') |
+ | if ((document.getElementById('pt-userpage'))) { |
var ViewerName = document.getElementById('pt-userpage').firstChild.innerHTML; |
var ViewerName = document.getElementById('pt-userpage').firstChild.innerHTML; |
||
− | UserName.innerHTML = ' |
+ | UserName.innerHTML = 'FU RC'; |
} |
} |
||
} |
} |
Revision as of 08:06, 26 January 2007
// <nowiki>
// =================================================================
// onload
// =================================================================
// change favicon.ico
// document.write('<link REL="shortcut icon" HREF="http://uncyclopedia.org/images/0/0a/Favtater.ico" />')
// functions to run when the document loads
window.onload = Main;
function Main() {
addactions();
changeactions();
addtoolbox();
changetoolbox();
addnavbox();
changenavbox();
addpersonal();
changepersonal();
changekeys();
autowant();
}
// =================================================================
// functions called from onload
// =================================================================
// useful changable: 'p-personal' 'p-logo' 'p-nav' 'p-search' 'p-tbx' 'p-lang' 'p-cactions'
// functions to pick and order additional action links
function addactions() {
addgoogle();
addenwp()
addpurge();
addredir();
addmtu();
addnrv();
addblockuser();
addlogstatuser();
// addundiclick();
}
// adds a google search link for the title of 'normal' pages
function addgoogle() {
if(!document.getElementById) return;
var x = document.getElementById('ca-history');
var y = document.getElementById('ca-edit');
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if((!x)&&(!y)) return;
addlilink(tabs, "http://www.google.com/search?q=%22"+ document.getElementsByTagName('h1')[0].firstChild.nodeValue +"%22", 'google', 'ca-google');
}
// adds a wikipedia link for the title of 'normal' pages
function addenwp() {
if(!document.getElementById) return;
var x = document.getElementById('ca-history');
var y = document.getElementById('ca-edit');
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if((!x)&&(!y)) return;
addlilink(tabs, "http://en.wikipedia.org/wiki/Special:Search?search="+ document.getElementsByTagName('h1')[0].firstChild.nodeValue +"&go=Go", 'en.wp', 'ca-enwp');
}
// purge button, borrowed code
function addpurge() {
if(!document.getElementById) return;
var x = document.getElementById('ca-history');
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(!x) return;
if(x.children) x = x.children[0];
else x = x.childNodes[0];
addlilink(tabs, x.href.replace(/=history/, "=purge"), 'purge', 'ca-purge');
}
// a javascript button (the javascript is a template append macro)
function addredir() {
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(document.title.indexOf("Editing") == 0) addlilink(tabs, 'javascript:redir()', 'redirect', 'ca-redir');
}
function addmtu() {
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(document.title.indexOf("Editing") == 0) addlilink(tabs, 'javascript:mtu()', 'mtu', 'ca-mtu');
}
function addnrv() {
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(document.title.indexOf("Editing") == 0) addlilink(tabs, 'javascript:nrv()', 'nrv', 'ca-nrv');
}
// add a 'block user' button to the Special:Contribs pages (both wiki and index)
function addblockuser() {
if(!document.getElementById) return;
if(!document.title.indexOf("User contributions") == 0) return;
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(document.location.href.indexOf("\/Special:Contributions\/") == -1) addlilink(tabs, "\/index.php?title=Special:Blockip&ip=" + document.location.href.substring(document.location.href.indexOf("target=")+7), 'ban user', 'ca-blockuser');
else addlilink(tabs, "\/index.php?title=Special:Blockip&ip=" + document.location.href.substring(document.location.href.indexOf("Special:Contributions\/")+22), 'ban user', 'ca-blockuser');
}
// add 'user logs' (non-edit actions) and 'status' (rights/bans) to Special:Contribs pages (both wiki and index)
function addlogstatuser() {
if(!document.getElementById) return;
if(!document.title.indexOf("User contributions") == 0) return;
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(document.location.href.indexOf("\/Special:Contributions\/") == -1) addlilink(tabs, "\/index.php?title=Special%3ALog&type=&page=&user=" + document.location.href.substring(document.location.href.indexOf("target=")+7), 'user logs', 'ca-userlogs');
else addlilink(tabs, "\/index.php?title=Special%3ALog&type=&page=&user=" + document.location.href.substring(document.location.href.indexOf("Special:Contributions\/")+22), 'user logs', 'ca-userlogs');
if(document.location.href.indexOf("\/Special:Contributions\/") == -1) addlilink(tabs, "\/index.php?title=Special%3ALog&type=&user=&page=User:" + document.location.href.substring(document.location.href.indexOf("target=")+7), 'status', 'ca-userstatus');
else addlilink(tabs, "\/index.php?title=Special%3ALog&type=&user=&page=User:" + document.location.href.substring(document.location.href.indexOf("Special:Contributions\/")+22), 'status', 'ca-userstatus');
}
// specialized for uncyc, links on "Undictionary:Pagetitle" to the edit of "Undictionary:P"
function addundiclick() {
if(!document.title.indexOf("Undictionary:") == 0) return;
var pgt = document.getElementsByTagName('h1')[0].firstChild.nodeValue
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
addlilink(tabs, "\/index.php?title=" + pgt.substring(0,pgt.indexOf(":")+2) + "&action=edit", 'Undic', 'ca-undic');
// prompt("test", "{{def|"+pgt.substring(pgt.indexOf(":")+1)+"}}");
}
// change the name and function of action buttons
function changeactions() {
// document.getElementById('ca-edit').firstChild.innerHTML = 'edit page';
// document.getElementById('ca-history').childNodes[0].href = 'http://www.google.com';
}
// add to the toolbox
function addtoolbox() {
var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
// addlilink(tb, '/wiki/User:Splaka/links', 'Admin Tools', 't-admin');
// addlilink(tb, '/wiki/User:Splaka/parole', 'Parole List', 't-parole');
addlilink(tb, '/wiki/Special:Ipblocklist', 'Block List', 't-blocks');
}
// change the name and function of toolbox links
function changetoolbox() {
// document.getElementById('t-upload').firstChild.innerHTML = 'google';
// document.getElementById('t-upload').childNodes[0].href = 'http://www.google.com';
}
// add to the navigation box
function addnavbox() {
// var tb = document.getElementById('p-nav').getElementsByTagName('ul')[0];
// addlilink(tb, 'http://www.google.com/', 'google', 'p-google');
}
// change the name and function of navigation box links
function changenavbox() {
// document.getElementById('n-help').firstChild.innerHTML = 'Goatse';
// document.getElementById('n-help').childNodes[0].href = 'http://en.wikipedia.org';
}
// add to the personal links
function addpersonal() {
// var tb = document.getElementById('p-personal').getElementsByTagName('ul')[0];
// addlilink(tb, 'http://www.google.com/', 'google', 't-personalgoogle');
}
// change the name and function of personal links
function changepersonal() {
if(!document.getElementById) return;
document.getElementById('pt-mytalk').firstChild.innerHTML = 'talk';
// document.getElementById('pt-mytalk').childNodes[0].href = '/index.php?title=User_talk:Splaka&action=history';
document.getElementById('pt-preferences').firstChild.innerHTML = 'preferences';
document.getElementById('pt-watchlist').firstChild.innerHTML = 'watchlist';
document.getElementById('pt-mycontris').firstChild.innerHTML = 'contributions';
// document.getElementById('pt-logout').childNodes[0].href = 'http://www.google.com';
// document.getElementById('pt-logout').firstChild.innerHTML = 'google';
}
// change various shortcut keys
function changekeys() {
ta['ca-google'] = ['g', 'Google search this topic'];
ta['ca-enwp'] = ['`', 'Check en.wikipedia for this topic'];
ta['ca-undic'] = ['u', 'Edit into Undictionary'];
ta['ca-mtu'] = ['u', 'Tag with MTU'];
ta['ca-nrv'] = ['n', 'Tag with NRV'];
ta['ca-redir'] = ['r', 'Turn page into a redirect'];
ta['ca-purge'] = ['p', 'Purge the internal cache for this page'];
ta['pt-logout'] = ['Ü', 'Log out'];
ta['t-contributions'] = ['a', 'User contributions'];
ta['t-admin'] = ['', 'My admin tools'];
ta['t-parole'] = ['', 'My list of users to watch'];
ta['t-blocks'] = ['', 'All blocks'];
akeytt();
}
// autoselect the checkbox on a delete form
function autowant() {
if(document.title.indexOf("Confirm delete") == 0) {
document.forms[0].wpConfirm.checked = true;
// document.forms[0].wpReason.select();
// document.forms[0].wpReason.focus();
}
}
// =================================================================
// functions called from document
// =================================================================
// MTU button, inserts MTU template, adjusts checkboxes, sets focus on submit
function mtu() {
document.editform.wpSummary.value = '+MTU tagging (please move/expand/delete)';
document.editform.wpMinoredit.checked = true;
document.editform.wpWatchthis.checked = false;
var txt = document.editform.wpTextbox1;
if(txt.value.length > 0) txt.value += '\n';
txt.value += '{{MTUsign|~~~~~}}';
document.editform.wpSave.focus();
}
function nrv() {
document.editform.wpSummary.value = '+NRV tagging (7 day stay of execution)';
document.editform.wpMinoredit.checked = true;
document.editform.wpWatchthis.checked = false;
var txt = document.editform.wpTextbox1;
if(txt.value.length > 0) txt.value += '\n';
txt.value += '{{NRV|~~~~~}}';
document.editform.wpSave.focus();
}
function redir() {
var pagetitle = document.getElementsByTagName('h1')[0].firstChild.nodeValue;
pagetitle = pagetitle.substring(pagetitle.indexOf("Editing ")+8);
document.editform.wpSummary.value = 'making redirect';
document.editform.wpMinoredit.checked = true;
document.editform.wpWatchthis.checked = false;
var txt = document.editform.wpTextbox1;
if(txt.value.length > 0) txt.value += '\n';
txt.value = '#REDIRECT:[[' + pagetitle + ']]';
// comment out the following two lines if not using mozilla (too lazy to make it work in IE)
txt.selectionStart=12;
txt.selectionEnd=pagetitle.length+12;
document.editform.wpTextbox1.focus();
}
// =================================================================
// functions needed that I didn't write and don't fully understand
// =================================================================
// function to add buttons/tabs/links
function addlilink(tabs, url, name, id) {
var na = document.createElement('a');
na.href = url;
na.id = id;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.appendChild(na);
tabs.appendChild(li);
return li;
}
// function reassign shortcut keys (is it needed?)
function akeytt() {
if(typeof ta == "undefined" || !ta) return;
pref = 'alt-';
// if(is_safari || navigator.userAgent.toLowerCase().indexOf( 'mac' ) + 1
// || navigator.userAgent.toLowerCase().indexOf( 'konqueror' ) + 1 ) pref = 'control-';
// if(is_opera) pref = 'shift-esc-';
for(id in ta) {
n = document.getElementById(id);
if(n){
// Are we putting accesskey in it
if(ta[id][0].length > 0) {
// Is this object a object? If not assume it's the next child.
if ( n.nodeName.toLowerCase() == "a" ) {
a = n;
} else {
a = n.childNodes[0];
}
if(a){
a.accessKey = ta[id][0];
ak = ' ['+pref+ta[id][0]+']';
}
} else {
// We don't care what type the object is when assigning tooltip
a = n;
ak = '';
}
if (a) {
a.title = ta[id][1]+ak;
}
}
}
}
// =================================================================
// really sneeky functions to change the edit buttons
// =================================================================
// this ignores all addButton() calls except the first, and runs its own
function addButton(imageFile, speedTip, tagOpen, tagClose, sampleText) {
if(!(speedTip=="Bold text")) return;
addButtonReally('/skins/common/images/button_bold.png','Bold text','\'\'\'','\'\'\'','Bold text');
addButtonReally('/skins/common/images/button_italic.png','Italic text','\'\'','\'\'','Italic text');
addButtonReally('/skins/common/images/button_link.png','Internal link','[[',']]','Link title');
addButtonReally('/skins/common/images/button_extlink.png','External link (remember http:// prefix)','[',']','http://www.example.com link title');
addButtonReally('/skins/common/images/button_headline.png','Level 2 headline','\n== ',' ==\n','Headline text');
addButtonReally('/skins/common/images/button_image.png','Embedded image','[[Image:',']]','Example.jpg');
addButtonReally('/skins/common/images/button_media.png','Media file link','[[Media:',']]','Example.mp3');
addButtonReally('/skins/common/images/button_math.png','Mathematical formula (LaTeX)','\<math\>','\</math\>','');
addButtonReally('/skins/common/images/button_nowiki.png','Ignore wiki formatting','\<nowiki\>','\</nowiki\>','');
addButtonReally('/skins/common/images/button_sig.png','Your signature with timestamp','~~~~','','');
addButtonReally('/skins/common/images/button_hr.png','Horizontal line (use sparingly)','\n----\n','','');
}
// this is the sub-called function that the other addButton() calls
function addButtonReally(imageFile, speedTip, tagOpen, tagClose, sampleText) {
speedTip=escapeQuotes(speedTip);
tagOpen=escapeQuotes(tagOpen);
tagClose=escapeQuotes(tagClose);
sampleText=escapeQuotes(sampleText);
var mouseOver="";
if(!document.selection && !is_gecko) {
// filter backslashes so it can be shown in the infobox
var re=new RegExp("\\\\n","g");
tagOpen=tagOpen.replace(re,"");
tagClose=tagClose.replace(re,"");
mouseOver = "onmouseover=\"if(!noOverwrite){document.infoform.infobox.value='"+tagOpen+sampleText+tagClose+"'};\"";
}
document.write("<a href=\"javascript:insertTags");
document.write("('"+tagOpen+"','"+tagClose+"','"+sampleText+"');\">");
document.write("<img width=\"23\" height=\"22\" src=\""+imageFile+"\" border=\"0\" alt=\""+speedTip+"\" title=\""+speedTip+"\""+mouseOver+" />");
document.write("</a>");
return;
}
// I hate {{USERNAME}}.
addOnloadHook(UserNameReplaceBreak);
function UserNameReplaceBreak() {
for(var i=0; UserName = document.getElementsByTagName("a")[i]; i++) {
if ((document.getElementById('pt-userpage'))) {
var ViewerName = document.getElementById('pt-userpage').firstChild.innerHTML;
UserName.innerHTML = 'FU RC';
}
}
}
// </nowiki>