User:ExtorcDev/rmMaster.js: Difference between revisions

Content deleted Content added
ExtorcDev (talk | contribs)
No edit summary
ExtorcDev (talk | contribs)
fix depreciated RMT regex
 
(9 intermediate revisions by the same user not shown)
Line 1:
//<nowiki>
$('<br><button class="closeButton">Close</button><button class="relistButton">Relist</button>').insertBefore('.tmbox-move');
$('.mw-heading').each(function(index){
$('<button class="rmTechButton">Raise Technical Move request</button>').insertBefore('.mw-archivedtalk');
var $heading = $(this).find('span.mw-headline');
if($heading.text().includes('Requested move')){
$(this).append('<br><button class="closeButton">Close</button><button class="relistButton">Relist</button><button class="rmTechButton">Raise Technical Move request</button>');
}
});
 
var url = window.___location.href.match(/Talk.*$/gm).toString().replace(/_/g, ' ');
Line 13 ⟶ 9:
console.log(url);
$('.closeButton').click(function(){
queryPage(function(result){
var api = new mw.Api();
sectionLog = result.split("==");
api.get( queryParams(url) ).done( function ( data ) {
for(let i = 0; i < sectionLog.length; i++){
var page;
if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
for (page in data.query.pages){
var section = sectionLog[i+1];
result = data.query.pages[page].revisions[0]['*'];
section = section + '\n{{subst:RM bottom}}\n';
sectionLog = result.split("==");
var closeMSG = window.prompt("Close Message : ");
for(let i = 0; i < sectionLog.length; i++){
var updatedSection;
if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
var if(section .match(/multiple= sectionLog[i+1];yes/gm)){
sectionupdatedSection = section.replace(/{{requested + 'move.*multiple=yes\n.*/g,'{{subst:RM bottomtop|' + closeMSG + '|nac=yes}}\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');
}
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){
var api = new mw.Api();
sectionLog = result.split("==");
api.get( queryParams(url) ).done( function ( data ) {
for(let i = 0; i < sectionLog.length; i++){
var page;
if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
for (page in data.query.pages){
var section = sectionLog[i+1];
result = data.query.pages[page].revisions[0]['*'];
console.log(section);
sectionLog = result.split("==");
if(section.match(/'''''Relisting.*>/gm)){
for(let i = 0; i < sectionLog.length; i++){
console.log('Already relisted atleast once');
if(sectionLog[i].match(/Requested move \d/gm) && sectionLog[i+1].match(/{{requested move.*/g)){
var sectionprevRelists = sectionLog[i+1]section.match(/'''''Relisting.*>/);
var newRelists = prevRelists + '{{subst:relisting}}';
console.log(section);
if(var updatedSection = section.matchreplace(/'''''Relisting.*>/gm)prevRelists, newRelists){;
result = result.replace(section, updatedSection);
console.log('Already relisted atleast once');
console.log(result);
var prevRelists = section.match(/'''''Relisting.*>/);
editPage(url, result, 'Relisted');
var newRelists = prevRelists + '{{subst:relisting}}';
}
var updatedSection = section.replace(prevRelists, newRelists);
else{
result = result.replace(section, updatedSection);
var updatedSection = section.replace(section.match(/.UTC./m),'(UTC){{subst:relisting}}');
console.log(result);
editPage(url,result = result.replace(section, 'Relisted'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){
var api = new mw.Api();
sectionLog = result.split("==");
api.get( queryParams(url) ).done( function ( data ) {
for(let i = 0; i < sectionLog.length; i++){
var page;
if(sectionLog[i].match(/Requested move \d/gm)){
for (page in data.query.pages){
var section = sectionLog[i+1];
result = data.query.pages[page].revisions[0]['*'];
sectionLog var moveFrom = resultwindow.splitprompt("==Enter Move Source : ");
var moveTo = window.prompt("Enter Move Destination : ");
for(let i = 0; i < sectionLog.length; i++){
var reason = window.prompt("Request reason : ");
if(sectionLog[i].match(/Requested move \d/gm)){
var techReq = '{{subst:RMassist|'+ moveFrom +'|' + moveTo + '|reason=' + reason + '}}';
var section = sectionLog[i+1];
var moveFrom = window.prompt("Enter Move Source : ");
var moveToapi2 = windownew mw.promptApi("Enter Move Destination : ");
api2.get( queryParams('Wikipedia:Requested moves/Technical requests') ).done( function ( data ) {
var reason = window.prompt("Request reason : ");
var page2;
var techReq = '{{subst:RMassist|'+ moveFrom +'|' + moveTo + '|reason=' + reason + '}}';
for (page2 in data.query.pages){
result2 = data.query.pages[page2].revisions[0]['*'];
var api2 = new mw.Api();
var newMatch = result2.match(/=.* U.*\n.*>\n.*\n.*\n.*/gm).toString() + '\n' + techReq;
api2.get( queryParams('Wikipedia:Requested moves/Technical requests') ).done( function ( data ) {
var page2 console.log(newMatch);
result2 = result2.replace(/=.* U.*\n.*>\n.*\n.*\n.*/gm, newMatch);
for (page2 in data.query.pages){
console.log(result2);
result2 = data.query.pages[page2].revisions[0]['*'];
editPage('Wikipedia:Requested moves/Technical requests', result2, 'Raised Technical Request');
var newMatch = result2.match(/Uncontro.*====\n.*>\n<!--.*/gm).toString() + '\n' + techReq;
}
console.log(newMatch);
});
result2 = result2.replace(/Uncontro.*====\n.*>\n<!--.*/gm, newMatch);
console.log(result2);
editPage('Wikipedia:Requested moves/Technical requests', result2, 'Raised Technical Request');
}
});
}
}
}
} );
});
 
Line 116 ⟶ 98:
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>