Difference between revisions of "User:Nx/monobook.js"

From RationalWiki
Jump to: navigation, search
m (improved status widget)
m (blog version)
Line 68: Line 68:
 
Uptime widget
 
Uptime widget
 
*/
 
*/
 
+
/*
 
function rwloadaverage()
 
function rwloadaverage()
 
{
 
{
Line 143: Line 143:
  
 
addOnloadHook(setup_server_monitor);
 
addOnloadHook(setup_server_monitor);
 +
*/
 +
 +
/*
 +
For the blog
 +
*/
 +
 +
function rwstatus()
 +
{
 +
  var req = false;
 +
  if (window.XMLHttpRequest) {
 +
    req = new XMLHttpRequest();
 +
  } else if (window.ActiveXObject) {
 +
    req = new ActiveXObject("Microsoft.XMLHTTP");
 +
  }
 +
  if (req) {
 +
    req.open("GET", "http://rationalwiki.com/widget/up.php", true);
 +
    req.onreadystatechange = function()
 +
    {
 +
      if (req.readyState==4)
 +
      {
 +
        if (req.status == 200) {
 +
          if (statusdiv = document.getElementById("rwstatus")) {
 +
            statusdiv.innerHTML = "<font color=green>Server online</font><br/>" + req.responseText;
 +
          }
 +
        } else {
 +
          if (statusdiv = document.getElementById("rwstatus")) {
 +
            statusdiv.innerHTML = "<font color=red>Server offline</font>";
 +
          }
 +
        }
 +
        setTimeout("rwstatus()",30000);
 +
      }
 +
    }
 +
    req.send(null);
 +
  }
 +
}
 +
 +
//why make things simple?
 +
if (window.attachEvent) {
 +
  window.attachEvent('onload', rwstatus);
 +
} else if (window.addEventListener) {
 +
  window.addEventListener('load', rwstatus, false);
 +
} else {
 +
  document.addEventListener('load', rwstatus, false);
 +
}
  
 
importScript('User:Nx/Scripts/Shared.js');
 
importScript('User:Nx/Scripts/Shared.js');

Revision as of 19:12, 12 September 2009

/*
var api = sajax_init_object();
api.open('GET', wgServer + wgScriptPath + '/api.php?format=json&action=query&prop=info&indexpageids=1&intoken=edit&titles=Whatever', true);
api.onreadystatechange = extract_token;
api.send(null);
function extract_token() {
	if(api.readyState==4) {
		if(api.status==200) {
			var response = eval('(' + api.responseText + ')');
			var token = response['query']['pages'][response['query']['pageids'][0]]['edittoken'];
			edit_page(token);
		}
		else {
			alert('The token query returned an error.');
		}
	}
}
 
// edit page (must be done through POST)
function edit_page(_token) {
	var parameters = 'action=edit&title=User:Nx/Sandbox&text=AJAX_test!&token=' +  encodeURIComponent(_token);
	api.open('POST', wgServer + wgScriptPath + '/api.php', true); // just reuse the same query object
	api.onreadystatechange = alert_result;
	api.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	api.setRequestHeader('Connection', 'keep-alive');
	api.setRequestHeader('Content-length', parameters.length);
	api.send(parameters);
 
	// process response
	function alert_result() {
		if(api.readyState==4) {
			if(api.status==200) {
				alert('Page edited!' +  api.responseText);
			}
			else {
				alert('The query returned an error.' +  api.responseText);
			}
		}
	}
}
*/


/*importScript('User:Nx/Scripts/Smileybox.js');
importScript('User:Nx/Scripts/Smileylist.js');
importScript('User:Nx/Scripts/Addcomment.js');
importScript('User:Nx/Scripts/Curse.js');
importScript('User:Nx/Scripts/AutoWIGO.js');*/
var nx_hfn_strict = true;
importScript('User:Nx/Scripts/HideFakeNotice.js');
/*importScript('User:Ipatrol/popups.js');
importScript('User:Nx/Scripts/Botwarn.js');
importScript('User:Π/Scripts/fakename.js');
//var botswitch_altacc = "NxBot";
//importScript('User:Nx/Scripts/Botswitch.js');
//importScript('User:Nx/Scripts/Autoarchive.js');
importScript('User:Nx/Scripts/Resurrect.js');
importScript("User:Nx/Scripts/RandomCP.js");
//importScript("User:Nx/Scripts/Editcount.js");
importScript("User:Nx/Scripts/Userrights.js");
*/

/*
Sandbox
*/

/*
Uptime widget
*/
/*
function rwloadaverage()
{
  var req = false;
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req) {
    req.open("GET", "http://rationalwiki.com/widget/up.php", true);
    req.onreadystatechange = function()
    {
      if (req.readyState==4) 
      {
        if (req.status == 200) {
          if (uptimewidget = document.getElementById("serveruptime")) {
            uptimewidget.style.display = "inline";
            uptimewidget.innerHTML = req.responseText.match(/Server uptime:<\/b> <br> (.*)<p>/)[1];
          }
          if (loadwidget = document.getElementById("serverload")) {
            loadwidget.style.display = "inline";
            loadwidget.innerHTML = req.responseText.match(/Server load:.*(<font.*<\/font>)/)[1];
          }
          if (statuswidget = document.getElementById("serverstatus")) {
            statuswidget.style.color = "green";
            statuswidget.innerHTML = "Server online";
          }
        } else {
          if (loadwidget = document.getElementById("serverload")) {
            loadwidget.style.display = "none";
          }
          if (uptimewidget = document.getElementById("serveruptime")) {
            uptimewidget.style.display = "none";
          }
          if (statuswidget = document.getElementById("serverstatus")) {
            statuswidget.style.color = "red";
            statuswidget.innerHTML = "Server offline";
          }
        }
        setTimeout("rwloadaverage()",30000);
      }
    }
    req.send(null);
  }
}

function setup_server_monitor() {
  if (columnone = document.getElementById("column-one")) {
    statusdiv = document.createElement("div");
    statusdiv.className = "portlet";
    
    heading = document.createElement("h5");
    heading.innerHTML = "status";
    statusdiv.appendChild(heading);
    statusbody = document.createElement("div");
    statusbody.className = "pBody";
    ul = document.createElement("ul");
    li1 = document.createElement("li");
    li2 = document.createElement("li");
    li3 = document.createElement("li");
    li1.innerHTML = "<span id=\"serverstatus\">";
    li2.innerHTML = "<span id=\"serveruptime\">";
    li3.innerHTML = "<span id=\"serverload\">";
    ul.appendChild(li1);
    ul.appendChild(li2);
    ul.appendChild(li3);
    statusbody.appendChild(ul);
    statusdiv.appendChild(statusbody);
    columnone.appendChild(statusdiv);
  }
  rwloadaverage();
}

addOnloadHook(setup_server_monitor);
*/

/*
For the blog
*/

function rwstatus()
{
  var req = false;
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req) {
    req.open("GET", "http://rationalwiki.com/widget/up.php", true);
    req.onreadystatechange = function()
    {
      if (req.readyState==4) 
      {
        if (req.status == 200) {
          if (statusdiv = document.getElementById("rwstatus")) {
            statusdiv.innerHTML = "<font color=green>Server online</font><br/>" + req.responseText;
          }
        } else {
          if (statusdiv = document.getElementById("rwstatus")) {
            statusdiv.innerHTML = "<font color=red>Server offline</font>";
          }
        }
        setTimeout("rwstatus()",30000);
      }
    }
    req.send(null);
  }
}

//why make things simple?
if (window.attachEvent) { 
  window.attachEvent('onload', rwstatus);
} else if (window.addEventListener) {
  window.addEventListener('load', rwstatus, false);
} else {
  document.addEventListener('load', rwstatus, false);
}

importScript('User:Nx/Scripts/Shared.js');

addOnloadHook(function() {
  if (mwEditButtons)
  {
    if (mwEditButtons.length >= 10)
    {
      if (mwEditButtons[9].tagOpen == ('--~' + '~' + '~'+ '~')) { mwEditButtons[9].tagOpen = ('~' + '~' + '~' + '~'); }
    }
  }
}
);