User:Joeytje50/AWB.js

/* To use this script, add a line with importScriptPage('User:Joeytje50/AWBload.js', 'dev') on the wiki. This will allow any user to use this script. If you want to limit usage to certain users, put var CheckList = ["Username1", "Username2", "User 3"]; on a line above the import of this script. Mind that this is case-sensitive.

if (CheckList.indexOf(wgUserName)!=-1||CheckList.length==0) { //setting main variables function setCookie( c_name, value, expiredays ) { var exdate = new Date; exdate.setDate( exdate.getDate + expiredays); document.cookie = c_name + "=" + escape(value) + ( ( expiredays === null ) ? "" : ";expires=" + exdate.toGMTString ); } function getCookie( c_name ) { if ( document.cookie.length > 0 ) { var c_start = document.cookie.indexOf( c_name + "=" ) if ( c_start !== -1 ) { c_start = c_start + c_name.length + 1; var c_end = document.cookie.indexOf( ";", c_start ); if ( c_end === -1 ) { c_end = document.cookie.length; }			return unescape( document.cookie.substring( c_start, c_end ) ); } 	}	return ""; } var bot = (wgUserGroups.indexOf('bot')!=-1); var sysop = (wgUserGroups.indexOf('sysop')!=-1); //Interface $('body').html(' \n '); $('#inputsWindow').html(' \nEditing box: \n \n \n  '); $('#inputsBox').html(' \nEnter list of pages: ( save |load ) \n \n \n '); $('.tabs').html(' \n \n \n '+(sysop?' ':'')+' done '); $('.tabholder').html(' Content \n Editing \n Skip '+(sysop?' Other actions ':'')); $('#replacesPopup').html('add more inputs Replace:  \n With:  \n  Regular Expression \nRegular Expression flags:  ') $('.tabc[data-tab="1"]').html('Article list: Remove duplicates Sort \n Replace:  \n With:  \n  Regular Expression \nRegular Expression flags: <input type="text" id="regexFlags"/> <button id="replacesButton">More replace inputs ') $('.tabc[data-tab="2"]').html(' Summary: <input class="fullwidth" type="text" id="summary" maxlength="250"/> \n <input type="checkbox" id="minorEdit" checked="checked"> Minor edit \n <input type="checkbox" id="followPage"> Follow this page (<button id="followNow" disabled="disabled" accesskey="f" title="Follow this page without having to edit ['+tooltipAccessKeyPrefix+'f]">or click here ) <input type="checkbox" id="unfollowPage"> Unfollow this page (<button id="unfollowNow" disabled="disabled" accesskey="u" title="Unfollow this page without having to edit ['+tooltipAccessKeyPrefix+'u]">or click here ) '+(bot?'\n <input type="checkbox" id="autosave"> Save automatically \n':'')+'<button id="stopbutton" disabled="disabled" accesskey="q" title="['+tooltipAccessKeyPrefix+'q]">Stop <button id="startbutton" accesskey="a" title="['+tooltipAccessKeyPrefix+'a]">Start <button class="editbutton" id="editbutton-1" disabled="disabled" accesskey="s" title="['+tooltipAccessKeyPrefix+'s]">Save <button class="editbutton" id="editbutton-3" disabled="disabled" accesskey="p" title="['+tooltipAccessKeyPrefix+'p]">Preview <button class="editbutton" id="editbutton-2" disabled="disabled" accesskey="n" title="['+tooltipAccessKeyPrefix+'n]">Skip <button class="editbutton" id="editbutton-4" disabled="disabled" accesskey="d" title="['+tooltipAccessKeyPrefix+'d]">Diff ') $('.tabc[data-tab="3"]').html(' <input type="checkbox" id="skipNoChange" checked="checked"> No changes \n <input type="checkbox" id="skipNoPage" checked="checked"> Page doesn\'t exist \n Redirects: <label title="Edit the page the redirect leads to"><input type="radio" class="redirects" value="follow" name="redir"> Follow <label title="Skip redirects"><input type="radio" class="redirects" value="skip" name="redir"> Skip <label title="Edit the redirect itself instead of the page it redirects to"><input type="radio" class="redirects" value="edit" name="redir" checked="checked"> Edit \n Contains: <input class="fullwidth" type="text" id="skipContains"> \n Doesn\'t contain: <input class="fullwidth" type="text" id="skipNotContains"> \n <input type="checkbox" id="containRegex"> Regular Expression \n<label title="Any flags for regular expressions, for example i for ignorecase." style="display:none;">Regular Expression flags: <input type="text" id="containFlags"/> ') $('.tabc[data-tab="4"]').html((sysop?' <input type="checkbox" id="suppressRedir"> Suppress redirects Also move (when exists): <input type="checkbox" id="movetalk"> talk page <input type="checkbox" id="movesubpage"> subpages  New pagename: <input type="text" id="moveTo"> <button class="editbutton" id="movePage" disabled="disabled" accesskey="m" title="['+tooltipAccessKeyPrefix+'m]">Move ':)+(sysop?'<button class="editbutton delete" id="deletePage" disabled="disabled" accesskey="x" title="['+tooltipAccessKeyPrefix+'x]"> Delete Protect: <span title="Create protection when page doesn\'t exist">Edit:<select id="editProt"><option value="all" selected="selected">No protection <option value="autoconfirmed">Autoconfirmed  Sysop only  Move:<select id="moveProt"><option value="all" selected="selected">No protection <option value="autoconfirmed">Autoconfirmed  Sysop only  \n Expiry: <input type="text" id="protectExpiry"/> \n <input type="checkbox" id="cascadeProt"> Cascading protection \n<button class="editbutton" id="protectPage" disabled="disabled">Protect ':)+(sysop?'<button class="editbutton" id="skipPage" title="['+tooltipAccessKeyPrefix+'n]">Skip ':'')) $('head').append('<style type="text/css">body {background:none !important;} \n #resultWindow {resize:both;height:200px;width:99.5%;border:1px solid #555;padding:3px;overflow:auto;} #resultWindow * {resize:none;} \n #inputsWindow {height:300px;width:99.5%;margin-top:-2px;} \n #inputsBox {height:100%;} \n #editBox {width:40%;height:100%;float:right;position:relative;} \n #articleBox {width:15%;height:100%;float:left;margin-right:5px;position:relative;z-index:5;} \n textarea {width:100%;height:100%;} \n #editBoxArea {position:absolute;z-index:10;bottom:-24px;right:0px;} \n .tabs {height:100%;padding-top:5px;position:relative;} \n #progress {position:absolute;bottom:-20px;border:1px solid #555;margin-left:15.4%;width:44%;background:white;} \n .tabs .tabc {display:none;height:100%;border:1px solid #888;margin-top:-2px;} \n .tabs .tabc.active {display:block;} \n .tabc .fullwidth {width:44%;} \n #regexFlags, #containFlags {width:30px;} \n b {font-size:85%;} \n .tab {padding:0 3px;border:1px solid #888;border-bottom:none;border-radius:2px 2px 0 0;background:#FFF;cursor:pointer;} \n .tab:hover {background:#DDD;position:static !important;} \n .tab:active {background:#BBB;} \n .tab.active {background:#BBE;} \n body {font:16px "Times New Roman";} \n .editbutton {padding:10px;font-size:115%;color:#262;} #editbutton-2 {color:#A33;} \n #stopbutton {color:#F00;} #startbutton {color:#008000;} \n #articleList[disabled]:first-line {background-color:#77F;color:#000;} \n #deletePage {color:#F00;} \n #protectPage {color:#00F;} \n .overlay {z-index:30;cursor:pointer;position:fixed;top:0px;left:0px;width:100%;height:100%;background:rgba(0,0,0,0.3);} #replacesPopup {position:fixed;z-index:50;top:15%;left:25%;width:50%;height:70%;border:2px solid black;padding:5px;overflow:auto;background:white;} .cookieSave span {cursor:pointer;color:blue;} .cookieSave span:hover {text-decoration:underline;} ') .append('<link rel="stylesheet" href="http://images.wikia.nocookie.net/common/skins/common/diff.css" />'); $('.tab').click(function {	$('.active').removeClass('active');	$(this).addClass('active');	$('.tabc[data-tab="'+$(this).attr('data-tab')+'"]').addClass('active') }) $('#useRegex, #containRegex, .useRegex').click(function {	if ($(this).is(':checked')) {		$(this).parent.next.next.css('display','inline');	} else {		$(this).parent.next.next.css('display','none');	} }) function progress(p) { p = p!='back'?p+' <img src="http://images2.wikia.nocookie.net/dev/images/8/82/Facebook_throbber.gif" alt="loading..."/>':'done'; $('#progress').html(p); } $('#replacesButton').click(function {	$('#replacesPopup, .overlay').css('display','block'); }) $('.overlay').click(function {	$('#replacesPopup, .overlay').css('display','none'); }) $('#moreReplaces').click(function {	$('#replacesPopup').append(' Replace: <input type="text" class="replaceText"/> \n With: <input type="text" class="replaceWith"/> \n <input type="checkbox" class="useRegex"/> Regular Expression \n<label title="Any flags for regular expressions, for example i for ignorecase." style="display:none;">Regular Expression flags: <input type="text" class="regexFlags"/> ')	$('#useRegex, #containRegex, .useRegex').click(function { if ($(this).is(':checked')) { $(this).parent.next.next.css('display','inline'); } else { $(this).parent.next.next.css('display','none'); }	}) }) //-- $('#setCookie').click(function {	setCookie('AWBPagesList',$('#articleList').val,1000)	$('#articleList').select }) $('#getCookie').click(function {	var newList = getCookie('AWBPagesList')==''?$('#articleList').val:getCookie('AWBPagesList')	$('#articleList').val(newList).select }) //-- function replaceAll(input) { var replaces = document.getElementById('replacesPopup').getElementsByClassName('replaces') var result = input; for (i=0;i<replaces.length;i++) { var useRegex = replace==''?true:replaces[i].getElementsByClassName('useRegex')[0].checked var regexFlags = replaces[i].getElementsByClassName('regexFlags')[0].value var replace = replaces[i].getElementsByClassName('replaceText')[0].value replace = replace==''?'$':replace; replace = useRegex?(new RegExp(replace, regexFlags)):replace; rWith = replaces[i].getElementsByClassName('replaceWith')[0].value result = result.replace(replace, rWith) }	return result; } //-- function removeDupes(a) { for (i=0;a.join('\n').match(/(.*)\n((.*\n)*)\1\n/);i++) { a = a.join('\n').replace(/(.*)\n((.*\n)*)\1\n/g, '$1\n$2').split('\n'); }	if (a[a.length-1]==a[a.length-2]) { a = a.join('\n').replace(/\n.*$/,'').split('\n'); }	return a } $('#removeDupes').click(function {	var articleList = $('#articleList').val.replace(/^$\r/, '')	$('#articleList').val(removeDupes(articleList.split('\n')).join('\n')) }) $('#sortArticles').click(function {	var articleList = $('#articleList').val.replace(/^$\n/m, '')	$('#articleList').val(articleList.split('\n').sort.join('\n')) }) //-- function blink(e,t) { t=t?t:500; $(e).attr('disabled','disabled') .children.animate({opacity:'0.1'},t-100) .animate({opacity:'1'},t) .animate({opacity:'0.1'},t-100) .animate({opacity:'1'},t) setTimeout("$('"+e+"').removeAttr('disabled')",t*4-400) } //-- function callAPI(data, method, callback, addurl) { data['format'] = 'json'; $.ajax({		data: data,		dataType: 'json',		url: wgScriptPath + '/api.php' + (addurl?addurl:''),		type: method,		cache: false,		success: function(response) {			if (response.error)				alert('API error: ' + response.error.info);			else 				callback(response);		},		error: function(xhr, error) { alert('AJAX error: ' + error) }	}); } function watchPage(pagename) { progress('Adding page to watchlist') callAPI({		'action':'watch',		'title':pagename	}, 'POST', function(response) {		$('#followNow').after(' '+pagename+' has been added to your watchlist. ');		progress('back')	}); } function unwatchPage(pagename) { progress('Removing page from watchlist') callAPI({		'action':'watch',		'unwatch':'yes',		'title':pagename	}, 'POST', function(response) {		$('#unfollowNow').after(' '+pagename+' has been removed from your watchlist. ');		progress('back')	}); } function getDiff { progress('Getting edit diff') var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0] var editBoxInput = $('#editBoxArea').val; redirect = $('input.redirects:checked').val; redirects = redirect=='follow'?'redirects':'inprop'; callAPI({		'action': 'query',		'prop': 'info|revisions',		'indexpageids': 'true',		'titles': pagename,		'rvlimit': '1',		'rvdifftotext': editBoxInput	}, 'POST', function(response) {		var pageExists = response.query.pages["-1"]?false:true;		var page = pageExists?response.query.pages[response.query.pageids[0]]:;		var diff = pageExists?page.revisions[0].diff['*']:;		diff = pageExists?(diff!=''?' ':' No changes made. Press skip to go to the next page in the list. '):' Page doesn\'t exist, diff can not be made. ';		$('#resultWindow').html(diff)		progress('back')	}, '?'+redirects+'=redirect'); } function getPageInfo(pagename,action) { var editBoxInput = $('#editBoxArea').val; if ($('#articleList').val.replace(/^$\n/m, '').length == 0) { stopEditing } else { redirect = $('input.redirects:checked').val; redirects = redirect=='follow'||redirect=='skip'?'redirects':'inprop'; var progressAction = action=='submit'?'Submitting edit':(action=='preview'?'Getting preview':(action=='get'?'Getting page contents':'')); progressAction = action=='move'?'Moving page':(action=='delete'?($('#deletePage').is('.delete')?'D':'Und')+'eleting page':(action=='protect'?'Protecting page':progressAction)); progress(progressAction) callAPI({	'action': 'query',	'prop': 'info|revisions',	'intoken': 'edit|delete|protect|move',	'titles': pagename,	'rvprop': 'content|timestamp|ids',	'rvlimit': '1',	'indexpageids': 'true' }, 'GET', function(response) {	var page = response.query.pages[response.query.pageids[0]];	var content = typeof(page.revisions)!="undefined"?page.revisions[0]['*']:'';	var pageExists = response.query.pages["-1"]?false:true;	var isRedirect = response.query["redirects"]||page["redirectto"]?true:false;	var newContent = content;	if (!pageExists&&$('#deletePage').is('.delete')) {		$('#deletePage').removeClass('delete').addClass('undelete').children('span').html('Undelete')		blink('#deletePage')	} else if (pageExists&&$('#deletePage').is('.undelete')) {		$('#deletePage').removeClass('undelete').addClass('delete').children('span').html('Delete')		blink('#deletePage')	}	if (!pageExists) {		$('#movePage').attr('disabled','disabled') } else { $('#movePage').removeAttr('disabled') }	if (doReplace) { newContent = replaceAll(content.replace(replace, replaceWith)); }	if (action=='submit') { var minorEdit = $('#minorEdit').is(':checked'); var pagename = redirects=='redirects'?response.query.redirects[0]["to"]:$('#articleList').val.replace(/^$\n/m, '').split('\n')[0]; var summary = $('#summary').val; callAPI({			'title': pagename,			'bot': 'yes',			'summary': summary,			'action': 'edit',			'basetimestamp': typeof(page.revisions)!="undefined"?page.revisions[0].timestamp:,			'token': page.edittoken,			'text': $('#editBoxArea').val		}, 'POST', function(response) {			$('#articleList').val($('#articleList').val.replace(/^.*\n?/,))			var pagename = $('#articleList').val.replace(/^$\n/m, ).split('\n')[0]			defVars("getPageInfo(pagename,'get')")			progress('back')		}, (minorEdit?'?minor=yes':)); if (followPage) { watchPage(pagename); } else if (unfollowPage) { unwatchPage(pagename); }	} else if (action=='preview') { $.ajax({			data: {				'wpTextbox1': editBoxInput			},			dataType: 'text',			type: 'POST',			cache: false,			url: wgScriptPath + '/index.php?title='+pagename+'&action=submit&wpPreview=true&live=true',			success: function(response) {				$('#resultWindow').html(response.replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&amp;/g, '&').replace(/&quot;/g, '"'));				$('#resultWindow div.previewnote').remove				progress('back')			}		});	} else if (action=='get') {		progress('back')		if (!(skipNoChange && content == newContent) && (!content.match(skipContains) || !skipContains) && (content.match(skipNotContains) || !skipNotContains) && !(skipNoPage && !pageExists) && !(redirect=='skip' && isRedirect)) {			$('#editBoxArea').val(newContent);			getDiff			if ($('#autosave').is(':checked')&&bot) {				defVars("getPageInfo(pagename,'submit')")			}		} else {			$('#articleList').val($('#articleList').val.replace(/^.*\n?/,'')) var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0] defVars("getPageInfo(pagename,'get')") }	} else if (action=='move') { var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0] var topage = $('#moveTo').val var summary = $('#summary').val; var movetalk = $('#moveTalk').is(':checked') var movesubpage = $('#moveSubpage').is(':checked') var noredir = $('#suppressRedir').is(':checked') callAPI({			'action':'move',			'from':pagename,			'to':topage,			'token':page.movetoken,			'reason':summary,			'ignorewarnings':'yes'		}, 'POST', function(response) {			progress('back')			$('#articleList').val($('#articleList').val.replace(/^.*/,topage))		}, (movetalk||movesubpage||noredir?'?':) + (movetalk?'&movetalk=yes':) + (movesubpage?'&movesubpages=yes':) + (noredir?'&noredirect=yes':)) } else if (action=='delete') { var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0] var summary = $('#summary').val; var undeltoken = typeof response.query.deletedrevs[0]=='undefined'?'':response.query.deletedrevs[0].token; callAPI({			'action':(pageExists?'delete':'undelete'),			'title':pagename,			'token':(pageExists?page.deletetoken:undeltoken),			'reason':summary		}, 'POST', function(response) {			progress('back')			$('#articleList').val($('#articleList').val.replace(/^.*\n?/,))			var pagename = $('#articleList').val.replace(/^$\n/m, ).split('\n')[0]			defVars("getPageInfo(pagename,'get')")		}) } else if (action=='protect') { var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0] var summary = $('#summary').val; var editprot = $('#editProt').val; var moveprot = $('#moveProt').val; callAPI({			'action':'protect',			'title':pagename,			'token':page.protecttoken,			'reason':summary,			'expiry':$('#protectExpiry').val!=''?$('#protectExpiry').val:'infinite',			'protections':(pageExists?'edit='+editprot+'|move='+moveprot:'create='+editprot)		}, 'POST', function(response) {			progress('back')		}) } }, '?'+redirects+'=redirect'+(sysop?'&list=deletedrevs&drprop=token':)); } } //--- var useRegex,RegexFlags,doReplace,replace,replaceWith,summary,minorEdit,followPage,skipNoChange,skipNoPage,skipContains,skipNotContains,containRegex,containFlags,articleList,pagename; function defVars(run) {	articleList = $('#articleList').val.replace(/^$\n/m, ).split('\n');	useRegex = $('input#replaceText').val.length>0? $('#useRegex').is(':checked') : true;	RegexFlags = useRegex?$('#regexFlags').val:'';	doReplace = ($('input#replaceText').val.length>0 || $('input#replaceWith').val.length>0)?true:false;	replace = $('input#replaceText').val.length>0? $('input#replaceText').val : '$';	replace = useRegex?(new RegExp(replace, RegexFlags)):replace;	replaceWith = $('input#replaceWith').val;	summary = $('#summary').val;	minorEdit = $('#minorEdit').is(':checked')?true:false;	followPage = $('#followPage').is(':checked'); unfollowPage = $('#unfollowPage').is(':checked'); skipNoChange = $('#skipNoChange').is(':checked'); skipNoPage = $('#skipNoPage').is(':checked'); skipContains = $('#skipContains').val.length>0? $('#skipContains').val : null; skipNotContains = $('#skipNotContains').val.length>0? $('#skipNotContains').val : null; containRegex = $('#containRegex').is(':checked'); containFlags = containRegex?$('#containFlags').val:''; skipContains = containRegex&&skipContains?(new RegExp(skipContains,containFlags)):skipContains; skipNotContains = containRegex&&skipNotContains?(new RegExp(skipNotContains,containFlags)):skipNotContains; redirect = $('input.redirects:checked').val; redirects = redirect=='follow'||redirect=='skip'?'redirects':'inprop'; pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0] eval(run); } //--- $('#startbutton').click(function { var articleList = $('#articleList').val.replace(/^$\n/m, '') if (articleList.length==0) {	alert('Please enter some articles to browse before clicking start.') } else {	$('#stopbutton, .editbutton, #followNow, #unfollowNow').removeAttr('disabled')	$('#startbutton, #articleList').attr('disabled','disabled');	var pagename = articleList.split('\n')[0]	defVars("getPageInfo(pagename,'get')") } }); function stopEditing { $('#stopbutton, .editbutton, #followNow, #unfollowNow').attr('disabled','disabled'); $('#articleList, #startbutton').removeAttr('disabled'); $('#watchsuccess, #unwatchsuccess').remove; $('#resultWindow').html(''); } $('#stopbutton').click(function {	stopEditing }) $('#followNow, #unfollowNow').click(function {	var pagename = $('#articleList').val.replace(/^$\n/m, ).split('\n')[0];	$('#watchsuccess, #unwatchsuccess').remove	if ($('#articleList').val.replace(/^$\n/m, ).length==0) {		alert('No page entered to watch');	} else {		if ($(this).attr('id')=='followNow') {			watchPage(pagename);		} else {			unwatchPage(pagename);		}	} }); $('#unfollowPage, #followPage').click(function {	var other = $(this).attr('id')=='followPage'?'#unfollowPage':'#followPage';	if ($(this).is(':checked')) {		$(other).attr('disabled','disabled');	} else {		$(other).removeAttr('disabled');	} }); $('#editbutton-1').click(function {	var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0]	defVars("getPageInfo(pagename,'submit')") }) $('#editbutton-2, #skipPage').click(function {	$('#articleList').val($('#articleList').val.replace(/^.*\n?/,))	var pagename = $('#articleList').val.replace(/^$\n/m, ).split('\n')[0]	defVars("getPageInfo(pagename,'get')") }) $('#editbutton-3').click(function {	var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0]	defVars("getPageInfo(pagename,'preview')") }); $('#editbutton-4').click(function {	var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0]	defVars("getDiff") }); $('#movePage').click(function {	if ($('#moveTo').val.length==0) {		alert('Please enter the new pagename before clicking move.')	} else {		var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0]		if (sysop) defVars("getPageInfo(pagename,'move')")	} }) $('#protectPage').click(function {	var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0]	if (sysop) defVars("getPageInfo(pagename,'protect')") }) $('#deletePage').click(function {	var pagename = $('#articleList').val.replace(/^$\n/m, '').split('\n')[0]	if (sysop) defVars("getPageInfo(pagename,'delete')") }) } else { alert('Your username is not on the AWB checklist. Please request AWB access on RS:AWB/R.') }