User:SD0001/draft-sort-burst.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:SD0001/draft-sort-burst. |
// NOTE: this doesn't work until the edit request at
// User_talk:Enterprisey/draft-sorter.js#Interface-protected_edit_request_on_24_June_2019
// is accepted.
/**
* Sort drafts one after the other
*
* Requires User:Enterprisey/draft-sort.js
*
* Activate by clicking on "Draft-sort (burst)" in the More menu.
* Enterprisey's draft-sort opens up. Add WikiProject tags and save,
* or skip if unsure (skip button is produced by this script).
* Now you will be redirected to another currently submitted AfC draft
* that hasn't been sorted yet, and draft-sort automatically opens up.
* The cycle continues.
*
*/
$.when(
mw.loader.using(['mediawiki.util', 'mediawiki.api']),
mw.loader.getScript('https://en.wikipedia.org/w/index.php?title=User:Enterprisey/draft-sort.js&action=raw&ctype=text/javascript'),
$.ready
).then(function() {
if (mw.config.get('wgNamespaceNumber') !== 118) return;
$(mw.util.addPortletLink('p-tb', '#', 'Draft-sort (burst)', 'pt-draftsortburst', 'Sort drafts in burst mode')).click(function(e) {
e.preventDefault();
actions();
});
if (mw.util.getParamValue('draftsorttrigger')) {
actions();
}
function actions() {
setTimeout(function() {
$('#pt-draftsort').click();
}, 800);
$(document).on('draft_sort:ready', function() {
$('#draft-sorter-wrapper button.mw-ui-quiet').append(
$('<button>')
.addClass('mw-ui-button')
.addClass('mw-ui-destructive')
.addClass('mw-ui-quiet')
.addClass('draft-sort-skip')
.text('Skip')
)
});
var nextDraft, cmcontinue;
var api = new mw.Api();
var query = {
"action": "query",
"list": "categorymembers",
"cmtitle": "Category:Pending_AfC_submissions",
"cmprop": "title",
"cmnamespace": "118",
"cmlimit": "50",
"cmsort": "sortkey",
"cmdir": "ascending",
"cmstartsortkeyprefix": "P"
};
function checkTalkPages(r) {
//console.log('in checkTalkPages');
//console.log(r);
if (r && r.query && r.query.categorymembers) {
cmcontinue = r.continue.cmcontinue;
var draftTalkPages = r.query.categorymembers.map(function(e) {
return e.title.replace(/^Draft:/, 'Draft talk:');
});
return api.get({
action: 'query',
titles: draftTalkPages
});
}
}
function selectNextDraft(r) {
//console.log('in selectNextDraft');
//console.log(r);
if (r && r.query && r.query.pages) {
var found = false;
$.each(r.query.pages, function(i,e) {
if (parseInt(i) < 0) {
var page = r.query.pages[i].title.replace(/^Draft talk:/, 'Draft:');
if (page !== mw.config.get('wgPageName').replace(/_/g, ' ')) {
nextDraft = page;
found = true;
return false;
}
}
});
//console.log('found:', found);
if (!found) {
//console.log('No suitable next draft found');
query.cmcontinue = cmcontinue;
postQuery();
return;
}
$(document).on('draft_sort:saved', function() {
window.location = '//en.wikipedia.org/wiki/' + nextDraft + '?draftsorttrigger=y';
});
$('.draft-sort-skip').click(function() {
window.location = '//en.wikipedia.org/wiki/' + nextDraft + '?draftsorttrigger=y';
});
}
}
function postQuery() {
//console.log(query);
api.get(query)
.then(checkTalkPages)
.then(selectNextDraft)
.fail(function(e) {
console.log('API for getting next draft failed ' + e);
});
}
postQuery();
}
});