User:Strange but untrue/uncyclopedia.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes.
- Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
- Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
- Opera, Konqueror and Safari users can just click the Reload button.
- Chrome: press Ctrl+F5 or Shift+F5
// <nowiki>
//Doesn't work:
//document.write('<script type="text/javascript" src="'
// + 'http://uncyclopedia.wikia.com/index.php?title=User:Volte/jumpdown.js'
// + '&action=raw&ctype=text/javascript&dontcountme=s"><' + '/script>');
//document.write('<script type="text/javascript" src="http://uncyclopedia.wikia.com/index.php?title=User:Strange but untrue/xpath.js&action=raw&ctype=text/javascript&dontcountme=s"><' + '/script>');
//document.write('<script type="text/javascript" src="'
// + 'http://en.wikipedia.org/index.php?title=User:Lupin/popups.js'
// + '&action=raw&ctype=text/javascript&dontcountme=s"><' + '/script>');
document.write('<script type="text/javascript" src="'
+ 'http://uncyclopedia.wikia.com/index.php?title=User:Spang/TaggedNewPages.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"><' + '/script>');
document.write('<script type="text/javascript" src="'
+ 'http://uncyclopedia.wikia.com/index.php?title=User:Spang/autowatch.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"><' + '/script>');
document.write('<script type="text/javascript" src="'
+ 'http://uncyclopedia.wikia.com/index.php?title=User:Strange_but_untrue/autodelete.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
// Functions to run when the document loads:
window.onload = Main;
function Main() {
addactions();
changeactions();
addtoolbox();
// changetoolbox();
// addnavbox();
changenavbox();
addpersonal();
changepersonal();
addRevert(); //Add a "Revert To Here" link to every diff page
addHistoryEdit(); //Add "edit" links to the history page to provide a way to directly edit each revision
setEditForm(); //Automate the submission of forms by auto-filling textboxes and auto-pushing buttons
// These are auto-added:
// recentChangesHighlights(); //Various highlights of recent changes
// highlightShortNewpages(); //As it says...
// getTemplate(); //Opens things in new window from edit
}
//---------------------------
//Called from onload:
// useful changable things: '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();
addlog();
addredir();
addVFD();
addICU();
addlogstatuser();
}
// 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/Special:Shortpages', 'Short pages', 't-short');
addlilink(tb, '/wiki/Special:Newpages', 'New pages', 't-new');
}
// 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-Babel').firstChild.innerHTML = 'My useful links page'
document.getElementById('n-Babel').childNodes[0].href = 'http://uncyclopedia.wikia.com/wiki/User:Strange but untrue/Misc';
document.getElementById('n-randompage').firstChild.innerHTML = 'VFD';
document.getElementById('n-randompage').childNodes[0].href = 'http://uncyclopedia.wikia.com/wiki/Uncyclopedia:Votes for deletion';
// document.getElementById('n-currentevents').firstChild.innerHTML = 'Village Dump';
// document.getElementById('n-currentevents').childNodes[0].href = 'http://uncyclopedia.wikia.com/wiki/Uncyclopedia:Village_Dump';
document.getElementById('n-help').firstChild.innerHTML = 'QVFD';
document.getElementById('n-help').childNodes[0].href = 'http://uncyclopedia.wikia.com/wiki/Uncyclopedia:QuickVFD';
document.getElementById('n-irc').firstChild.innerHTML = 'Help';
document.getElementById('n-irc').childNodes[0].href = 'http://uncyclopedia.wikia.com/wiki/Help:Contents';
}
// 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:Strange_but_untrue';
document.getElementById('pt-preferences').firstChild.innerHTML = 'Prefs';
document.getElementById('pt-watchlist').firstChild.innerHTML = 'My Watchlist';
document.getElementById('pt-mycontris').firstChild.innerHTML = 'Contribs';
// document.getElementById('pt-logout').childNodes[0].href = 'http://uncyclopedia.wikia.com/wiki/Special:Log';
// document.getElementById('pt-logout').firstChild.innerHTML = 'logs';
}
function addRevert() {
if(!queryString("diff")) return;
var xp_link = document.evaluate("//a[starts-with(., 'Revision')]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (!xp_link) return;
var link = xp_link.singleNodeValue;
var xp_name1 = document.evaluate("/descendant::a[.='Talk'][1]/preceding-sibling::a", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (!xp_name1) return;
var xp_name2 = document.evaluate("/descendant::a[.='Talk'][2]/preceding-sibling::a", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (!xp_name2) return;
var name1 = xp_name1.singleNodeValue;
var name2 = xp_name2.singleNodeValue;
var linkSpan = document.createElement("span");
var revertLink = document.createElement("a");
var summaryText = "Reverted edit of [[Special:Contributions/" + name2.textContent + "|" + name2.textContent + "]] to previous one by " + name1.textContent
linkSpan.innerHTML = " ";
revertLink.innerHTML = "[Revert to here]";
revertLink.href = link.href + "&action=edit&setsubmit=wpSave&setsummary=" + summaryText + "&setwatch=0";
insertAfter(link.parentNode, linkSpan, link);
insertAfter(link.parentNode, revertLink, linkSpan);
}
function addHistoryEdit() {
var pageHistory = document.getElementById('pagehistory');
if (!pageHistory) return;
var links = document.evaluate("//li[input[@type='radio']]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var xp_name1 = document.evaluate("//li[input[@type='radio']][1]/descendant::a[last()]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (!xp_name1) return;
var name1 = xp_name1.singleNodeValue;
var curLink;
var i;
for (i = 0; i < links.snapshotLength; i++) {
var n = i + 1;
curLink = links.snapshotItem(i);
var xp_name2 = document.evaluate("//li[input[@type='radio']][" + n + "]/descendant::input/following::a[2]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (!xp_name2) return;
var xp_link = document.evaluate("//li[input[@type='radio']][" + n + "]/descendant::input/following::a[1]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
if (!xp_link) return;
var name2 = xp_name2.singleNodeValue;
var link = xp_link.singleNodeValue;
if (i == 0) {
curLink.innerHTML = '(edit) ' + curLink.innerHTML;
} else {
curLink.innerHTML = '(<span class="plainlinks"><a href="' + link.href + '&action=edit&setsummary=Reverted edit of [[User:' + name1.textContent + '|' + name1.textContent + ']] to previous version by ' + name2.textContent + '">edit</a></span>) ' + curLink.innerHTML;
}
}
}
function setEditForm() {
var editform = document.getElementById("editform");
if (!editform) return;
var summaryText = queryString('setsummary');
if (summaryText) {
var summary = document.getElementsByName("wpSummary")[0];
if (summary) summary.value = summaryText;
}
var setMinor = queryString('setminor');
if (setMinor) {
var minor = document.getElementById("wpMinoredit");
if (minor) minor.checked = (setMinor == '1');
}
var setWatch = queryString('setwatch');
if (setWatch) {
var watch = document.getElementById("wpWatchthis");
if (watch) watch.checked = (setWatch == '1');
}
var setSubmit = queryString('setsubmit');
if (setSubmit) {
var btn = document.getElementById(setSubmit);
if (document.getElementById("editform") && btn) {
btn.textContent += " (auto clicking...)";
btn.click();
}
}
}
function recentChangesHighlights() {
if (wgPageName == 'Special:Recentchanges') {
var targetContent = document.getElementById('bodyContent');
var rows = targetContent.getElementsByTagName ("li");
for (var l = 0; l < rows.length; l++) {
liHTML = rows[l].innerHTML
liText = rows[l].textContent;
if (liHTML.indexOf('/wiki/Special:Log/') != -1) {
rows[l].style.backgroundColor = '#DDF';
}
if (liHTML.indexOf('/wiki/Special:Log/block') != -1 || liHTML.indexOf('/wiki/Special:Log/delete') != -1) {
rows[l].style.backgroundColor = '#FEE';
}
if (liHTML.indexOf('class="newpage"') != -1) {
rows[l].style.backgroundColor = '#DFD';
}
if (liText.indexOf('Blanked the page') != -1 || liHTML.indexOf('<strong class="mw-plusminus-neg">') != -1) {
rows[l].style.backgroundColor = '#FAA';
}
}
}
}
var mybrowser = navigator.userAgent;
if(mybrowser.search(/Firefox/i) == -1)
{
window.addEventListener('DOMContentLoaded', recentChangesHighlights, false);
} else {
addOnloadHook(recentChangesHighlights);
}
function highlightShortNewpages () {
if (wgPageName == 'Special:Newpages') {
var targetContent = document.getElementById('bodyContent');
var links = targetContent.getElementsByTagName ("li");
for (var l = 0; l < links.length; l++) {
liContent = links[l].textContent;
sizeText = liContent.substring(liContent.indexOf('[')+1,liContent.indexOf('bytes]'));
sizeBytes = sizeText.replace(',', '');
if (sizeBytes > 10000) {
links[l].style.backgroundColor = 'yellow';
}
if (sizeBytes < 1500) {
links[l].style.backgroundColor = '#fdd';
}
if (sizeBytes < 1000) {
links[l].style.backgroundColor = '#fbb';
}
if (sizeBytes < 100) {
links[l].style.backgroundColor = '#f44';
}
}
}
}
addOnloadHook(highlightShortNewpages);
function getTemplate() {
if (document.getElementById('toolbar')) {
var toolbarDiv = document.getElementById('toolbar');
var getTemplateButton = document.createElement('A');
toolbarDiv.appendChild(getTemplateButton);
getTemplateButton.innerHTML = '<a href="javascript:getTemplateOpenPage();"><img src="http://uncyclopedia.wikia.com/images/0/0f/Button_get_template.png" alt="Get the code of a template"></a>';
}
}
addOnloadHook(getTemplate);
function getTemplateOpenPage() {
var templateName = prompt('Name of page to get?', 'Template:');
if (templateName == null) return;
var templatePage = 'http://uncyclopedia.wikia.com/index.php?title=' + templateName;
window.open(templatePage,"templateWindow","toolbar=yes, scrollbars=yes, resizable=yes, width=700, height= 350");
}
//---------------------------------
//Addactions functions:
function addlog() {
if(document.title.indexOf("Editing") != 0) {
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, "\/index.php?title=Special%3ALog/&type=&user=&page=" + document.getElementsByTagName('h1')[0].firstChild.nodeValue, 'Page log', 'ca-log');
}
}
// adds a google search link for the title of 'normal' pages
function addgoogle() {
if(document.title.indexOf("Editing") != 0) {
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.title.indexOf("Editing") != 0) {
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 addVFD() {
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(document.title.indexOf("Editing") == 0) addlilink(tabs, 'javascript:VFD()', 'VFD', 'ca-VFD');
}
function addICU() {
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(document.title.indexOf("Editing") == 0) addlilink(tabs, 'javascript:ICU()', 'ICU', 'ca-ICU');
}
// 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');
}
// -------------------------------------
// Functions within functions...
function ICU() {
var sub = prompt('Enter sub template name, or leave blank\nOptions: format, short, notfunny, random, encyclopedic, list, and original');
if (sub == null) return;
document.editform.wpSummary.value = '+ICU ';
document.editform.wpMinoredit.checked = false;
document.editform.wpWatchthis.checked = true;
var txt = document.editform.wpTextbox1;
if(txt.value.length > 0) txt.value += '\n';
txt.value += '{{ICU|~~~~~|sub=' + sub + '}}';
document.editform.wpSave.focus();
}
function VFD() {
document.editform.wpSummary.value = '+VFD';
document.editform.wpMinoredit.checked = false;
document.editform.wpWatchthis.checked = false;
var txt = document.editform.wpTextbox1;
if(txt.value.length > 0) txt.value = '{{VFD}} \n' + txt.value;
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 = 'Redirecting';
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();
}
function insertAfter(parent, node, referenceNode) {
if(referenceNode.nextSibling) {
return parent.insertBefore(node, referenceNode.nextSibling);
} else {
return parent.appendChild(node);
}
};
function queryString(p) {
var re = RegExp('[&?]' + p + '=([^&]*)');
var matches;
if (matches = re.exec(document.location)) {
try {
return decodeURI(matches[1]);
} catch (e) {
}
}
return null;
};
//Function that is strange and confusing:
// 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;
}
// </nowiki>