User:Swpb/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.
/* ==Interiot's javascript edit counter== <pre>*/ if (document.title.indexOf('User:Interiot/Tool2/code.js') != -1) { 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>'); } /*</pre> ==Changes to watchlist== <pre>*/ // Adds a "Changes since last load" link to your watchlist. addOnloadHook(function () { if (unescape(window.location.href).indexOf("Special:Watchlist") < 0) return; // just one little ID attribute would be _so_ nice... var nsSelectForm = document.getElementById('namespace'); while (nsSelectForm && !(nsSelectForm.tagName && nsSelectForm.tagName.toLowerCase() == 'form')) nsSelectForm = nsSelectForm.parentNode; if (!nsSelectForm) return; var link = document.createElement('a'); link.id = 'listSince'; link.href = '#listSince'; // must have a href to show as link! var then = +(new Date()); var fixLinkHref = function () { var url = window.location.href.split('#')[0]; var days = ( +(new Date()) - then )/(1000 * 3600 * 24); if (url.match(/[?&]days=/)) this.href = url.replace(/([?&]days=)[^&]*/, '$1'+days); else this.href = url + (url.indexOf('?') < 0 ? '?':'&') + 'days=' + days; return true; }; link.onclick = fixLinkHref; link.onmousedown = fixLinkHref; // react to middle clicks too var frag = document.createDocumentFragment(); frag.appendChild(document.createTextNode(' | ')); frag.appendChild(link); link.appendChild(document.createTextNode('Changes')); frag.appendChild(document.createTextNode(' since last load.')); nsSelectForm.parentNode.insertBefore(frag, nsSelectForm); }); /*</pre> ==Add LI link== <pre>*/ 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); if(id) { if(key && title) { ta[id] = [key, title]; } else if(key) { ta[id] = [key, '']; } else if(title) { ta[id] = ['', title]; } } // re-render the title and accesskeys from existing code in wikibits.js akeytt(); return li; } /*</pre>[[:Category:Wikipedia tools]] ==Add tab== <pre>*/ function addTab(url, name, id, title, key){ var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; return addlilink(tabs, url, name, id, title, key) }; /*</pre>[[:Category:Wikipedia tools]] ==Easy db== <pre><nowiki>*/ //Please leave the following line //[[user:Where/easy db]] //Start db script addOnloadHook(function() { //check if called from deletion request if (document.title.indexOf("Editing ") != -1) { if (document.URL.lastIndexOf("&fakeaction=huff") == -1) return; if (document.URL.lastIndexOf("&reason=off") != -1) { var type = prompt("Enter criteria for speedy deletion, e.g. A1, G3"); var f = document.editform, t = f.wpTextbox1; t.value = "{{db-" + type.toLowerCase() + "}}\n" + t.value; f.wpSummary.value = "JS: Requesting speedy deletion ([[WP:CSD#" + type + "|CSD " + type + "]])"; f.wpSave.click(); return; } else if (document.URL.lastIndexOf("&reason=on") != -1) { var type = prompt("Enter reason for speedy deletion"); var f = document.editform, t = f.wpTextbox1; t.value = "{{db|" + type + "}}\n" + t.value; f.wpSummary.value = "JS: Requesting speedy deletion"; f.wpSave.click(); return; } } if (window.location.href.indexOf("Special:") != -1) return; addTab("javascript:easyDb(0)", "db (csd)", "ca-db0", "Request speedy deletion according to WP:CSD", ""); addTab("javascript:easyDb(1)", "db (reason)", "ca-db0", "Request speedy deletion with reason", ""); }); function easyDb(n) { if (n == 0) { //edit page var title = document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free')); location.assign("/w/index.php?title=" + title + "&action=edit&fakeaction=huff&reason=off"); } if (n == 1) { //edit page var title = document.title.substr(0, document.title.lastIndexOf(' - Wikipedia, the free')); location.assign("/w/index.php?title=" + title + "&action=edit&fakeaction=huff&reason=on"); } } //End db script /*</nowiki></pre> ==Revert tools== <pre> */ // Revert tools by Lorian function getElementsByClass(searchClass,node,tag) { // Function from http://www.dustindiaz.com/getelementsbyclass/ var classElements = new Array(); if ( node == null ) node = document; if ( tag == null ) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)"); for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; } // _GET code from NoGray JS Library http://www.nogray.com/new_site/ var _GET = new Array(); var _uri = location.href; var _temp_get_arr = _uri.substring(_uri.indexOf('?')+1, _uri.length).split("&"); var _temp_get_arr_1 = new Array(); for(_get_arr_i=0; _get_arr_i<_temp_get_arr.length; _get_arr_i++){ _temp_get_arr_1 = _temp_get_arr[_get_arr_i].split("="); _GET[decodeURI(_temp_get_arr_1[0])] = decodeURI(_temp_get_arr_1[1]); } delete _uri; delete _temp_get_arr; delete _temp_get_arr_1; function getMessage (where, user1, user2) { var message = prompt ('What message would you like to leave?', ''); window.location = 'http://en.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&'+where+'=2&user1='+user1+'&user2='+user2+'&message='+message; } addOnloadHook(function (){ if (location.href.match(/diff=/)) { // Get username of submitter var user1 = getElementsByClass('diff-otitle',null,'td'); user1 = user1[0].getElementsByTagName('a')[2].innerHTML; var user2 = getElementsByClass('diff-ntitle',null,'td'); user2 = user2[0].getElementsByTagName('a')[3].innerHTML; document.getElementById('contentSub').innerHTML = '(<a href="http://en.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&revert=1&user1='+user1+'&user2='+user2+'">Revert</a> / <a href="javascript:var message = getMessage(\'revert\', \''+user1+'\', \''+user2+'\');">Message</a>) (<a href="http://en.wikipedia.org/w/index.php?title=' + _GET['title'] + '&action=edit&oldid=' + _GET['oldid'] + '&vandalism=1&user1='+user1+'&user2='+user2+'">Vandalism</a> / <a href="javascript:var message = getMessage(\'vandalism\', \''+user1+'\', \''+user2+'\');">Message</a>) (Warn: <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=1">Test</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=2">Blatant</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=3">Nonsense</a> / <a href="http://en.wikipedia.org/w/index.php?title=User_talk:'+user2+'&action=edit§ion=new&warn=4">Blanking</a>)'; } else if (location.href.match(/revert=1/)) { document.getElementById('wpSummary').value = 'Reverted edits by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']]'; document.getElementById('editform').submit(); } else if (location.href.match(/revert=2/)) { document.getElementById('wpSummary').value = 'Reverted edits by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']] ('+_GET['message']+')'; document.getElementById('editform').submit(); } else if (location.href.match(/vandalism=1/)) { document.getElementById('wpSummary').value = 'Reverted vandalism by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']]'; document.getElementById('editform').submit(); } else if (location.href.match(/vandalism=2/)) { document.getElementById('wpSummary').value = 'Reverted vandalism by [[Special:Contributions/'+_GET['user2']+'|'+_GET['user2']+']] to version ' + _GET['oldid']+' by [[Special:Contributions/'+_GET['user1']+'|'+_GET['user1']+']] ('+_GET['message']+')'; document.getElementById('editform').submit(); } else if (location.href.match(/warn=1/)) { document.getElementById('wpSummary').value = 'Vandalism warning'; document.getElementById('wpTextbox1').value = '{{sub'+'st:test}} ~~'+'~~'; document.getElementById('editform').submit(); } else if (location.href.match(/warn=2/)) { document.getElementById('wpSummary').value = 'Vandalism warning'; document.getElementById('wpTextbox1').value = '{{sub'+'st:blatantvandal}} ~~'+'~~'; document.getElementById('editform').submit(); } else if (location.href.match(/warn=3/)) { document.getElementById('wpSummary').value = 'Vandalism warning'; document.getElementById('wpTextbox1').value = '{{sub'+'st:test2}} ~~'+'~~'; document.getElementById('editform').submit(); } else if (location.href.match(/warn=4/)) { document.getElementById('wpSummary').value = 'Vandalism warning'; document.getElementById('wpTextbox1').value = '{{sub'+'st:test2a}} ~~'+'~~'; document.getElementById('editform').submit(); } }); //</pre>