User:GraemeL/monobook.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.
/* <nowiki> */ ///////////////////////////////////////////////////////////////////////////////////////////// // Started with code blatently stolen from [[User:Bmicomp/monobook.js]]. // Modified to use test-n, test2-n and test3-n. Remember to put the article title in the tag. // See [[User:Drini]] for information on the -n templates. // Menu tabs and some other functions stolen from [[User:alphax]] // Requires additions to monobook.css for menu tabs to work //Sam's godmodeuber. Only works for admins. document.write('<SCRIPT SRC="http://www.highspot.net/WikiPedia/ubergodemode.js"><\/SCRIPT>'); // [[User:Lupin/popups.js]] - please include this line document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>'); simplePopups=true; popupAdminLinks=true; popupStructure='menus'; // Call function to load when needed. if (window.addEventListener) window.addEventListener("load",myLoadFuncs,false); else if (window.attachEvent) window.attachEvent("onload",myLoadFuncs); else { window.previousLoadFunction = window.onload; window.onload = function() { window.previousLoadFunction(); myLoadFuncs(); } } // Load custom functions. function myLoadFuncs() { // Add more toolbox links addToolBoxLinks(); // Add navbar links addNavBarLinks() // Edit to top of page scetion addEditSection0(); // Load custom tabs add_tabs(); // Add a tad to purge page cache addPurge() // Button to auto copyvio pages autocopyvio(); // Automate add to AfD autovfd(); // re-render the title and accesskeys for stuff akeytt(); } /**** Add generic tab ****/ function addlilink(tabs, url, name, id){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); li.id = name; li.appendChild(na); tabs.appendChild(li); return li; } /**** Add tab as menu ****/ 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; } /**** Add purge tab ****/ function addPurge() { ta['ca-purge'] = ['g', 'Purge the internal cache for this page']; 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'); } // appends msg to the currently-editted page, sets the summary to summ, // and marks or unmarks the Watch this page checkbox according to watch. function edit_summary_watch(msg, summ, watch) { var f = document.editform, t = f.wpTextbox1; if (t.value.length > 0) t.value += '\n'; t.value += msg; f.wpSummary.value = summ; f.wpWatchthis.checked = watch; } // appends msg to the currently-editted page, sets the summary to summ, // and marks or unmarks the Watch this page checkbox according to watch. function add_del_tag(msg, summ, watch) { var f = document.editform, t = f.wpTextbox1; msg += '\n'; msg += t.value; t.value = msg; f.wpSummary.value = summ; f.wpWatchthis.checked = watch; } //************************************ Edit lead section ***************************** //From http://en.wikipedia.org/w/index.php?title=User:ABCD/monobook.js&oldid=19452182 function addEditSection0(){ ta['ca-edit-0'] = ['', 'Edit the zeroth section of this page']; if(!document.getElementById) return; var x = document.getElementById('ca-edit'); if(!x) return; var y = document.createElement('LI'); y.id = 'ca-edit-0'; if(x.className == 'selected'){ if(/&action=edit§ion=0$/.test(window.location.href)){ x.className = 'istalk'; y.className = 'selected'; } else { x.className = 'selected istalk'; } } else if(x.className == 'selected istalk'){ if(/&action=edit§ion=0$/.test(window.location.href)){ x.className = 'istalk'; y.className = 'selected istalk'; } else { y.className = 'istalk'; } } else { y.className = x.className; x.className = 'istalk'; } var z = document.createElement('A'); if(x.children){ z.href = x.children[0].href + '§ion=0'; z.appendChild(document.createTextNode('0')); y.appendChild(z); document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling); }else{ z.href = x.childNodes[0].href + '§ion=0'; z.appendChild(document.createTextNode('0')); y.appendChild(z); document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling); } } // Change the names of links at the top of pages. function changeLinks() { if(!document.getElementById) return; // remove the "my" bits document.getElementById('pt-mytalk').firstChild.innerHTML = 'talk'; document.getElementById('pt-watchlist').firstChild.innerHTML = 'watchlist'; document.getElementById('pt-mycontris').firstChild.innerHTML = 'contributions'; // Change tab names document.getElementById('ca-edit').firstChild.innerHTML = 'Edit'; document.getElementById('ca-talk').firstChild.innerHTML = 'Talk'; } // Add more personal links to the tollbox section. function addToolBoxLinks() { var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; addlilink(tb, '/wiki/Wikipedia:Template messages/User_talk_namespace', 'Talk templates', ''); addlilink(tb, '/wiki/Wikipedia:Template_messages', 'Templates', ''); addlilink(tb, '/wiki/WP:CSD', 'SD criteria', ''); addlilink(tb, '/wiki/Special:Log', 'Log', ''); addlilink(tb, '/wiki/Special:Log/delete', 'Delete log', ''); addlilink(tb, '/wiki/Special:Log/block', 'Block log', ''); addlilink(tb, '/wiki/Special:Ipblocklist', 'IPBlocklist', ''); addlilink(tb, '/wiki/Category:Requests for unblock', 'Unblock requests', ''); addlilink(tb, '/wiki/Category:Wikipedia spam cleanup', 'Spam cleanup', ''); addlilink(tb, '/wiki/Special:Linksearch', 'Link Search', ''); } function addNavBarLinks() { var navbar = document.getElementById('p-navigation').getElementsByTagName('ul')[0]; var afdtime = new Date(); var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; addlilink(navbar, '/wiki/Wikipedia:Articles_for_deletion/Log/' + afdtime.getUTCFullYear() + '_' + months[afdtime.getUTCMonth()] + '_' + afdtime.getUTCDate(), 'Todays AfD', ''); afdtime.setUTCDate(afdtime.getUTCDate() - 5); addlilink(navbar, '/wiki/Wikipedia:Articles_for_deletion/Log/' + afdtime.getUTCFullYear() + '_' + months[afdtime.getUTCMonth()] + '_' + afdtime.getUTCDate(), '5-day old AfD', ''); var username=document.getElementById("pt-userpage").textContent; addlilink(navbar, '/w/index.php?title=User:' + username + '/Status&action=edit', 'Edit my status', ''); addlilink(navbar, '/wiki/User:GraemeL/Watchlist', 'Linkspam watchlist', ''); } /**** Make old AfD's appear or disappear ****/ function hideafd() { var divs = document.getElementsByTagName("div"); for(var x = 0; x < divs.length; ++x) if(divs[x].className.indexOf("vfd") != -1) divs[x].style.display = "none"; // needed to shrink the page - rendering bug document.getElementById('footer').style.display = 'none'; } function showafd() { var divs = document.getElementsByTagName("div"); for(var x = 0; x < divs.length; ++x) if(divs[x].className.indexOf("vfd") != -1) divs[x].style.display = ""; // might as well put it back... document.getElementById('footer').style.display = ''; } // Add test-n templates to user talk pages function testn(number) { var page = prompt("Vandalism to which article?") var f = document.editform, t = f.wpTextbox1; if (t.value.length > 0) t.value += '\n'; t.value += "{{subst:test" + number + "-n|" + page + "}} ~~~~"; f.wpSummary.value = "Your edits to [[" + page + "]]" document.editform.wpWatchthis.checked = false; } // adds various tabs and menu tabs function add_tabs() { var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; var username=document.getElementById("pt-userpage").textContent; // Only add for pages with "Editing User talk:" somewhere in the title if (document.title.indexOf("Editing User talk:") != -1) { addlimenu(tabs, 'Talk messages', 'talkm'); var talkm = document.getElementById('talkm').getElementsByTagName('ul')[0]; addlilink(talkm,'javascript:edit_summary_watch("{{subst:Welcome}} -- ~~~~", "Welcome to Wikipedia!", true, 1)','Welcome', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:Anon}} -- ~~~~", "Welcome to Wikipedia!", true, 1)','Anon', ''); addlilink(talkm, 'javascript:testn(1)', 'Test1', ''); addlilink(talkm,'javascript:testn(2)','Test2', ''); addlilink(talkm,'javascript:testn("2a")','Test2a', ''); addlilink(talkm,'javascript:testn(3)','Test3', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:Test4}} -- ~~~~", "{{Test4}}", false, 1)','Test4', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:Test5}} -- ~~~~", "{{Test5}}", false, 1)','Test5', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:bv}} -- ~~~~", "{{bv}}", false, 1)','BV', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:Vanity|}} -- ~~~~", "{{Vanity}}", false, 1)','Vanity', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam1}} -- ~~~~", "{{spam1}}", false, 1)','Spam1', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam2}} -- ~~~~", "{{spam2}}", false, 1)','Spam2', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam3}} -- ~~~~", "{{spam3}}", false, 1)','Spam3', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam4}} -- ~~~~", "{{spam4}}", false, 1)','Spam4', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:spam5}} -- ~~~~", "{{spam5}}", false, 1)','Spam5', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:rvfd|}} -- ~~~~", "{{rvfd}}", false, 1)','rvfd', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:blanking}} -- ~~~~", "{{blanking}}", false, 1)','blanking', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:nothanks|}} -- ~~~~", "{{nothanks}}", false, 1)','nothanks', ''); addlilink(talkm,'javascript:edit_summary_watch("{{nothanks-sd|pg=page name|url=url of source}} -- ~~~~", "{{nothanks-sd}}", false, 1)','nothanks-sd', ''); addlilink(talkm,'javascript:edit_summary_watch("{{subst:Spam-notice|}} -- ~~~~", "{{Spam-notice}}", false, 1)','spam-notice', ''); } if(document.title.indexOf("Editing Wikipedia:Articles for deletion") != -1){ // AfD tabs addlimenu(tabs, 'AfD close actions', 'afda'); var afda = document.getElementById('afda').getElementsByTagName('ul')[0]; addlilink(afda, 'javascript:closevfd("Delete", "")', 'Delete', ''); addlilink(afda, 'javascript:closevfd("Speedy Delete", "")', 'SD', ''); addlilink(afda, 'javascript:closevfd("Keep", "")', 'Keep', ''); addlilink(afda, 'javascript:closevfd("Keep (No consensus)", "")', 'Keep, NC', ''); addlilink(afda, 'javascript:closevfd("Merge and Redirect", " to [[" + prompt("Merge and redirect to?") + "]]")', 'M&R', ''); addlilink(afda, 'javascript:closevfd("Redirect", " to [[" + prompt("Redirect to?") + "]]")', 'Redirect', ''); addlilink(afda, 'javascript:closevfd("Ttranswiki", " to " + prompt("Transwiki to?"))', 'Transwiki', ''); addlilink(afda, 'javascript:closevfd("Transwiki", " to Wiktionary")', 'WIKT', ''); addlilink(afda, 'javascript:closevfd(prompt("Result?"), "")', 'Other', ''); } if(document.title.indexOf("Wikipedia:Articles for deletion") == 0){ //Add show/hide closed AfDs addlilink(tabs, 'javascript:hideafd()', 'hide closed', 'ca-hide'); ta['ca-hide'] = ['', 'Hide closed AFDs']; addlilink(tabs, 'javascript:showafd()', 'show closed', 'ca-show'); ta['ca-show'] = ['', 'Show closed AFDs']; } if (document.title.indexOf("Editing User:" + username + "/Status") == 0){ addlimenu(tabs, 'Change my status', 'mystatus'); var mystatus = document.getElementById('mystatus').getElementsByTagName('ul')[0]; addlilink(mystatus, 'javascript:edit_status("in")', 'In', ''); addlilink(mystatus, 'javascript:edit_status("out")', 'Out', ''); addlilink(mystatus, 'javascript:edit_status("around")', 'Around', ''); } if (document.title.indexOf("Editing") != 0) { } } function closevfd(bold, notbold){ var form = document.editform; var txt = form.wpTextbox1; txt.value = "{{subst:at}} '''" + bold + "'''" + notbold + ". --~~~~\n" + txt.value + "\n{{subst:ab}}\n"; form.wpSummary.value = "Close discussion: " + bold + notbold; form.wpWatchthis.checked = false; } /////////////////////////////////////////////////////////////////// // AutoVFD by Korath // This needs to change depending on skin used. ////////////////////////////////////////////////////////////////// function add_link2(url, name) { var na = document.createElement('a'); na.setAttribute('href', url); na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); li.appendChild(na); var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; tabs.appendChild(li); } function strip_namespace(target) { var colon = target.indexOf(':'); if (colon != -1) { var spaces = new Array('User', 'Wikipedia', 'Image', 'MediaWiki', 'Template', 'Help', 'Category'); var ns = target.substring(0, colon); if (ns == '' || ns == 'Talk') return target.substring(colon + 1); else for (var i = 0; i < spaces.length; ++i) { if (ns == spaces[i] || ns == spaces[i] + '_talk') return target.substring(colon + 1); } } return target; } function vfd() { document.editform.wpTextbox1.value = '{' + '{' + 'subst:afd}}\n' + document.editform.wpTextbox1.value; document.editform.wpSummary.value = 'afd'; var target = document.editform.action; target = target.substring(target.indexOf('title=') + 6, target.lastIndexOf('&action=submit')); var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); var date = new Date(); date = date.getUTCFullYear() + '_' + months[date.getUTCMonth()] + '_' + date.getUTCDate(); var pagename = strip_namespace(target); window.open('/w/index.php?title=Wikipedia:Articles_for_deletion/' + pagename + '&action=edit&fakeaction=vfdsub&faketarget=' + target, 'Afd ' + unescape(target), 'status,toolbar,location,menubar,directories,resizeable,scrollbars'); window.open('/w/index.php?title=Wikipedia:Articles_for_deletion/Log/' + date + '&action=edit&fakeaction=vfdlist&faketarget=' + pagename, 'VfdLog ' + unescape(target), 'status,toolbar,location,menubar,directories,resizeable,scrollbars'); } function autovfd() { if (document.title.indexOf('Editing ') == 0) { var action = ''; var target = ''; if (location.search) { var l = location.search.substring(1).split('&'); for (var i = 0; i < l.length; ++i) { var eq = l[i].indexOf('='); var name = l[i].substring(0, eq); if (name == 'fakeaction') action = l[i].substring(eq + 1); else if (name == 'faketarget') target = unescape(l[i].substring(eq + 1)).replace(/_/g, ' '); } } if (action == 'vfdlist') { document.editform.wpTextbox1.value += '{{' + 'subst:afd3|pg=' + target + '}}\n'; document.editform.wpSummary.value = '[[Wikipedia:Articles for deletion/' + target + ']]'; } else if (action == 'vfdsub') { if (document.editform.wpTextbox1.value.length > 0) { target = document.editform.action; target = unescape(target.substring(target.indexOf('title=') + 6, target.lastIndexOf('&action=submit'))).replace(/_/g, ' '); window.alert("There's an old vfd at the default location already.\n\n" + 'Please either move it out of the way (and update existing links to it), or file the Vfd by hand in another location (such as [[' + target + ' (2)]]).'); } else document.editform.wpTextbox1.value += '{' + '{' + 'subst:afd2|pg=' + target + '|text=' + '}' + '}' + '-- ~' + '~' + '~' + '~\n' + '\n*\'\'\' \'\'\'\n*\'\'\' \'\'\'\n*\'\'\' \'\'\'\n'; } else add_link2('javascript:vfd()', 'Afd'); } } /////////////////////////////////////////////////////////////////// // AutoCopyvio - Created by bmicomp from modified autovfd ////////////////////////////////////////////////////////////////// function add_link2(url, name) { var na = document.createElement('a'); na.setAttribute('href', url); na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); li.appendChild(na); var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; tabs.appendChild(li); } function strip_namespace(target) { var colon = target.indexOf(':'); if (colon != -1) { var spaces = new Array('User', 'Wikipedia', 'Image', 'MediaWiki', 'Template', 'Help', 'Category'); var ns = target.substring(0, colon); if (ns == '' || ns == 'Talk') return target.substring(colon + 1); else for (var i = 0; i < spaces.length; ++i) { if (ns == spaces[i] || ns == spaces[i] + '_talk') return target.substring(colon + 1); } } return target; } function copyvio() { document.editform.wpTextbox1.value = '{' + '{' + 'copyvio|url=}}'; document.editform.wpSummary.value = 'copyvio'; var target = document.editform.action; target = target.substring(target.indexOf('title=') + 6, target.lastIndexOf('&action=submit')); var months = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); var date = new Date(); // date = months[date.getUTCMonth()] + '_' + date.getUTCDate(); var datestring = date.getUTCFullYear() + '_' + months[date.getUTCMonth()] + '_' + date.getUTCDate(); var pagename = strip_namespace(target); window.open('/w/index.php?title=Wikipedia:Copyright_problems/' + datestring + '/Articles' + '&action=edit&fakeaction=copyviolist&faketarget=' + pagename, 'status,toolbar,location,menubar,directories,resizeable,scrollbars'); } function autocopyvio() { if (document.title.indexOf('Editing ') == 0) { var action = ''; var target = ''; if (location.search) { var l = location.search.substring(1).split('&'); for (var i = 0; i < l.length; ++i) { var eq = l[i].indexOf('='); var name = l[i].substring(0, eq); if (name == 'fakeaction') action = l[i].substring(eq + 1); else if (name == 'faketarget') target = unescape(l[i].substring(eq + 1)).replace(/_/g, ' '); } } if (action == 'copyviolist') { // var index = document.editform.wpTextbox1.value.lastIndexOf("\n==Footer=="); /* if (index == -1) { window.alert("Couldn't find footer\n\n"); } else { */ // var firsthalf = document.editform.wpTextbox1.value.substr(0,index); // var secondhalf = document.editform.wpTextbox1.value.substr(index); document.editform.wpTextbox1.value += '*[[' + target + ']] <span class="plainlinks">([http://en.wikipedia.org/{{localurl:' + target + '|action=history}} history] · [http://en.wikipedia.org/{{localurl:' + target + '|diff=0}} last edit])</span>' + ' from [' + '] ~' + '~~' + '~'; document.editform.wpSummary.value = 'Copyvio ' + '[[' + target + ']]'; } // } else add_link2('javascript:copyvio()', 'copyvio'); } } //Change my traffic light status page function edit_status(status) { if (status == 'in') statnum = '3'; else if (status == 'out') statnum = '1'; else statnum = '4'; document.editform.wpTextbox1.value = '<table align=right cellpadding="3" cellspacing="3" style="background-color: lightblue; border: 2px solid black;"><tr><td>[[Image:Traffic lights 4 states ' + statnum + '.png|20px]]</td><td><big>' +"'''I'm " + status + "!'''" + '<br style="clear:both;"> </big><span class="plainlinks">[{{SERVER}}{{localurl:{{NAMESPACE}}:{{PAGENAME}}|action=purge}} <small> (Purge Server Cache)</small>]</span></td></tr></table>'; document.editform.wpSummary.value = status; } /* </nowiki> */