Jump to content

User:Jacek Kendysz/whackamole.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/*
 
 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
  
 Original version by User:Kbh3rd. Modified by User:Jacek_Kendysz
  
 */
 // <pre><nowiki>
  
  
 // ****************
 //  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') ;
 }
 
 // **************
 // Warnings
 // **************

 function whackEdit (message, msg2, summary) {
    var f = document.editform ;
    var tbox = document.editform.wpTextbox1 ;
    var a = "" + (window.getSelection ? window.getSelection()
                                      : document.getSelection ? document.getSelection()
                                                              : document.selection.createRange().text);
   message = msg2 ;

    f.wpTextbox1.value += "\r==March 2009=="
    f.wpTextbox1.value += "\n" + message + " ~~~~" ;
    f.wpSummary.value = summary ;
    f.wpMinoredit.checked=false;
    f.wpWatchthis.checked=false;
    f.wpTextbox1.focus();
    if (f.wpTextbox1.scrollTop || true) f.wpTextbox1.scrollTop = f.wpTextbox1.scrollHeight ;
 }
 
 function whackTest1      () { whackEdit ("-", "{{subst:uw-test1}}",       "{{subst:uw-test1}}"); }
 function whackTest2      () { whackEdit ("-", "{{subst:uw-test2}}",       "{{subst:uw-test2}}"); }
 function whackTest3      () { whackEdit ("-", "{{subst:uw-test3}}",       "{{subst:uw-test3}}"); }
 function whackVandalism1 () { whackEdit ("-", "{{subst:uw-vandalism1}}",  "{{subst:uw-vandalism1}}"); }
 function whackVandalism2 () { whackEdit ("-", "{{subst:uw-vandalism2}}",  "{{subst:uw-vandalism2}}"); }
 function whackVandalism3 () { whackEdit ("-", "{{subst:uw-vandalism3}}",  "{{subst:uw-vandalism3}}"); }
 function whackVandalism4 () { whackEdit ("-", "{{subst:uw-vandalism4}}",  "{{subst:uw-vandalism4}}"); }
 function whackDelete1    () { whackEdit ("-", "{{subst:uw-delete1}}",     "{{subst:uw-delete1}}"); }
 function whackDelete2    () { whackEdit ("-", "{{subst:uw-delete2}}",     "{{subst:uw-delete2}}"); }
 function whackDelete3    () { whackEdit ("-", "{{subst:uw-delete3}}",     "{{subst:uw-delete3}}"); }
 function whackDelete4    () { whackEdit ("-", "{{subst:uw-delete4}}",     "{{subst:uw-delete4}}"); }
 function dummyli         () { whack_addToolboxLink('#', '<font size="1" color="white">.</font>', null, true); }
 
 // **************************************************
 // Installation
 // **************************************************
 
 window.whack_addlilink=function(tabs, url, name, id, title, key, raw){
    var na = document.createElement('a');
    na.href = url;
    if(raw) na.innerHTML = name;
	else 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;
 }
 
 window.whack_addToolboxLink=function(url, name, id, raw){
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    whack_addlilink(tb, url, name, id, null, null, raw);
 }
 
 window.playWhackMoles=function() {
 
  if (document.title.match("Editing User talk:") ) {
    dummyli();
    dummyli();
    whack_addToolboxLink('javascript:{whackTest1();};void(0);',       'test1',      'toolbox_test1');
    whack_addToolboxLink('javascript:{whackTest2 ();};void(0);',      'test2',      'toolbox_test2');
    whack_addToolboxLink('javascript:{whackTest3();};void(0);',       'test3',      'toolbox_test3');
    dummyli();    
    whack_addToolboxLink('javascript:{whackVandalism1();};void(0);',  'vandalism1', 'toolbox_vandalism1');
    whack_addToolboxLink('javascript:{whackVandalism2();};void(0);',  'vandalism2', 'toolbox_vandalism2');
    whack_addToolboxLink('javascript:{whackVandalism3();};void(0);',  'vandalism3', 'toolbox_vandalism3');
    whack_addToolboxLink('javascript:{whackVandalism4();};void(0);',  'vandalism4', 'toolbox_vandalism4');
    dummyli();    
    whack_addToolboxLink('javascript:{whackDelete1();};void(0);',     'delete1',    'toolbox_delete1');
    whack_addToolboxLink('javascript:{whackDelete2 ();};void(0);',    'delete2',    'toolbox_delete2');
    whack_addToolboxLink('javascript:{whackDelete3 ();};void(0);',    'delete3',    'toolbox_delete3');
    whack_addToolboxLink('javascript:{whackDelete4 ();};void(0);',    'delete4',    'toolbox_delete4');
  } else {
    whack_addToolboxLink('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);
 
 // </nowiki></pre>