Jump to content

User:GeorgeMoney/aDel.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.
//<pre><nowiki>
var pathu = "en.wikipedia.org/wiki/";

function intitle(string) {
if(string == "") { return "Missing parameter 'string'"; }
if(window.location.href.indexOf(string) != -1) { return true; }
else { return false; }
}

function dotab(jsaction, title) {
var tbs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
addlilink(tbs, 'javascript:'+jsaction, title);
}


//-----------AUTOEDIT----------
/*
===parameters:===
__mandatory__:
'txt' is the text you want to put in the edit box;
'sum' is your summary;
example: autoedit('hello', 'saying hello to user');

__optional__:
_mode_: the mode to use. Modes are:
        'r': replace all existing text (or create page if no text) with your text;
		'a': append your text to bottom of original;
		't': add your text to top of original text;
	    mode examples: autoedit('{{header}}', 'adding header to all pages', 't');
		default mode: 'r';
_watch_: To click 'Watch this page'. Use either true or false;
         watch examples: autoedit('hi', 'saying hi', '', true);
		 watch notes: because this parameter occurs after the mode parameter, if you dont want to include the mode parameter, leave it like ''. so autoedit('text','summary','',true) notice how the mode is '', but you can still use a mode like 'a';
		 watch default: false;
_minor_: like watch except to mark edit as minor;
         minor default: false;
_autoclick_: What button to click for autoclick
             autoclick options: 'wpSave', 'wpDiff', 'wpPreview';
	  to not use autoclick, value is 'none';
             autoclick default: wpSave;

*/
function autoedit(txt, sum, mode, watch, minor, autoclick) {
/*
if(booluse) { var otherif = (intitle('action=submit')); }
else { var otherif = false; }
*/

if(!txt||!sum) { return "Missing parameters"; }

if(!autoclick) { autoclick = 'wpSave'; }


if(!mode) { mode = 'r'; }

if(watch == "false") { watch = false; }
if(minor == "false") { minor = false; }

if(!watch) { document.getElementById('wpWatchthis').checked = ""; } else { document.getElementById('wpWatchthis').checked = "checked"; }
if(!minor) { document.getElementById('wpMinoredit').checked = ""; } else { document.getElementById('wpMinoredit').checked = "checked"; }

var txta = document.getElementById('wpTextbox1');
var sma = document.getElementById('wpSummary');

if(mode=='r') {
txta.value = txt;
} else if(mode=='a') {
txta.value += '\n'+txt;
} else if(mode=='t') {
txta.value = txt + '\n' + document.getElementById('wpTextbox1').value;
}

sma.value = sum;

if(autoclick!='none') {
document.getElementById(autoclick).click();
}


}

//Originally from [[User:Lupin/autoedit.js]]
function gv(paramName) {
  var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
  var h=document.location;
  var m;
  if (m=cmdRe.exec(h)) {
    try { 
      return unescape(decodeURI(m[1]));
    } catch (someError) {}
  }
  return null;
};



/*
Uses of parameters explained above, this comment is just a map to show what url params go to what autoedit params;

URLPARAM = FUNCTIONPARAM;

myedit = txt;
mysum = sum;
mymode = mode;
mywatch = watch;
myminor = minor;
myautoclick = autoclick;

http://en.wikipedia.org/wiki/bob?action=edit&myedit=jim&mysum=fred
+OPTIONALS:  &mymode=t&mywatch=false&myminor=true&myautoclick=wpSave

*/
if(intitle('myedit') && intitle('action=edit')) {
addOnloadHook(function() {
var txt = gv('myedit');
var sum = gv('mysum');
var mode = gv('mymode');
var watch = gv('mywatch');
var minor = gv('myminor');
var autoclick = gv('myautoclick');
autoedit(txt,sum,mode,watch,minor,autoclick);
});
}

function askwarn() {
var page = prompt('What did the person vandalize? \n If none given, then the page template is not used, \n the other one that does not need a page is used ');
if(page==null) { alert('Action canceled'); return; }
var num = prompt('What test- number? If none given, 1 is used.');
if(num==null) { alert('Action canceled'); return; }
if(confirm('Autosave? Or just insert text? \n press ok to auto-save, \n cancel to just insert text to editbox. ')) { var aut = 'wpSave'; } else { var aut = 'none'; }
if(page) { var usen = '-n|'+page; var extrasum = ' for vandalism to page: [['+page+']]'; } else { var usen = ''; extrasum = ''; }
if(!num) { var num = '1'; }
if(document.getElementById('ca-delete')) { var maxnum = 5; } else { var maxnum = 4; }
if(parseInt(num) > maxnum) { var num = maxnum; }
if(num == 5) {
if(confirm('You used the test-5 warning, admin. \n Would you like to autoblock? \nIf you press ok, a dialog box will come up asking \n for the block expiry and summary.')) {
var blreason = prompt('Block reason. If none provided, reason is \'vandalism\'');
if(blreason == null) { alert('Action Canceled'); } else {
if(blreason == "") { blreason = "Vandalism"; }
var bltime = prompt('Block expiry? If none provided, time is 24 hours');
if(bltime == null) { alert('Action Canceled'); } else {
if(bltime == "") { bltime = "24 hours"; }
window.open('http://'+pathu+'Special:Blockip/'+wgTitle.replace(' ','_').split('/')[0]+'?autoblock=true&blreason='+escape(blreason)+'&bltime='+escape(bltime), 'blockwindow', 'status=0,toolbar=0,location=0,menubar=0,directories=0,scrollbars=0,resizable=0,height=1,width=1');
}
}
}
}
var txt = '{{su'+'bst:test'+num+usen+'|}} ~~'+'~~';
autoedit(txt,'warning user with test-'+num+extrasum,'a',true,'',aut);
}

if(intitle('autoblock')) { addOnloadHook(function() { 
for(var i=0; i<document.getElementsByTagName('input').length; i++) {
var k = document.getElementsByTagName('input')[i];
if(k.name == "wpBlockOther") {
k.value = gv('bltime');
oktodo = true;
} else if(k.name=='wpBlockReason') {
k.value=gv('blreason');
oktodo = true;
} else if(k.name == 'wpBlock'&&oktodo) {
k.click();
window.close();
}
}
}); }


if(intitle('dowarn')) { addOnloadHook(function() {
alert('Due to technical limitations, you must click the warn tab now.');
}); }

addOnloadHook(function() {
if(intitle('action=edit')||intitle('action=submit')) {
var taburl = "askwarn()";
} else {
if(document.getElementById('ca-edit')) {
if(document.getElementById('ca-edit').firstChild.href.indexOf('&') != -1) { var symbol = "&"; } else { var symbol = "?"; }
if(symbol=="&") { var fnd = /User_talk:(.*)\/.*&ac/; var rpl = 'User_talk:$1&ac'; } else { var fnd = /User_talk:(.*)\/.*\?ac/; var rpl = 'User_talk:$1?ac'; } 
var taburl = "window.location.href = (\'"+(document.getElementById('ca-edit').firstChild.href.replace('User:','User_talk:')+symbol+"dowarn=true").replace(fnd,rpl)+"\')";
}
}
if(intitle('User')&&document.getElementById('ca-edit')) {
dotab(taburl,'warn');
}
});

//</nowiki></pre>