User:Ostrichyearning3/challenge-submit.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:Ostrichyearning3/challenge-submit. |
/* jshint maxerr: 999 */
/* <nowiki> */
$.when(
mw.loader.using(['mediawiki.Title', 'ext.gadget.morebits']),
$.ready
).then(function() {
// hide on special pages and talk pages
if (mw.config.get('wgNamespaceNumber') < 0 || mw.config.get('wgNamespaceNumber') % 2 === 1 || !mw.config.get('wgRevisionId')) {
return;
}
var advert = ' ([[User:Ostrichyearning3/challenge|challenge-submit]])';
var menu = mw.util.addPortletLink('p-cactions', '#', 'challenge-submit', 'p-challenge-submit', 'Redirect to another article and add merge templates to talk pages');
menu.addEventListener('click', callback);
function callback(e) {
if (e) e.preventDefault();
var Window = new Morebits.simpleWindow(600, 500);
Window.setScriptName('challenge-submit');
Window.setTitle("Submit articles to challenges");
Window.addFooterLink('10000 Challenge', 'Wikipedia:The 10,000 Challenge');
var form = new Morebits.quickForm(evaluate);
form.append({
type: 'input',
label: 'Location (used for {{flag}}',
name: 'location',
value: ''
});
// form.append({
// type: 'input', // changed to 'date' after render
// name: 'date',
// label: 'Date of merger: ',
// value: new Date().toISOString().slice(0, 10),
// tooltip: 'This date is used in the {{merged-from}} and {{merged-to}} templates'
// });
form.append({
type: 'checkbox',
name: 'challenges',
list: [
{
label: 'Submit to the 10000 challenge',
name: 'chall_10_submit',
checked: true
},
{
label: 'Submit to the 50000 challenge',
name: 'chall_50_submit',
checked: true
} // {
]
});
form.append({ type: 'submit', label: 'Submit' });
var result = form.render();
Window.setContent(result);
Window.display();
}
function evaluate(e) {
var form = e.target;
var params = {};
params.target = form.target.value;
if (!params.target.trim()) {
alert('Please enter a flag');
return;
}
params.current = Morebits.pageNameNorm;
// params.redirect = form.redirect.checked;
// params.summary = form['redirect.summary'] && form['redirect.summary'].value.replace('###', params.target);
// params.removemerge = form.removemerge.checked;
// params.addmergedfrom = form.addmergedfrom.checked;
// params.addmergedto = form.addmergedto.checked;
// params.adjusttalktemplates = form.adjusttalktemplates.checked;
params.chall_10_submit = form.chall_10_submit.checked;
params.chall_50_submit = form.chall_50_submit.checked;
params.location = form.location.value;
// var dateobj = new Date(form.date.value);
// if (isNaN(dateobj.getTime())) {
// alert('Invalid date. Please enter in YYYY-MM-DD format'); // should arise only for browsers w/o datepicker
// return;
// }
// params.date = dateobj.getUTCDate() + ' ' + dateobj.getUTCMonthName() + ' ' + dateobj.getUTCFullYear();
Morebits.simpleWindow.setButtonsEnabled(false);
Morebits.status.init(form);
Morebits.wiki.api.setApiUserAgent('[[w:User:Ostrichyearning3/challenge-submit.js]]');
if (params.chall_10_submit) {
// var page = new Morebits.wiki.page(params.current, 'Submitting');
var challenge_page = new Morebits.wiki.page(63582974, 'Submitting');
page.load(function(page) {
var pageText = page.getPageText() + "append"
page.setPageText(pageText);
page.setEditSummary(params.summary + advert);
page.setCreateOption('nocreate');
page.save();
});
}
}
});
/* </nowiki> */