User:Elkman/js/dyk-notifier.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. |
Documentation for this user script can be added at User:Elkman/js/dyk-notifier. |
// <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);