User:ExtorcDev/rmMaster.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:ExtorcDev/rmMaster. |
//<nowiki>
$('<br><button class="closeButton">Close</button><button class="relistButton">Relist</button>').insertBefore('.tmbox-move');
$('<button class="rmTechButton">Raise Technical Move request</button>').insertBefore('.mw-archivedtalk');
var url = window.location.href.match(/Talk.*$/gm).toString().replace(/_/g, ' ');
if(url.match(/#/gm)){
url = url.toString().replace(/#.*$/gm,'');
}
console.log(url);
$('.closeButton').click(function(){
queryPage(function(result){
sectionLog = result.split("==");
for(let i = 0; i < sectionLog.length; i++){
if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
var section = sectionLog[i+1];
section = section + '\n{{subst:RM bottom}}\n';
var closeMSG = window.prompt("Close Message : ");
var updatedSection;
if(section.match(/multiple=yes/gm)){
updatedSection = section.replace(/{{requested move.*multiple=yes\n.*/g,'{{subst:RM top|' + closeMSG + '|nac=yes}}');
}
else{
updatedSection = section.replace(/{{requested move.*/g,'{{subst:RM top|' + closeMSG + '|nac=yes}}');
}
result = result.replace(sectionLog[i+1], updatedSection);
console.log(result);
editPage(url, result, 'Closed');
}
}
});
});
$('.relistButton').click(function(){
console.log("Relisted");
queryPage(function(result){
sectionLog = result.split("==");
for(let i = 0; i < sectionLog.length; i++){
if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
var section = sectionLog[i+1];
console.log(section);
if(section.match(/'''''Relisting.*>/gm)){
console.log('Already relisted atleast once');
var prevRelists = section.match(/'''''Relisting.*>/);
var newRelists = prevRelists + '{{subst:relisting}}';
var updatedSection = section.replace(prevRelists, newRelists);
result = result.replace(section, updatedSection);
console.log(result);
editPage(url, result, 'Relisted');
}
else{
var updatedSection = section.replace(section.match(/.UTC./m),'(UTC){{subst:relisting}}');
result = result.replace(section, updatedSection);
console.log(result);
editPage(url, result, 'Relisted');
}
}
}
});
});
$('.rmTechButton').click(function(){
queryPage(function(result){
sectionLog = result.split("==");
for(let i = 0; i < sectionLog.length; i++){
if(sectionLog[i].match(/Requested move \d/gm)){
var section = sectionLog[i+1];
var moveFrom = window.prompt("Enter Move Source : ");
var moveTo = window.prompt("Enter Move Destination : ");
var reason = window.prompt("Request reason : ");
var techReq = '{{subst:RMassist|'+ moveFrom +'|' + moveTo + '|reason=' + reason + '}}';
var api2 = new mw.Api();
api2.get( queryParams('Wikipedia:Requested moves/Technical requests') ).done( function ( data ) {
var page2;
for (page2 in data.query.pages){
result2 = data.query.pages[page2].revisions[0]['*'];
var newMatch = result2.match(/=.* U.*\n.*>\n.*\n.*\n.*/gm).toString() + '\n' + techReq;
console.log(newMatch);
result2 = result2.replace(/=.* U.*\n.*>\n.*\n.*\n.*/gm, newMatch);
console.log(result2);
editPage('Wikipedia:Requested moves/Technical requests', result2, 'Raised Technical Request');
}
});
}
}
});
});
function editPage( loc , result , action) {
var api2 = new mw.Api();
api2.postWithToken("csrf", editParams(loc, result, action) ).done(function( data ) {
alert( 'Page edited!' );
} ).fail( function(code, data) {
console.log( api.getErrorMessage( data ).text());
} );
}
function queryParams(loc){ return { action: 'query', prop: 'revisions', rvprop: 'content', rvlimit: 1, titles: loc }; }
function editParams(loc, content, action){ return { action: 'edit', title: loc, text: content, summary: action + ' Request using [[User:ExtorcDev/rmMaster.js|rmMaster]]' }; }
function queryPage(onQuery){
var api = new mw.Api();
api.get( queryParams(url) ).done( function ( data ) {
var page;
for (page in data.query.pages){
result = data.query.pages[page].revisions[0]['*'];
onQuery(result);
}
});
}
//</nowiki>