// <pre>
/*
To install, add
// [[User:Henrik/dyk-notifier]]
importScript('User:Henrik/js/dyk-notifier.js');
to your monobook.js (located at User:YOURUSERNAME/monobook.js)
*/
function mylog(text) {
var p2 = document.createElement("p");
p2.appendChild(
document.createTextNode(text)
);
p2.setAttribute("class", "labrat");
var bottle = document.getElementById("log");
bottle.appendChild(p2);
}
function mydate()
{
var months = ["January","February","March","April",
"May","June","July","August",
"September","October","November","December"];
var currentTime = new Date();
var month = currentTime.getMonth();
var day = currentTime.getDate();
var year = currentTime.getFullYear();
return ""+day+" "+months[month]+"|"+year;
}
function clear(){
var parent = document.getElementById("log");
while ( parent.hasChildNodes() ) { parent.removeChild(parent.firstChild); }
}
function xpathfind(findPattern) {
return document.evaluate( findPattern, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
}
function dykNotifyAll(autosave) {
allLinks = xpathfind("//div[@id=\"credits\"]/ul/li");
for(i=0;i<allLinks.snapshotLength;i++) {
var idx = i + 1;
articleLink = xpathfind("//div[@id=\"credits\"]/ul/li["+idx+"]//a[1]");
var title = articleLink.snapshotItem(0).textContent;
//mylog(title);
// autoedit search/replace below will probably add it to the end of the whole thing. Consider adding section 0 to this.
var atalkurl = articleLink.snapshotItem(0).href.replace("/wiki/","/wiki/Talk:")
+"?action=edit&autoedit=s/$/" + escape("\n{{dyktalk|" + mydate() + "}}\n/")
+"&autosummary=DYK"+autosave;
window.open(atalkurl,"articletalk"+i);
//mylog(" -- talk page: " + atalkurl);
resultLinks = xpathfind("//div[@id=\"credits\"]/ul/li["+idx+"]//a[starts-with(@title,'User talk:')]");
if ( (res = resultLinks.snapshotItem(0) ) != null ){
authormsg = "s/$/" + "{"+"{subst:" + escape("UpdatedDYK|"+mydate()+"|"+title+"}} --~~"+"~~") + "/";
// New arguments to popups.js scripts
authorurl = res.href+"?action=edit§ion=new&autosummary="+escape(title)+"&autoedit="+authormsg+autosave;
window.open(authorurl,"authortalk"+i);
//mylog(" -- author: " + authorurl);
}
if ( (res = resultLinks.snapshotItem(1) ) != null ){
authormsg = "s/$/" + "{"+"{subst:" + escape("UpdatedDYKNom|"+mydate()+"|"+title+"}} --~~"+"~~") + "/";
// New arguments to popups.js scripts
authorurl = res.href+"?action=edit§ion=new&autosummary="+escape(title)+"&autoedit="+authormsg+autosave;
window.open(authorurl,"notifiertalk"+i);
// //mylog(" -- author: " + authorurl);
}
}
}
function insertDykButtons() {
if (wgPageName != "User:Elkman/temp" &&
wgPageName != "Template:Did_you_know/Next_update" &&
wgPageName != "Template:Did_you_know/Next_update/Clear")
return;
d=document.createElement('div')
var b=document.createElement('input');
b.type='button';
b.value='Notify contributors';
b.onclick=function(){
dykNotifyAll("");
}
d.appendChild(b);
var b=document.createElement('input');
b.type='button';
b.value='Notify contributors (autosave)';
b.onclick=function(){
dykNotifyAll("&amautosave=1");
}
d.appendChild(b);
document.getElementById("credits").appendChild(d);
}
$(insertDykButtons);