User:Sander Säde/allest.js
Appearance
(Redirected from User:DLX/allest.js)
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. |
Documentation for this user script can be added at User:Sander Säde/allest. |
//Script to quickly get a list of all WikiProject Estonia articles
$(CollectButton);
function CollectButton() {
addPortletLink( chooseBox( 'wpe: AllEstTest', TwinkleConfig.toolboxButtons ), "javascript:allEstTest()", "wpe: allEstTest", "", "", "");
}
var estAjax;
var estArticles = new Array();
function allEstTest()
{
document.getElementById("contentSub").innerHTML = "";
getAllEstonianArticles();
}
function getAllEstonianArticles()
{
ajaxEstGet("http://wiki.riteme.site/w/api.php?action=query&list=categorymembers&cmtitle=Category:WikiProject_Estonia_articles&cmlimit=500&cmnamespace=1&cmprop=title&format=json");
}
function ajaxEstGet(url) {
estAjax = sajax_init_object(null);
estAjax.onreadystatechange = ajaxEstGetReceived;
estAjax.open("GET", url, true);
estAjax.send(null);
}
function ajaxEstGetReceived() {
if (estAjax.readyState != 4) return;
var response = eval('(' + estAjax.responseText + ')');
for(i = 0; i < response["query"]["categorymembers"].length; i++)
{
estArticles.push(response["query"]["categorymembers"][i]["title"].replace("Talk:", ""));
}
//nice progressbar
var s = "";
for(i = 0; i < Math.floor(estArticles.length / 30); i++)
{
s = s + "|";
}
document.getElementById("contentSub").innerHTML = s + " " + estArticles.length;
if (response["query-continue"] == null)
{
updateEstArticles();
document.getElementById("contentSub").innerHTML = "Posting...";
}
else
{
document.getElementById("contentSub").innerHTML = document.getElementById("contentSub").innerHTML + " " + response["query-continue"]["categorymembers"]["cmcontinue"];
ajaxEstGet("http://wiki.riteme.site/w/api.php?action=query&list=categorymembers&cmtitle=Category:WikiProject_Estonia_articles&cmlimit=500&cmnamespace=1&cmprop=title&format=json&cmcontinue=" + response["query-continue"]["categorymembers"]["cmcontinue"]);
}
}
function updateEstArticles() {
var getForm = sajax_init_object(null);
getForm.overrideMimeType('text/xml');
getForm.open( 'GET' , 'http://wiki.riteme.site/w/index.php?title=User:Sander_S%C3%A4de/WPEarticles&action=submit', true);
getForm.onreadystatechange = function() {
if(getForm.readyState != 4) return;
doUpdateEstArticles(getForm.responseXML);
};
getForm.send(null)
}
function doUpdateEstArticles(pg) {
form = pg.getElementById('editform');
if(!form ) return;
var text = '';
for(i = 0; i < estArticles.length; i++) {
text = text + " [[" + estArticles[i] + "]]·([[Talk:" + estArticles[i] + "|talk]]) | ";
}
text = estArticles.length + " articles found<br/>" + text;
var summary = 'Updating Estonia-related articles';
var postData = {
'wpMinoredit': form.wpMinoredit.checked, 'wpWatchthis': form.wpWatchthis.checked, 'wpStarttime': form.wpStarttime.value, 'wpEdittime': form.wpEdittime.value, 'wpAutoSummary': form.wpAutoSummary.value, 'wpEditToken': form.wpEditToken.value, 'wpSummary': summary, 'wpTextbox1': text};
var postFormAjax = sajax_init_object();
postFormAjax.overrideMimeType('text/xml');
postFormAjax.open( 'POST' , "http://wiki.riteme.site/w/index.php?title=User:Sander_S%C3%A4de/WPEarticles&action=submit", true);
postFormAjax.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
postFormAjax.onload = function() {
return;
}
postFormAjax.send( QueryString.create(postData));
document.getElementById("contentSub").innerHTML = "Update finished. " + estArticles.length + " articles found. <br />" + QueryString.create(postData) + "<br />" + text;
}