Jump to content

User:Parent5446/MediaWiki/AvatarMessaging.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <pre><nowiki>
// License: [[Public Domain]]
// Created by [[User:Parent5446]]


//Customizable Variables
var ProjectName="Avatar: The Last Airbender task force";
var MainProjectPage="Wikipedia:WikiProject%20Television/Avatar:%20The%20Last%20Airbender%20task%20force";

var IsMemberPageSubpageOfMainPage=true;
var MembersPage="members"; //If above value is set to true, only enter sub-page name (no slash or anything)

var IsTaskForce=true;
var ParentProject="Television WikiProject";
var ParentProjectMainPage="Wikipedia:WikiProject%20Television";

var EditSummary="";
var SectionHeading=""; //This will be added before the message name.


//DO NOT EDIT BELOW THIS LINE
//Global Variable
var UserArray;
var token;
var timestamp;

function getMemberArray() {
  var xmlHttpMember;
  try {
    xmlHttpMember=new XMLHttpRequest();
  }
  catch (e) {
    try {
      xmlHttpMember=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttpMember=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttpMember.onreadystatechange=function() {
    if(xmlHttpMember.readyState==4&&xmlHttpMember.status==200) {
      var MembersXML=xmlHttpMember.responseXML.documentElement;
      for (i=0;i<MembersXML.getElementsByTagName('pl').length;i++) {
        UserArray[x]=MembersXML.getElementsByTagName('pl')[i].attributes.title.nodeValue;
      }
    }
  }
  var url="http://en.wikipedia.org/w/api.php?action=query&plnamespace=3&prop=links&tlnamespace=3&format=xml&titles=";
  if(IsMemberPageSubpageOfMainPage) {
    url+=escape(MainProjectPage)+"/"+escape(MembersPage);
  }
  else {
    url+=escape(MembersPage);
  }
  xmlHttpMember.open("GET",url,true);
  xmlHttpMember.send(null);
}

function createEntryBox() {
  if(wgPageName!="User:Parent5446/MediaWiki/AvatarMessaging.js") { return; }
  var bodyContent='Message Header:<br /><input type="text" maxlength="50" name="MessageHeader" id="MessageHeader" size="25" title="Message Header" />';
  bodyContent+='<br /><br />Message:<br /><textarea rows="26" cols="60" name="Message" id="Message" title="Message" /></textarea>';
  bodyContent+='<br /><input type="button" name="Submit" id="Submit" value="Submit" onclick="submitMessage()" />';
  document.getElementById('content').innerHTML=bodyContent;
}
  
function submitMessage() {
  getMemberArray();
  getToken();
  for(x in UserArray) {
    var xmlHttpMember;
    try {
      xmlHttpMember=new XMLHttpRequest();
    }
    catch (e) {
      try {
        xmlHttpMember=new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch (e) {
        try {
          xmlHttpMember=new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {
          alert("Your browser does not support AJAX!");
          return false;
        }
      }
    }
    var MessageToSend='=='+escape(document.getElementById('MessageHeader').value)+'==\n'+escape(document.getElementById('Message').value);
    var url='http://en.wikipedia.org/w/api.php?action=edit&section=new&notminor=yes&recreate=yes&title='+escape(UserArray[x]);
    url+='&text='+MessageToSend+'&token='+token;
    xmlHttpMember.open("GET",url,true);
    xmlHttpMember.send(null);
  }
  document.getElementById('content').innerHTML="Messages sent.";
}

function getToken() {
  var xmlHttpMember;
  try {
    xmlHttpMember=new XMLHttpRequest();
  }
  catch (e) {
    try {
      xmlHttpMember=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        xmlHttpMember=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {
        alert("Your browser does not support AJAX!");
        return false;
      }
    }
  }
  xmlHttpMember.onreadystatechange=function() {
    if(xmlHttpMember.readyState==4&&xmlHttpMember.status==200) {
      var TokenXML=xmlHttpMember.responseXML.documentElement;
      var RawToken=TokenXML.getElementsByTagName('page')[0].attributes.edittoken.nodeValue;
      token=escape(RawToken);
    }
  }
  var url="http://en.wikipedia.org/w/api.php?action=query&prop=info&intoken=edit&format=xml&titles=";
  if(IsMemberPageSubpageOfMainPage) {
    url+=escape(MainProjectPage)+"/"+escape(MembersPage);
  }
  else {
    url+=escape(MembersPage);
  }
  xmlHttpMember.open("GET",url,true);
  xmlHttpMember.send(null);
}

addOnloadHook(createEntryBox());
//</pre></nowiki>