User:Bawolff/DYKVerified.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:Bawolff/DYKVerified. |
importScriptURI('http://en.wikinews.org/w/index.php?action=raw&ctype=text/javascript&title=User:Bawolff/mwapilib2.js')
function filterDYKSuggest(text) {
var lines = text.split('\n');
var out = '';
var mode = 0;
var h2 = /^==[^=].*[^=]==$/, h3 = /^===[^=].*[^=]===$/, h4 = /^====[^=].*[^=]====$/;
var verified = /\[\[File:Symbol confirmed\.svg\|16px\]\]|\[\[File:Pictogram voting keep\.svg\|16px\]\]/;
var buffer = '';
loop: for (var i = 0; i < lines.length; i++) {
switch (mode) {
case 0: //before text
if (lines[i] === '==Candidate entries==') {
//alert('cand');
//out += lines[i] + '\n';
mode++;
continue loop;
}
break;
case 1: //in possibly but not yet interesting part
if (lines[i].match(h2)) { // next section
//alert('match h2' + lines[i] + mode);
mode = 3;
break loop; //done
}
if (lines[i].match(h3)) {
buffer = ''; //reset buffer
out += lines[i] + '\n';
continue loop;
}
if (lines[i].match(h4)) {
buffer = lines[i] + '\n';
continue loop;
}
if (lines[i].match(verified)) {
mode++;
}
buffer += lines[i] + '\n';
break;
case 2: //in interesting nom.
if (lines[i].match(h2)) { // next section
//alert('match h2' + lines[i] + mode);
out += buffer;
mode = 3;
break loop; //done
}
if (lines[i].match(h3)) {
out += buffer;
buffer = ''; //reset buffer
out += lines[i] + '\n';
mode--;
continue loop;
}
if (lines[i].match(h4)) {
out += buffer;
buffer = lines[i] + '\n';
mode--;
continue loop;
}
buffer += lines[i] + '\n'
break;
default:
break loop;
}
}
return out;
}
function DYKUpdateVerified () {
api('template_talk:Did you know').getPage().lift(filterDYKSuggest).
setDefaultSummary('Updating Verified DYK (using experimental [[User:Bawolff/DYKVerified.js]])').
savePage('User:Bawolff/DYKVerified').exec();
}
addOnloadHook(function () {
var button = document.getElementById('DYKUpdateVerified');
if (button) button.innerHTML = "<button type='button' onclick='DYKUpdateVerified();'>Update verified DYK list</button>";
});