User:TigerShark/WikiBreak

//- //Server-based Wikibreak enforcer //-

// XMLHttpRequest support (thanks to Sam Hocevar for this code) // --

if (document.implementation.createDocument) { var gml_xmlparser = new DOMParser; } function gml_XMLParse(string) { if (document.implementation.createDocument) { return gml_xmlparser.parseFromString(string, "text/xml"); } else if (window.ActiveXObject) { var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM"); gml_xmldoc.async = "false"; ret = gml_xmldoc.loadXML(string); if (!ret) return null; return gml_xmldoc.documentElement; } return null; }

var gml_xmlhttp;

function HTTPClient { var gml_http; if(window.XMLHttpRequest) { gml_http = new XMLHttpRequest; } else if (window.ActiveXObject) { try { gml_http = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { gml_http = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { gml_http = false; }   }  }  return gml_http; }

//Main Wikibreak logic (thanks to Mike1024 for the initial inspiration and code used as a template) //-

addOnloadHook(EnforceWikiBreak2);

function EnforceWikiBreak2 {     //Date based bypass for testing //var currentdate = new Date; //var enforced_break_end = new Date("November 1, 2006"); //alert(enforced_break_end); // if (currentdate < enforced_break_end) // {            //alert("Performing WikiBreak check..."); GetContents; // } }

function GetContents {

gml_xmlhttp = HTTPClient; if (!gml_xmlhttp) return;

history_url = "http://en.wikipedia.org/w/index.php?title=User:TigerShark/DateTime&action=purge";

gml_xmlhttp.open("GET", history_url, true); gml_xmlhttp.onreadystatechange = StepTwo; gml_xmlhttp.send(null);

}

function StepTwo { if (gml_xmlhttp.readyState != 4) return;

xml = gml_xmlhttp.responseText;

var iStart; var iEnd; strTest = "CHECKDATESTART"; iStart = xml.indexOf(strTest); strEnd = "CHECKDATEEND"; iEnd = xml.indexOf(strEnd);

if(iStart == -1) {   alert("CHECKDATESTART Not Found"); } else {    var thechar = ""; var icounter; for (icounter=iStart + 14; icounter<=iEnd-1; icounter=icounter+1) {       thechar += xml.charAt(icounter); }    //alert(thechar); var cDate = new Date(thechar);

//SET THIS TO THE END DATE/TIME FOR THE WIKIBREAK var enforceddate = new Date("May 1, 2006 18:00");

if (enforceddate > cDate) {      alert("You should be on a Wikibreak!!!"); window.location = "http://en.wikipedia.org/w/index.php?title=Special:Userlogout&returnto=Main_page"; }

} }