User:Lyrithya/deadlist.js
Jump to navigation
Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes.
- Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
- Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
- Opera, Konqueror and Safari users can just click the Reload button.
- Chrome: press Ctrl+F5 or Shift+F5
// <nowiki>
dl = {};
dl.addDL = function() {
if (document.getElementById('ca-edit')) {
addPortletLink('p-cactions', 'javascript:dl.go(1)', 'DL', 'td-dl', 'List page');
};
}
dl.debugOutput = function(str) {
dl.output += str;
dl.panel.setBody(dl.output);
}
dl.debugStatus = function(i) {
var s = (i) ? 'green;"> [OK]' : 'red;"> [FAILED]';
dl.debugOutput('<span style="font-weight: bold;color:' + s + '</span>');
}
dl.go = function(com, page) {
dl.comment = (com) ? " - " + escape(prompt("What's missing:","")) : '';
if (com && dl.comment == " - null") return;
dl.page = (page) ? page : wgPageName.replace(/_/g,' ');
dl.panel = new YAHOO.widget.Panel("Deathlist", { width:"240px", fixedcenter:true, draggable:true, zindex:10, modal:false, visible:false } );
dl.panel.setHeader('Listing, please wait...');
dl.panel.setFooter('<br /><hr>We\'re all doomed.')
dl.output = '';
dl.debugOutput("<br />Loading list page...");
dl.panel.render(document.body);
dl.panel.show();
YAHOO.util.Connect.asyncRequest('GET', '/api.php?action=query&titles=User:Lyrithya/deathlist/other&prop=revisions|info|links&pllimit=500&rvprop=content&rvlimit=1&rvsection=1&format=xml&intoken=edit', dl.update, null);
}
dl.update = {
success: function(o) {
dl.debugStatus(1);
dl.debugOutput("<br />Checking list for selected page...");
var titles = o.responseXML.getElementsByTagName('pl');
for (lk in titles) {
try {
if (titles[lk].getAttribute('title') == dl.page) {
dl.debugStatus(0);
dl.debugOutput('<br />Page already on list?<br /><a href="javascript:dl.panel.hide()">Close</a>');
return;
}
} catch(e) {};
}
dl.debugStatus(1);
dl.debugOutput('<br />Page not listed, adding it now...');
try {
var sectionText = o.responseXML.getElementsByTagName('rev')[0].firstChild.nodeValue;
var lines = sectionText.split('\n');
var redirect = (document.getElementById('contentSub').innerHTML.indexOf('Redirect page') == -1) ? 0 : 1;
if (redirect == 0) {
lines.splice(1,0,' [[:' + dl.page + ']]' + dl.comment);
} else {
lines.splice(1,0,' {{redirect|' + dl.page + '}}' + dl.comment);
};
sectionText = lines.join('\n');
} catch(e) {
dl.debugStatus(0);
dl.debugOutput('<br />Could not add text to the page...<br /><a href="javascript:dl.panel.hide()">Close</a>');
return;
}
dl.debugStatus(1);
dl.debugOutput('<br />Saving page...');
var token = o.responseXML.getElementsByTagName('page')[0].getAttribute('edittoken');
var post = 'title=User:Lyrithya/deathlist/other§ion=1&token=' + encodeURIComponent(token) + '&summary=%2B[[' + encodeURIComponent(dl.page) + ']]&text=' + encodeURIComponent(unescape(sectionText));
YAHOO.util.Connect.asyncRequest('POST', '/api.php?action=edit&format=xml', dl.saved, post);
},
failure: function() {
dl.debugStatus(0);
dl.debugOutput('<br />Couldn\'t connect to list page...<br /><a href="javascript:dl.panel.hide()">Close</a>');
}
}
dl.saved = {
success: function(o) {
try {
result = (o.responseXML.getElementsByTagName('edit')[0].getAttribute('result') == 'Success') ? 1 : 0;
} catch(e) {
result = 0;
}
if (result) {
dl.debugStatus(1);
dl.debugOutput('<br /><b>Saved!</b><br /><a href="/wiki/User:Lyrithya/deathlist/other">Go to list</a> or <br /><a href="javascript:dl.panel.hide()">close</a>');
} else {
with(o.responseXML.getElementsByTagName('error')[0]) {
dl.debugStatus(0);
dl.debugOutput('<br /><b>Saving failed :(</b><br />Error: ' + getAttribute('code') + ' - ' + getAttribute('info') + '<br /><a href="/wiki/User:Lyrithya/deathlist/other">Add manually</a> or <br /><a href="javascript:dl.panel.hide()">close</a>');
}
}
},
failure: function(o) {
dl.debugStatus(0);
dl.debugOutput('<br /><b>Connection failed :(</b><br /><a href="/wiki/User:Lyrithya/deathlist/other">Go to list</a> or <br /><a href="javascript:dl.panel.hide()">close</a>');
}
}
YAHOO.util.Event.onContentReady('p-cactions', dl.addDL);
// </nowiki>