// <nowiki>
// <pre>
/*
To install, add
// ]
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+"|"+year;
}
function clear(){
var parent = document.getElementById("log");
while ( parent.hasChildNodes() ) { parent.removeChild(parent.firstChild); }
}
function makeXhr() {
xhr = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
xhr = new XMLHttpRequest();
if (xhr.overrideMimeType) {
// set type accordingly to anticipated content type
//xhr.overrideMimeType('text/xml');
xhr.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!xhr) {
alert('Cannot create XMLHTTP instance');
return false;
}
return xhr;
}
function makePOSTRequest(url, parameters) {
//xhr.onreadystatechange = alertContents;
var xhr = makeXhr();
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-length", parameters.length);
xhr.setRequestHeader("Connection", "close");
xhr.onreadystatechange = function()
{
if(xhr.readyState == 4)
{
if(xhr.status == 200) {
mylog("successful!");
}
}
}
xhr.open('POST', url, false);
xhr.send(parameters);
}
function postTalk(user,msg,summary)
{
var xhr = makeXhr();
xhr.onreadystatechange = function(){
if(xhr.readyState == 4)
{
if(xhr.status == 200) {
var doc = xhr.responseXML;
var form = xhr.responseXML.getElementById( 'editform' );
var pstr = 'wpEditToken='+encodeURIComponent(form.wpEditToken.value) + "&"+
'wpAutoSummary='+encodeURIComponent(form.wpAutoSummary.value) + "&"+
'wpStarttime='+encodeURIComponent(form.wpStarttime.value) + "&"+
'wpEdittime='+encodeURIComponent( form.wpEdittime.value) + "&"+
//'wpSave='+encodeURIComponent("Save page") + "&" +
'wpSection=new&'+
'wpSummary='+encodeURIComponent("foo") + "&" +
'wpTextbox1='+encodeURIComponent("foo");
alert(form.action); alert(pstr);
makePOSTRequest(form.action,pstr);
}
}
};
xhr.overrideMimeType('text/xml');
xhr.open('GET', "http://en.wikipedia.org/w/index.php?title="+user+"&action=edit", false);
xhr.send(null);
}
function xpathfind(findPattern) {
return document.evaluate( findPattern, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
}
function dykNotifyAll(autosave) {
allLinks = xpathfind("//div/ul/li");
for(i=0;i<allLinks.snapshotLength;i++) {
var idx = i + 1;
articleLink = xpathfind("//div/ul/li//a");
var title = articleLink.snapshotItem(0).textContent;
mylog(title);
var atalkurl = articleLink.snapshotItem(0).href.replace("https://wikifreehand.com/en/","https://wikifreehand.com/en/Talk:")+"?action=edit&xamfind="+escape("({{.*}})?(.*\n=.*=)?")+"&amreplace="+escape("$1\n{{dyktalk|"+mydate()+"}}\n$2")+"&amsummary=Dyktalk"+autosave;
postTalk("User_talk:Henrik/sandbox/test1","hello ~~"+"~~","hi");
//mylog(" -- talk page: " + atalkurl);
resultLinks = xpathfind("//div/ul/li//a");
if ( (res = resultLinks.snapshotItem(0) ) != null ){
authormsg = escape("{"+"{subst:UpdatedDYK|"+mydate()+"|"+title+"}} --~~"+"~~");
authorurl = res.href+"?action=edit§ion=new&amsummary="+escape(title)+"&amaddbefore="+authormsg+autosave;
//window.open(authorurl,"authortalk"+i);
mylog(" -- author: " + res.textContent);
}
if ( (res = resultLinks.snapshotItem(1) ) != null ){
authormsg = escape("{"+"{subst:UpdatedDYKNom|"+mydate()+"|"+title+"}} --~~"+"~~");
authorurl = res.href+"?action=edit§ion=new&amsummary="+escape(title)+"&amaddbefore="+authormsg+autosave;
//window.open(authorurl,"notifiertalk"+i);
mylog(" -- nominator: " + res.textContent);
}
}
}
function insertDykButtons() {
if (mw.config.get('wgPageName') != "User:Henrik/sandbox" &&
mw.config.get('wgPageName') != "Template:Did_you_know/Next_update" &&
mw.config.get('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);
// </nowiki>