User:JJPMaster/csd.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/csd. |
// <nowiki>
importScript("User:JJPMaster/CurateThisPage/gsr.js");
var parsedTitle = mw.config.get("wgPageName").replace("_", " ");
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) {
getAuthor();
var porty = mw.util.addPortletLink('luna-actions', '#', 'CSD', 'luna-csd', 'Nominate this page for speedy deletion');
$("#bodyContent").append(`
<div id="CSDdialog">
Why would you like the page to be deleted?
<select name="CSDtagReason" id="CSDtagReason">
<option>Select the criterion</option>
<option id="spam">Spam</option>
<option id="copyvio">Copyright violation (include link to source)</option>
<option id="req">Author request</option>
<option id="scope">Out of scope</option>
<option id="redirect">Implausible orphaned redirect</option>
<option id="c-repost">Repost of deleted material (include title of RfD)</option>
<option id="vandalism">Vandalism</option>
<option id="nonsense">Nonsense</option>
<option id="test">Test page</option>
<option id="blank">No content</option>
<option id="c-other">Other (please specify)</option>
</select>
<input type="checkbox" id="notifyAuthorCSD" name="notifyAuthorCSD" checked /><label for="notifyAuthorCSD">Notify page author</label><br />
<button type="button" id="addTagCSD">Mark for deletion</button></div>
`);
$("#CSDdialog").hide();
$(porty).click(() => $("#CSDdialog").dialog({ title: "Mark this page for speedy deletion"} ));
$("#addTagCSD").click(function() {
var mySelect = document.getElementById("CSDtagReason");
var critValue = mySelect.value;
var criterion;
var tag = mySelect.options[CSDtagReason.selectedIndex].id;
var finalTag;
var realCrit = "";
var contin = true;
if (!tag) alert("You must select a criterion.");
else {
if(!tag.startsWith("c")) {
criterion = `Marking for deletion: ${critValue}`;
finalTag = `Delete|${critValue}`;
realCrit = critValue;
}
else {
var innerCrit = prompt("Please provide more information. Leaving this field blank will abort the deletion tagging.");
if(innerCrit) {
if(tag !== "c-other") {
realCrit = `${critValue.split("(")[0].slice(0, -1)}: ${innerCrit}`;
criterion = `Marking for speedy deletion: ${critValue.split("(")[0].slice(0, -1)}`;
finalTag = `Delete|1=${realCrit}`;
}
else {
criterion = `Marking for speedy deletion: ${innerCrit}`;
finalTag = `Delete|1=${innerCrit}`;
realCrit = innerCrit;
}
}
else contin = false;
}
if (contin) {
var metaReq = confirm("Would you like to request that a global sysop delete this page?");
if (metaReq) makeMetaReq(summaryAd, parsedTitle, realCrit);
var params = {
action: 'edit',
prependtext: `{{${finalTag}}}\n`,
title: parsedTitle,
summary: criterion + summaryAd,
format: 'json'
},
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log( data );
} );
(async function() {
if ($("#notifyAuthor").prop("checked")) {
params = {
action: 'edit',
appendtext: `\n{{subst:User:JJPMaster/CurateThisPage/authorMsg|title=${parsedTitle}|tag=delete|deletereason=${realCrit}}}`,
title: `User_talk:${await getAuthor()}`,
summary: "Notifying author about speedy deletion nomination" + summaryAd,
format: 'json'
},
api = new mw.Api();
api.postWithToken( 'csrf', params ).done( function ( data ) {
console.log( data );
} );
}
})();
mw.notify("Luna:\nThe tag has been added. Reloading...");
setTimeout(() => window.location.reload(), 2000);
}
}
});
}
});
// </nowiki>