User:Ian13/monobook.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Firefox/Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.
//<pre><nowiki> // Menu tabs and some other functions stolen from [[User:alphax]]. God-like skin from Sam Hocevar. AfD stuff by [[User:Jnothman]]. 0th section and other stuff from [[User:ABCD]]. Morelinks from [[User:Trilobite]]. Since by [[User:JesseW]]. 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(); } } function myLoadFuncs() { addNavBarLinks(); addEditSection0(); addPurge(); changeLinks(); akeytt(); morelinks(); } /**** 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 = id; 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; } 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 selection ****/ function addEditSection0(){ ta['ca-edit-0'] = ['', 'Edit the initial 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 top links ****/ 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'; document.getElementById('pt-preferences').firstChild.innerHTML = 'prefs'; // Change tab names document.getElementById('ca-edit').firstChild.innerHTML = 'edit'; document.getElementById('ca-talk').firstChild.innerHTML = 'talk'; } /*** Add to nav bar ***/ function addNavBarLinks() { var navbar = document.getElementById('p-navigation').getElementsByTagName('ul')[0]; addlilink(navbar, '/wiki/Special:Newpages', 'New pages', ''); addlilink(navbar, '/wiki/Category:Candidates_for_speedy_deletion', 'Speedy deletions', ''); addlilink(navbar, '/wiki/Wikipedia:Articles_for_deletion/Old', 'VfD backlog', ''); addlilink(navbar, '/wiki/Wikipedia:Vandalism_in_progress', 'Vandalism', ''); addlilink(navbar, '/wiki/Special:Blockip', 'Block IP', ''); addlilink(navbar, '/wiki/Wikipedia:Village_pump_%28all%29', 'Village pump', ''); addlilink(navbar, '/wiki/Wikipedia:Administrators%27_noticeboard', 'Noticeboard', ''); addlilink(navbar, '/wiki/Wikipedia:Administrators%27_noticeboard/Incidents', 'Incidents', ''); } /**** Hide AfDs ****/ function hideafd(){ var divs = document.getElementsByTagName("div"); for(var x = 0; x < divs.length; ++x) if(divs[x].className.indexOf("vfd") != -1 || divs[x].className.indexOf("afd") != -1) divs[x].style.display = "none"; 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].className.indexOf("afd") != -1) divs[x].style.display = ""; document.getElementById('footer').style.display = ''; } /**** AFD helper ****/ if ((typeof auto_mod_loaded == 'undefined') || !auto_mod_loaded) { auto_mod_loaded = true; auto_mod_exectd = false; function am_get_query_vars(){ var res = new Array(); var pairs = location.search.substring(1).split("&"); for(var i=0; i < pairs.length; i++){ var pair = pairs[i].split("="); res[unescape(pair[0])] = unescape(pair[1]).replace(/\+/g, ' '); } return res; } function am_add_li(portlet, url, text, id, title) { var tabs = document.getElementById('p-'+portlet).getElementsByTagName('ul')[0] var na = document.createElement('a'); na.href = url; na.id = id; na.appendChild(document.createTextNode(text)); if (title) na.title = title; var li = document.createElement('li'); if (id) li.id = id; li.appendChild(na); tabs.appendChild(li); return li; } function am_get_title() { //Avoids problems with & etc, but will also include ' - edit this page', etc return document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free')); } function am_tidy_title() { var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit')); return unescape(editlk); } function am_guess_date() { var monthnames = new Array( "January", "Februrary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var today = new Date(); return today.getUTCFullYear() + ' ' + monthnames[today.getUTCMonth()] + ' ' + today.getUTCDate(); } function am_make_url(title, before, after, summary) { return 'http://en.wikipedia.org/w/index.php?title='+escape(title)+ '&action=edit'+ '&amaddbefore='+escape(before)+'&amaddafter='+escape(after)+ '&amsummary='+escape(summary); } function auto_mod() { if (auto_mod_exectd) return false; auto_mod_exectd = true; qvars = am_get_query_vars(); if (qvars['action']=='edit') { if (qvars['amaddafter'] || qvars['amaddbefore'] || qvars['amreplace']) { var summ_el = document.getElementById('wpSummary'); if (summ_el.value != '' && summ_el.value.substr(summ_el.value.length - 3, 3) != '*/ ') { // have already added summary return true; } var text = document.getElementById('wpTextbox1'); if (qvars['amclear']) text.value = ''; if (qvars['amfind'] && qvars['amreplace']) text.value = text.value.replace(new RegExp(qvars['amfind'], "g"), qvars['amreplace']); if (qvars['amaddafter']) { if (text.value.charAt(text.value.length-1) != '\n') text.value += '\n'; text.value += qvars['amaddafter']; } if (qvars['amaddbefore']) { if (text.value.charAt(0) != '\n') text.value = '\n' + text.value; text.value = qvars['amaddbefore'] + text.value; } summ_el.value += (qvars['amsummary'] || ' '); document.getElementById('editform').submit(); } return true; } return false; } function am_add_onload(f) { // borrowed from [[WP:US]] if (window.addEventListener) window.addEventListener("load",f,false); else if (window.attachEvent) window.attachEvent("onload",f); } } afdh_signature = '~~'+'~'; afdh_summaryprompt = true; afdh_shortcuts = Array(); afdh_shortcuts['d'] = 'Delete'; afdh_shortcuts['k'] = 'Keep'; afdh_shortcuts['m'] = 'Merge'; afdh_shortcuts['mv'] = 'Move'; afdh_shortcuts['rd'] = 'Redirect'; afdh_shortcuts['rw'] = 'Rewrite'; afdh_shortcuts['t'] = 'Transwiki'; afdh_shortcuts['wd'] = 'Weak delete'; afdh_shortcuts['sd'] = 'Strong delete'; afdh_shortcuts['sp'] = 'Speedy delete'; afdh_shortcuts['sk'] = 'Strong keep'; afdh_shortcuts['wk'] = 'Weak keep'; afdh_shortcuts['c'] = 'Comment'; afdh_commscs = Array(); afdh_commscs['pn'] = 'per nom.'; function afd_helper() { if (auto_mod()) return; var anchors = new Array(); { var oldanchors = document.getElementById('bodyContent').getElementsByTagName('a'); for (var i=0; i < oldanchors.length; i++) anchors[i] = oldanchors[i]; } var url_re = /\?title=Wikipedia:Articles_for_deletion\/([^&]+)&action=edit&/; var url, matches; for (var i=0; i < anchors.length; i++) { if (!(matches = anchors[i].href.match(url_re)) || (matches[1].substr(0, 4) == 'Log/')) continue; var na = document.createElement('a'); na.href = "javascript:afd_vote('"+anchors[i].href.replace(/'/g, '\\\'')+"')"; na.title = "Vote on deletion of "+unescape(matches[1]); var inlink = document.createElement('sup'); inlink.appendChild(document.createTextNode('vote')); na.appendChild(inlink); anchors[i].parentNode.insertBefore(na, anchors[i].nextSibling); } if (am_get_title().indexOf(':') == -1) am_add_li('tb', 'javascript:afd_nominate()', 'Nominate AFD', '', 'Nominate this article for deletion'); } function afd_vote(edit_link) { var shortcuts_list = ''; for (var key in afdh_shortcuts) shortcuts_list += key + ': ' + afdh_shortcuts[key] + '; '; var vote = window.prompt("Enter your vote. (Shortcuts available are: "+shortcuts_list+")"); if (!vote) return; if (afdh_shortcuts[vote.toLowerCase()]) vote = afdh_shortcuts[vote.toLowerCase()]; shortcuts_list = ''; for (var key in afdh_commscs) shortcuts_list += key + ': ' + afdh_commscs[key] + '; '; var comment = window.prompt("Enter your comment. (Shortcuts available are: "+shortcuts_list+")"); if (typeof comment != 'string') return; if (afdh_commscs[comment.toLowerCase()]) comment = afdh_commscs[comment.toLowerCase()]; var summary = vote; if (afdh_summaryprompt) if (!(summary = window.prompt("Enter the edit summary:", summary))) summary = vote; var url = edit_link + '&amaddafter='+escape("* '''"+vote+"''' "+comment+" "+afdh_signature+" ~~"+"~~"+"~") + '&amsummary='+escape(summary); if (window.location.href.indexOf("/Log/") == -1) window.location.href = url; else window.open(url, "afd_helper_vote"); } function afd_nominate() { var title = am_get_title(); var log_date = am_guess_date(); var reason = window.prompt("Please justify your AFD nomination of "+title+":"); if (!reason) return; window.open(am_make_url(title, '{{'+'subst:afd}}', '', 'nomination for [[WP:AFD|deletion]]'), 'afdhn1'); window.open(am_make_url('Wikipedia:Articles for deletion/Log/'+log_date, '', '{{'+'subst:afd3|pg='+title+'}}', 'Nominating [['+title+']] for deletion'), 'afdhn3'); window.location.href = am_make_url('Wikipedia:Articles for deletion/'+title, '', '{{'+'subst:afd2|pg='+title+'|text='+reason+' '+afdh_signature+" ~~"+"~~"+"~"+'}}', 'nominated for deletion'); } if (window.addEventListener) window.addEventListener("load",afd_helper,false); else if (window.attachEvent) window.attachEvent("onload",afd_helper); /**** Block/blocklog tabs ****/ function add_block_tab() { var c1 = document.getElementById('column-one'); var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0]; // use the "edit this page" tab to get already-tidied url var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href; // cut everything up to "title=" from the start and everything past "&action=edit" from the end editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit')); editlk = editlk.substring(editlk.indexOf(':') + 1); var slloc = editlk.indexOf('/'); if (slloc > 0) editlk = editlk.substring(0, slloc); // add "block" tab addlilink(tabs, '/wiki/Special:Blockip/' + editlk, 'block'); // To open the block page and block log simultaneously, replace the above line with: // addlilink(tabs, 'javascript:blockpage_and_log("' + editlk + '")', 'Block'); // and uncomment the blockpage_and_log() function above. // add "blocklog" tab addlilink(tabs, '/w/index.php?title=Special%3ALog&type=block&user=&page=User%3A' + editlk, 'blocklog'); } /**** More tabs ****/ function unverified() { document.editform.wpSummary.value = 'needs a source and copyright tag - see [[Wikipedia:Image copyright tags]]'; var txt = document.editform.wpTextbox1; if(txt.value.length > 0) txt.value += '\n'; txt.value += '{{unverified}}'; txt.focus(); } function pui() { document.editform.wpSummary.value = 'PUI'; var txt = document.editform.wpTextbox1; if(txt.value.length > 0) txt.value += '\n'; txt.value += '{{pui}}'; txt.focus(); } function replace() { var s = prompt("Search regexp?"); if(s) { var r = prompt("Replace regexp?"); if(!r && r != '') return; var txt = document.editform.wpTextbox1; txt.value = txt.value.replace(new RegExp(s, "g"), r); } } function speedy (criterion) { var form = document.forms.deleteconfirm; form.wpReason.value = criterion; } function closeafd(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; } function afdresult(){ var res = prompt("Result?"); if(!res) return; var form = document.editform; form.wpSummary.value = 'AFD result'; var txt = form.wpTextbox1; txt.value += '{{oldafdfull|date=[[DAY MONTH]] [[2005]]|result=' + res + '|votepage={{subst:PAGENAME}}}}'; txt.focus(); } function afddelete(){ document.forms.deleteconfirm.wpReason.value = '[[Wikipedia:Articles for deletion/' + unescape(window.location.href.replace(/^.*\?title=([^&]+)&action=delete.*$/, '$1').replace(/_/g, ' ')).replace(/^(Talk|Wikipedia( talk)?):/, '') + ']]'; } function fairusedelete(){ document.forms.deleteconfirm.wpReason.value = 'Orphanned fair use image (' + '[[' + 'WP:CSD' + ']]' + ' I5)'; } function replace(){ var s = prompt("Search regexp?"); if(s){ var r = prompt("Replace regexp?"); if(!r && r != '') return; var txt = document.editform.wpTextbox1; txt.value = txt.value.replace(new RegExp(s, "g"), r); } } function afdresult(){ var res = prompt("Result?"); var day = prompt("On which day was it nominated?"); if(!res) return; var form = document.editform; form.wpSummary.value = 'AFD result'; var txt = form.wpTextbox1; txt.value += '{{oldafdfull|date=[[' + day + ']] [[2005]]|result=' + res + '|votepage={{subst:PAGENAME}}}}'; txt.focus(); } function interwiki(wiki) { var f = document.editform, t = f.wpTextbox1; t.value += '\n'; t.value += "[["; t.value += wiki; t.value += ":{{subst:PAGENAME"; t.value += "}}]]"; f.wpSummary.value = "Adding interwiki to " + wiki + "-wiki"; } function morelinks() { var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; if(document.title.indexOf("Editing ") == 0) addlilink(tabs, 'javascript:replace()', 'replace', ''); if(document.title.indexOf("Editing Image:") == 0) { addlilink(tabs, 'javascript:unverified()', 'tag', ''); addlilink(tabs, 'javascript:pui()', 'pui', ''); } if(document.title.indexOf("Confirm delete") == 0) { addlilink(tabs, 'javascript:speedy("nonsense")', 'no', ''); addlilink(tabs, 'javascript:speedy("remove redirect for page move")', 're', ''); addlilink(tabs, 'javascript:speedy("misleading redirect")', 'mr', ''); addlilink(tabs, 'javascript:speedy("talk page with no useful history")', 'tu', ''); addlilink(tabs, 'javascript:speedy("talk page of deleted article")', 'td', ''); addlilink(tabs, 'javascript:afddelete()', 'AFD'); addlilink(tabs, 'javascript:fairusedelete()', 'Fair use'); } if(document.title.indexOf("Editing Wikipedia:Articles for deletion") == 0) { addlilink(tabs, 'javascript:closeafd("keep", "")', 'Keep'); addlilink(tabs, 'javascript:closeafd("delete", "")', 'Delete'); addlilink(tabs, 'javascript:closeafd(prompt("Result?"), "")', 'Other'); } if (document.title.indexOf("Wikipedia:Articles for deletion/Log/") != -1) { addlilink(tabs, 'javascript:hideafd()', 'Hide', 'ca-hide'); addlilink(tabs, 'javascript:showafd()', 'Show', 'ca-show'); } if (document.title.indexOf('User:') == 0 || document.title.indexOf('User talk:') == 0) { add_block_tab(); } } /*** Edit count ***/ document.write('<script type="text/javascript" src="' + 'http://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js' + '&action=raw&ctype=text/javascript&dontcountme=s"></script>') //</nowiki></pre>