User:ExtorcDev/rmMaster.js: Difference between revisions

Content deleted Content added
ExtorcDev (talk | contribs)
No edit summary
ExtorcDev (talk | contribs)
fix depreciated RMT regex
 
(48 intermediate revisions by the same user not shown)
Line 1:
//<nowiki>
$('.mw-heading').each(function(index){
$('<br><button class="closeButton">Close</button><button class="relistButton">Relist</button>').insertBefore('.tmbox-move');
var $heading = $(this).find('span.mw-headline');
$('<button class="rmTechButton">Raise Technical Move request</button>').insertBefore('.mw-archivedtalk');
if($heading.text().includes('Requested move')){
 
$(this).append('<br><button class="closeButton">Close</button><button class="relistButton">Relist</button>');
var url = window.___location.href.match(/Talk.*$/gm).toString().replace(/_/g, ' ');
}
if(url.match(/#/gm)){
var url = window.___location.href.match(/Talk.*$/gm).toString().replace(/_/g, ' ');
if(url = url.matchtoString().replace(/#.*$/gm,'')){;
}
url = url.toString().replace(/#.*$/gm,'');
console.log(url);
}
$('.closeButton').click(function(){
console.log(url);
$('.closeButton').clickqueryPage(function(result){
var apisectionLog = new mwresult.Apisplit("==");
for(let i = 0; i < sectionLog.length; i++){
api.get( queryParams(url) ).done( function ( data ) {
if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
var page;
var section = sectionLog[i+1];
for (page in data.query.pages){
section = section + '\n{{subst:RM bottom}}\n';
result = data.query.pages[page].revisions[0]['*'];
sectionLogvar closeMSG = resultwindow.splitprompt("==Close Message : ");
var updatedSection;
for(let i = 0; i < sectionLog.length; i++){
if(sectionLog[i]section.match(/Requested move \dmultiple=yes/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
updatedSection = section.replace(/{{requested move.*multiple=yes\n.*/g,'{{subst:RM top|' + closeMSG + '|nac=yes}}');
var section = sectionLog[i+1];
section = section + '\n{{subst:' + 'RM bottom}}\n';
var closeMSG = window.prompt("Close Message : ");
var 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);
}
}
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");
$('.relistButton').click(function(){
var api = new mw.Api();
console.log("Relisted");
api.get( queryParams(url) ).done( function ( data ) {
queryPage(function(result){
var page;
sectionLog = result.split("==");
for (page in data.query.pages){
for(let i = 0; i < sectionLog.length; i++){
result = data.query.pages[page].revisions[0]['*'];
if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
sectionLog = result.split("==");
for(letvar isection = 0; i < sectionLog.length; [i++){1];
console.log(section);
if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
var if(section = sectionLog[i+1];.match(/'''''Relisting.*>/gm)){
console.log(section'Already relisted atleast once');
if(var prevRelists = section.match(/'''''Relisting.*>/gm)){;
var newRelists = prevRelists + '{{subst:relisting}}';
console.log('Already relisted atleast once');
var updatedSection = section.replace(prevRelists, newRelists);
}
result = result.replace(section, updatedSection);
else{
console.log('Never relisted before'result);
editPage(url, result, 'Relisted');
}
}
// section = section + '\n{{subst:' + 'RM bottom}}\n';
else{
// var closeMSG = window.prompt("Close Message : ");
// var updatedSection = section.replace(section.match(/{{requested move.*UTC./gm),'(UTC){{subst:' + 'RM top|' + closeMSG + '|nac=yesrelisting}}');
// result = result.replace(sectionLog[i+1]section, updatedSection);
// console.log(result);
editPage(url, result, 'Relisted');
// editPage(url, result);
}
}
}
} );
});
});
 
function editPage( url , result ) {
$('.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(urlloc, 'Closed'result, action) ).done(function( data ) {
alert( 'Page edited!' );
} ).fail( function(code, data) {
Line 71 ⟶ 96:
}
 
function queryParams(urlloc){ return { action: 'query', prop: 'revisions', rvprop: 'content', rvlimit: 1, titles: urlloc }; }
function editParams(urlloc, content, action){ return { action: 'edit', title: urlloc, text: resultcontent, 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>