User:Xania/Sandbox3

/* This is a modified version of Kbh3rd's Vandal warning toolbox from enwiki The maintainer of this version (Snowolf) is not a js person and is merely borrowing Kbh3rd great code :)

Put some functions in the toolbox for the anti-vandal whack-a-mole game. Documented at http://en.wikipedia.org/wiki/User:Kbh3rd/Vandal_warning_toolbox */ //  // **************** //  Google Lookup // **************** function whackGoogleLookup { var q = "" + (window.getSelection ? window.getSelection                                     : document.getSelection ? document.getSelection                                                              : document.selection.createRange.text); if (!q) q = prompt("You didn't select any text. Enter a search phrase:", ""); if (q!=null) // location="http://www.google.com/search?q=" + escape(q).replace(/ /g, "+"); window.open("http://www.google.com/search?q=" + escape(q).replace(/ /g, "+") ,'new-tab') ; } // ************** // Month section // ************** function whackMonth { var d=new Date var f = document.editform ; var month=new Array(12) month[0]="January"; month[1]="February"; month[2]="March"; month[3]="April"; month[4]="May"; month[5]="June"; month[6]="July"; month[7]="August"; month[8]="September"; month[9]="October"; month[10]="November"; month[11]="December"; f.wpTextbox1.value += "\n== "+month[d.getMonth]+" "+d.getFullYear+" ==\n\n" ; f.wpSummary.value = month[d.getMonth] ; f.wpMinoredit.checked=true; f.wpWatchthis.checked=false; if (f.wpTextbox1.scrollTop || true) f.wpTextbox1.scrollTop = f.wpTextbox1.scrollHeight ; } // ** // Check for month when making an edit // ** function whackCheckMonth { var d=new Date var f = document.editform ; var month=new Array( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December") ; var myregexstr = new String ('== *' + month[d.getMonth] + " " + d.getFullYear + ' *==') ; var myregex = new RegExp(myregexstr); if (myregex.test(f.wpTextbox1.value) != true) { f.wpTextbox1.value += "\n== "+month[d.getMonth]+" "+d.getFullYear+" ==\n" ; f.wpSummary.value = month[d.getMonth] ; if (f.wpTextbox1.scrollTop || true) f.wpTextbox1.scrollTop = f.wpTextbox1.scrollHeight ; } } // ************** // Warnings // ************** function whackEdit (message, msg2, summary, level) { var f = document.editform ; var tbox = document.editform.wpTextbox1 ; var a = "" + (window.getSelection ? window.getSelection                                     : document.getSelection ? document.getSelection                                                              : document.selection.createRange.text); if (msg2 != "") { a = prompt ("Article name?\n(Empty+OK for a generic message; Cancel aborts.)", a) ; if (a == null) return ; a = a.replace(/^\s+/, '') ; a = a.replace(/\.?\s*$/, ''); if (a != null && a != "") { message = message.replace(/\|/,"|"+a) ; summary += " on " + a + "" ; } else { message = msg2 ; }   }	whackCheckMonth  ; f.wpTextbox1.value += "\n\n" + message + " \n" ; f.wpSummary.value = summary ; if (document.getElementById('wpMinoredit')) f.wpMinoredit.checked=false; f.wpWatchthis.checked=false ; f.wpTextbox1.focus; if (f.wpTextbox1.scrollTop || true) f.wpTextbox1.scrollTop = f.wpTextbox1.scrollHeight ; } function whackEditBlock (message, msg2, summary, level) { var f = document.editform ; var tbox = document.editform.wpTextbox1 ; var a = "" + (window.getSelection ? window.getSelection                                     : document.getSelection ? document.getSelection                                                              : document.selection.createRange.text); if (msg2 != "") { a = prompt ("Block duration?\nFormat: for 28 hours\n(Empty+OK for a 31 hours; Cancel aborts.)", a) ; if (a == null) return ; a = a.replace(/^\s+/, '') ; a = a.replace(/\.?\s*$/, ''); if (a != null && a != "") { message = message.replace(/\|/,"|"+a) ; summary += " for " + a ; } else { message = msg2 ; summary += " for 31 hours"; }   }	whackCheckMonth  ; f.wpTextbox1.value += "\n\n" + message + " \n" ; f.wpSummary.value = summary ; if (document.getElementById('wpMinoredit')) f.wpMinoredit.checked=false; f.wpWatchthis.checked=false ; f.wpTextbox1.focus; if (f.wpTextbox1.scrollTop || true) f.wpTextbox1.scrollTop = f.wpTextbox1.scrollHeight ; } function whackEditWelcome (message, msg2, summary, level) { var f = document.editform ; var tbox = document.editform.wpTextbox1 ; var a = "" + (window.getSelection ? window.getSelection                                     : document.getSelection ? document.getSelection                                                              : document.selection.createRange.text); if (msg2 != "") { a = prompt ("Any extra messages?\n(Empty+OK for a generic message; Cancel aborts.)", a) ; if (a == null) return ; a = a.replace(/^\s+/, '') ; a = a.replace(/\.?\s*$/, ''); if (a != null && a != "") { message = message.replace(/\|/,"|"+a) ; summary += "" ; } else { message = msg2 ; }   }	whackCheckMonth  ; f.wpTextbox1.value += "\n\n" + message + " \n" ; f.wpSummary.value = summary ; if (document.getElementById('wpMinoredit')) f.wpMinoredit.checked=false; f.wpWatchthis.checked=false ; f.wpTextbox1.focus; if (f.wpTextbox1.scrollTop || true) f.wpTextbox1.scrollTop = f.wpTextbox1.scrollHeight ; } function whackWelcome(x) { whackEditWelcome (" ~",   " ~",      "Welcome", 0); } function whackVandal (x) { whackEdit (" ~", " ~", "Nonconstructive edits", x); } function whackTest  (x) { whackEdit (" ~", " ~", "Editing tests", x); } function whackDelete (x) { whackEdit (" ~", " ~", "Blanking", x); } function whackTout  (x) { whackEdit (" ~",    " ~",   "Touting", 0); } function whackBlock (x) { whackEditBlock (" ~",    " ~",   "Blocked", 0); } // ************************************************** // Installation // ************************************************** window.whack_addlilink=function(tabs, n, url, name, id, title, key){ var ix ; var li = document.createElement('li'); if (n > 0) { li.appendChild(document.createTextNode(name)) ; for (ix = 1 ; ix <= n ; ix++) { var na = document.createElement('a'); na.href = url.replace(/XX/g, ix) ; na.appendChild(document.createTextNode(" "+ix)); li.appendChild(na); }   } else { var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); li.appendChild(na); }   if(id) li.id = id; 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; } window.whack_addToolboxLink=function(n, url, name, id){ var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; whack_addlilink(tb, n, url, name, id); } window.playWhackMoles=function { if (document.title.match("Editing User talk:") || document.title.match("Creating User talk:") ) { whack_addlilink (document.getElementById('p-tb').getElementsByTagName('ul')[0],        0, "//en.wikivoyage.org/wiki/User:Snowolf/JS_toolbox",         "JS Toolbox:", "uTemplates") ;

whack_addToolboxLink(1, 'javascript:{whackWelcome(XX);};void(0);',   'Welcome', 'toolbox_welcome'); whack_addToolboxLink(2, 'javascript:{whackVandal(XX);};void(0);',   'Vandalism', 'toolbox_vand'); whack_addToolboxLink(2, 'javascript:{whackTest(XX);};void(0);',   'Tests', 'toolbox_test'); whack_addToolboxLink(2, 'javascript:{whackDelete(XX);};void(0);',   'Blanking', 'toolbox_test'); whack_addToolboxLink(1, 'javascript:{whackTout(XX);};void(0);',   'Touting', 'toolbox_tout'); whack_addToolboxLink(1, 'javascript:{whackBlock(XX);};void(0);',   'Block', 'toolbox_block'); } else { whack_addToolboxLink(0, 'javascript:{whackGoogleLookup;};void(0);', 'Google', 'toolbox_googlelookup'); } } // onload window.simpleAddOnload=function(f) { if (window.addEventListener) window.addEventListener("load", f, false); else if (window.attachEvent) window.attachEvent("onload",f); } simpleAddOnload(playWhackMoles); //