User:JJPMaster/rfd.js
Appearance
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
- Konqueror: simply click the Reload button, or press F5;
- Opera users may need to completely clear their cache in Tools→Preferences.
Warning: Malicious code can compromise your account. Page preview will cause your web browser to execute this page's content as code under some skins, including Monobook. If you have any questions about any code you plan to add, you can ask at the appropriate reading room. |
Documentation for this user script can be added at User:JJPMaster/rfd. |
// <nowiki>
importScript("User:JJPMaster/CurateThisPage/review.js");
var parsedTitle = mw.config.get("wgPageName").replace(/_/g, " ");
async function getAuthor() {
var par = {
action: 'query',
prop: 'revisions',
titles: parsedTitle,
rvprop: 'user',
rvdir: 'newer',
rvlimit: 1,
format: 'json'
},
api = new mw.Api();
const data = await api.get( par );
return Object.values(data.query.pages)[0].revisions[0].user;
}
$(() => {
if (mw.config.get("wgArticleId") !== 0) {
var RFDporty = mw.util.addPortletLink('p-cactions', '#', 'RfD', 'pt-rfd', 'File a deletion request for this page');
var RFDad = " (using [[:b:en:User:JJPMaster/rfd.js|RfD]])";
$("#bodyContent").append(`
<div id="RFDdialog">
Please enter the reason for deletion:
<textarea name="RFDreason" id="RFDreason">Reason for deletion</textarea>
<input type="checkbox" id="notifyAuthor2" name="notifyAuthor2" checked /><label for="notifyAuthor2">Notify page author</label><br />
<button type="button" id="reqDel">Request deletion</button></div>
`);
$("#RFDdialog").hide();
$(RFDporty).click(() => $("#RFDdialog").dialog({ title: "Request deletion" }));
$("#reqDel").click(function() {
var myText = document.getElementById("RFDreason");
var reason = myText.value;
doTheReviewA();
doTheReviewB();
var params = {
action: 'edit',
prependtext: `{{Rfd}}\n`,
title: parsedTitle,
summary: "Making [[WB:Requests for deletion|deletion request]]" + RFDad,
format: 'json'
},
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log( data );
} );
(async function() {
if ($("#notifyAuthor2").prop("checked")) {
params = {
action: 'edit',
appendtext: `\n{{subst:Rfd warning|${parsedTitle}|~~~~}}`,
title: `User_talk:${await getAuthor()}`,
summary: "Notifying author about page tagging" + RFDad,
format: 'json'
},
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log( data );
} );
}
})();
params = {
action: 'edit',
appendtext: `\n== [[${parsedTitle}]] ==\n${reason} ~~~~`,
title: `User:JJPMaster/CurateThisPage/sandbox`,
summary: `Adding deletion request for [[${parsedTitle}]]` + RFDad,
format: 'json'
},
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log( data );
} );
mw.notify("RfD:\nThe page has been nominated for deletion. Reloading...")
setTimeout(() => window.location.reload(), 2000);
});
}
});
// </nowiki>