MediaWiki:Gadget-Botify.js: Difference between revisions
Jump to navigation
Jump to search
POST and GET are similarly fast, so it's slower to check if bot first; if the POST succeeds, probably safe to assume the bot userright state
KokoroSenshi (talk | contribs) m (count arguments before callign callback) |
KokoroSenshi (talk | contribs) (POST and GET are similarly fast, so it's slower to check if bot first; if the POST succeeds, probably safe to assume the bot userright state) |
||
Line 7: | Line 7: | ||
function botify( addOrRemove, expiry, callback ) { | function botify( addOrRemove, expiry, callback ) { | ||
//Create api options object | |||
var apiOptions = { | var apiOptions = { | ||
action: 'userrights', | action: 'userrights', | ||
Line 12: | Line 13: | ||
}; | }; | ||
apiOptions[addOrRemove] = 'bot'; | apiOptions[addOrRemove] = 'bot'; | ||
if (addOrRemove === 'add') apiOptions.expiry = | if (arguments.length >= 2 && addOrRemove === 'add') { | ||
apiOptions.expiry = expiry ; //TODO:Not working: It doesn't expire... | |||
} | |||
//Use POST to change bot userright | |||
(new mw.Api()).postWithToken('userrights', apiOptions).done(function(data){ | |||
console.log(data); | console.log(data); | ||
console.log(" | console.log("Botify success."); | ||
if (arguments.length >= 3) { | |||
callback(); | |||
} | |||
} | |||
}).fail(function(){ | |||
alert("Error in botify."); | |||
}); | }); | ||
Line 35: | Line 37: | ||
$('#choose_pages').on('submit', function(e){ | $('#choose_pages').on('submit', function(e){ | ||
e.preventDefault(); | e.preventDefault(); | ||
botify('add', '1 minute', function(){ | |||
$('#choose_pages').off('submit').submit(); | |||
}); | }); | ||
}); | }); |