User:DanCherek/UAABotRemover.js

/** * Attribution: This script is a derivative of User:Σ/Testing facility/Archiver.js * and User:DannyS712/SectionRemover.js. */ $.when(mw.loader.using(['mediawiki.util', 'mediawiki.api']), $.ready).done(	function {		var validReports = {},			fromTos = {},			wikiText = '',			revStamp, startRemoveButton, overlay;

if (mw.config.get('wgPageName') !==			'Wikipedia:Usernames_for_administrator_attention' &&			mw.config.get('wgPageName') !==			'Wikipedia:Usernames_for_administrator_attention/Bot') { return; }		$('head').append(			' a.remylink { font-weight:bold } .remyhighlight { background-color:#b3ffcc } '		); startRemoveButton = mw.util.addPortletLink(			'p-cactions',			'#',			'Remove bot reports',			'ca-rmbot',			'Enter/exit the removal process',			null,			null		); overlay = $(document.createElement('button')); $(startRemoveButton).click(function(e) {			$('.remylink').click;			$('.remy').toggle;			$('#RemoveUAAbutton').toggle;		}); overlay.html("Remove the selected reports") .attr("id", 'RemoveUAAbutton') .css("position", 'sticky') .css("bottom", 0) .css("width", '100%') .css("font-size", '200%'); $(document.body).append(overlay); overlay.toggle; overlay.click(function(e) {			var numOfReports, sections, archiveThis, cutOffset,				revisedPage;

function cut(s, start, end) { return s.substr(0, start) + s.substring(end); }			cutOffset = numOfReports = 0; revisedPage = wikiText; sections = $('a.remylink').map(function {				return $(this).attr('data-name');			}); if (!(numOfReports = sections.length)) { return alert('No reports selected, aborting'); }			sections.each(function(i, n) {				revisedPage = cut( revisedPage, fromTos[n][0] - cutOffset, fromTos[n][1] - cutOffset );				cutOffset += fromTos[n][1] - fromTos[n][0];			}); archiveThis = sections.map(function {				return wikiText.substring(fromTos[this][0], fromTos[this][1]);			}).toArray.join(''); if (1) { new mw.Api.postWithToken(					'csrf', {						action: 'edit',						title: 'Wikipedia:Usernames_for_administrator_attention/Bot',						text: revisedPage,						summary: 'Removed bot report(s) using UAABotRemover',						basetimestamp: revStamp,						starttimestamp: revStamp					}				).done(function {					new mw.Api.edit( mw.config.get('wgPageName'), function(rev) { return rev.content; }).then(function { window.location.reload; });				}).fail(function {					alert( 'failed to remove reports. aborting.' );					window.location.reload;				}); }		});		new mw.Api.get({ action: 'query', pageids: 11238105, prop: ['revisions'], rvprop: ['content', 'timestamp'] }).done(function(reader) { var idx = [], rv; rv = reader.query.pages[11238105].revisions[0]; wikiText = rv['*']; revStamp = rv.timestamp; $('#mw-content-text') .find("span[id$='-Bot-reported']") .each(function(i, title) {					var username;					username = $(this).parent[0].textContent;					idx[i] = wikiText.indexOf(username);					$(this).closest('.userlinks')[0]						.innerHTML += ' ' +						' ' +						' [ ' +						'' +						'remove report' +						' ] ' +						' ';				}); for (let i = 0; i < idx.length; i++) { fromTos[i] = [ idx[i] - 14, idx[i + 1] !== undefined ? idx[i + 1] - 14 : Infinity ];			}		});	});