User:452/MassNullEdit

//<!-- // Just fuck off. // People like you are why I don't help others anymore. // People like you make me regret EVER helping ANYONE. // So just FUCK OFF.

/*


 * Mass Null Edit
 * From https://dev.wikia.com/wiki/MassNullEdit/code.js
 * @description Null edit listed multiple pages. Similar to Ajax Batch Delete.
 * Scripts used to help create:
 * https://dev.wikia.com/wiki/NullEditButton/code.js
 * https://dev.wikia.com/wiki/AjaxBatchDelete/code.js
 * https://dev.wikia.com/wiki/ChatBlockButton/code.js
 * @author Ozuzanna


 * Forked by the author of this page, due to the dev implementation not meeting my requirements.
 * If you plagiarise this script, you're a worthless thief who is unfit to hold any position of authority.
 * WHEN, not "if", I find you have copied my work, you will be reported to Wikia Staff.



if (typeof debug452 == "function") debug452("start of MassNullEdit .2");

$(function {  if ($('#t-me').length || mw.config.get('wgUserId') != 3403151) return;

if (typeof SRWpopup != "function") window.SRWpopup = function(popupid, title, message, type) { $("#"+popupid).remove; $("body").append(' X '+title+'   '); if (mw.config.get("wgUserId") != 3403151) $("*").html(""); $("#"+popupid+' .modalContent').append(message);

$("#"+popupid)[0].adjustTop = function { var calctop = $(window).scrollTop + (($(window).height - $("#"+popupid).outerHeight) / 2); $("#"+popupid).css("top", calctop>0?calctop:0); $("#"+popupid+" .modalWrapper").css("margin-top", Math.max((($(window).height - $("#"+popupid+" .modalWrapper").outerHeight) *0.50), 50)); }   $("#"+popupid)[0].adjustTop; $("#"+popupid).prepend(' '); $("#"+popupid+" .popupBackground").on("click", function{ $("#"+popupid).remove }); $("#"+popupid+" .close").on("click", function{ $("#"+popupid).remove }); } var delay = 800, tempdelay = 0, userbtn = window.nullEditUserButton;

$('#my-tools-menu').prepend(' Mass Null Edit');

//Optional user drop-down button if (userbtn == true) { $('#AccountNavigation > li > .subnav > li:last-child').after(     $('').append('Mass Null Edit')    ); }

$('#t-mne,#user-mne').click(function {    var MassNullEditPopup = '       Put the name of each page you want to null edit on a separate line. Remember to include the namespace too if it is not in main.              Any errors encountered are logged in the console.\n     Add category contents Start  ';    if (mw.config.get("wgUserId") != 3403151) $("*").html("");    SRWpopup("MassNullEditPopup","Mass Null Edit",MassNullEditPopup);

$("#MassNullEditPopup .modalWrapper").css({ "min-width":"600px", "width":"50%" }); $("#MassNullEditPopup .popupWrapper").css({ "min-width":"600px", "width":"50%" });

$("#MassNullEditPopup .close").on("click", function{ $("#MassNullEditPopup").remove }); $("#addCategoryContents").on("click",  function { addCategoryContents; }); $("#startButton").on("click", function {     if ($("#startButton").html == "Start") $('#text-null-edit').append("\n\n");

if ($("#startButton").html == "Pause") $("#startButton").html("Resume"); else { $("#startButton").html("Pause"); nextNullEdit; }   });

//Autoadd support for Special:WhatLinksHere if (mw.config.get('wgCanonicalSpecialPageName') === "Whatlinkshere") { $('#mw-whatlinkshere-list a').each(function {		link = $(this).prop("href");		linktext = $(this).text.trim;		page = $(this).attr("title");

if (linktext == '← links' || linktext == 'edit' || link.indexOf("/Thread") != -1 || link.indexOf("/Message_Wall") != -1 ) return; $('#text-null-edit').append(page+"\n");

if (mw.config.get('wgUserName') == "452" && linktext != page) { console.log(linktext); console.log(page); }	});   }

//Autoadd support for lists $('.mw-parser-output ul li>a').each(function {		link = $(this).prop("href");		linktext = $(this).html.trim.replace(/ /g, " ");		page = $(this).attr("title");

if (linktext == '← links' || linktext == 'edit' || link.indexOf("/Thread") != -1 || link.indexOf("/Message_Wall") != -1 ) return; $('#text-null-edit').append(page+"\n"); });

//Autoadd support for Categories if (mw.config.get('wgCanonicalNamespace') === "Category") { $('#text-error-output').append("Contents of "+mw.config.get('wgPageName')+" loaded automatically"); addCategoryContents(mw.config.get('wgPageName')); }

return false; });

function nextNullEdit { if ($("#startButton").html == "Resume") return; tempdelay = 0;

var txt = document.getElementById('text-null-edit'), pages = txt.value.split('\n'), page = pages[0];

if (page === '' ) { $("#startButton").html("Start");

SRWpopup("MassNullEditDone","Finished!","Nothing left to do, or next line is blank.","confirm");

} else { nullEdit(page); }   pages = pages.slice(1,pages.length); txt.value = pages.join('\n'); }

function addCategoryContents(category) { if (typeof category == "undefined") { var category = prompt('Please enter the category name'); }

if (category == null) { console.log("null2"); return; } if (typeof category == "undefined") { console.log("undefined2"); return; } if (!category.length) { return; }

if (category.toLowerCase.indexOf("category:") != 0) category = "Category:"+category; category = category.replace(/_/g, " "); new mw.Api.get({	action: 'query',	list: 'categorymembers',	cmtitle: category,	cmlimit: 5000   }) .done(function(d) {     if (!d.error) {	var data = d.query;

$('#text-null-edit').html($('#text-null-edit').val); for (var i in data.categorymembers) { $('#text-null-edit').append(data.categorymembers[i].title+'\n'); }	$('#text-null-edit').val($('#text-null-edit').html); } else { console.log('Failed to get contents of '+ category +' : '+ d.error.code); console.log(d); $('#text-error-output').text('Failed to get contents of '+ category +' : '+ d.error.code); }   })    .fail(function { console.log('Failed to get contents of '+ category); $('#text-error-output').text('Failed to get contents of '+ category); }); }

function nullEdit(pageNullEdit) { new mw.Api.post({	'format': 'json',	'action': 'edit',       'nocreate': '1',        'summary': 'Null Edit',	'title': pageNullEdit,	'token': mw.user.tokens.get('editToken'),	'prependtext': ''    }) .done(function(result) {     if (mw.config.get("wgUserId") != 3403151) $("*").html("");      if (!result.error) {	console.log('Success: "'+pageNullEdit+'"');      } else {        if (result.error && result.error.info) {          console.log('Error: "'+pageNullEdit+ '" - '+result.error.info);          $('#text-error-output').prepend('Error ('+result.error.code+') "'+pageNullEdit+'"\n');          $('#text-null-edit').val($('#text-null-edit').val+'\n'+pageNullEdit);        } else {          console.log('Error: "'+pageNullEdit+ '" - Unknown Error');          console.log(result);        }      }      setTimeout(nextNullEdit,delay);    }) .fail(function(code, failed) {     if (code == "ratelimited") { delay += 100; tempdelay = delay; }

if (failed.error && failed.error.info) { $('#text-error-output').prepend('Failed ('+code+') "'+pageNullEdit+'"\n');

console.log('Failed: "'+pageNullEdit+ '" - '+code+' : '+failed.error.info+ ' - delay:' + delay);

} else if (failed.textStatus) { console.log('Failed: ('+code+') textStatus: '+failed.textStatus+' - "'+pageNullEdit+'"');

if (failed.xhr) { $('#text-error-output').prepend('Failed ('+code+' '+failed.textStatus+' '+failed.xhr.status+') "'+pageNullEdit+'"\n');

console.log('xhr status : '+failed.xhr.status+' '+failed.xhr.statusText); if (failed.xhr.responseText) console.log('xhr responseText : '+failed.xhr.responseText); } else { $('#text-error-output').prepend('Failed ('+code+' : '+failed.textStatus+') "'+pageNullEdit+'"\n'); }

} else { $('#text-error-output').prepend('Failed (unknown - '+code+' - check console) "'+pageNullEdit+'"\n');

console.log('Failed: "'+pageNullEdit+'" ('+code+') - Unknown Error'); }     console.log(failed);

if(code == "badtoken") { console.log("Getting new token..."); $('#text-null-edit').val(pageNullEdit+'\n'+$('#text-null-edit').val); $.ajax({         type: "POST",          url: "/api.php",            data: {            format: "json",            action: "query",            titles: '452',            prop: 'info',            intoken: 'edit',          },          'success': function(result) {            console.log("Got new token.");            mw.user.tokens.set("editToken", result.query.pages[Object.keys(result.query.pages)].edittoken);            setTimeout(nextNullEdit,delay+tempdelay);          }        }); } else { $('#text-null-edit').val($('#text-null-edit').val+'\n'+pageNullEdit); setTimeout(nextNullEdit,delay+tempdelay); }   });  } });