User:Manyman/statusCheck.js

/* ======================================================== *\ \* ======================================================== */ // the following settings are used in this script: if (offlineAfter == null)	var offlineAfter 			= (15 * 60);	// number of seconds after which a user is considered offline (default: 15 * 60 seconds) if (statCloseOnClick == null)	var statCloseOnClick 	= true;			// whether to close the status window when clicking on it if (statPosition == null)	var statPosition = new Array(20, 600);		// position of the status window [left, top, right, bottom] //main script function statusCheck { this.launch = function { // launch helper. check whether there is a deletion tag on this page. if ((wgNamespaceNumber == 2) || (wgNamespaceNumber == 3) || (window.location.href.indexOf('Special:Contributions/') > -1)) { this.control	= new statusCheck_controller; this.control.runCheck; } else { return false; /* do nothing!*/ } } } function statusCheck_controller { var statusCheck = this; if (wgPageName == 'Special:Contributions') { this.userName = window.location.href.substr(window.location.href.indexOf('Special:Contributions/') + 22); if (this.userName == '') return false; } else { if (wgTitle.indexOf('/') > -1) { this.userName = wgTitle.substr(0, wgTitle.indexOf('/')); } else { this.userName = wgTitle; } }	this.runCheck = function(callback) { switch(callback) { default: statusCheck.interface = new wa_window; statusCheck.interface.win_left 		= statPosition[0]; statusCheck.interface.win_top 		= statPosition[1]; if (statPosition[2] != null)		statusCheck.interface.win_right = statPosition[2]; if (statPosition[3] != null)		statusCheck.interface.win_bottom = statPosition[3]; statusCheck.interface.win_width 	= 110; statusCheck.interface.win_height 	= 35; statusCheck.interface.win_bg		= '#dddddd'; statusCheck.interface.win_bd		= '#aaaaaa'; statusCheck.interface.win_bd_wd		= 1; statusCheck.interface.win_alpha 	= 0.75; statusCheck.interface.win_pos 		= 'fixed'; statusCheck.interface.win_content	= ' Checking status... StatusCheck '; statusCheck.interface.applyAll; statusCheck.runCheck('1'); break; case '1': statusCheck.user = new wa_mediawikiUser(this.userName); statusCheck.user.getUserContribs(1, function { statusCheck.runCheck('2'); }); break; case '2': statusCheck.user.getUserLogs(1, function { statusCheck.runCheck('3'); }); break; case '3': // regex extract data: [0] - year; [1] - month; [2] - day; [3] - hour; [4] - minutes; [5] - seconds var regTest = /([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z/; statusCheck.lastEdit = []; var tempCheck = []; tempCheck = regTest.exec(statusCheck.user.editDetails[0]['timestamp']); if (tempCheck != null) { statusCheck.lastEdit = tempCheck.slice(1); } else { statusCheck.lastEdit = false; } statusCheck.lastAction = []; var tempCheck2 = []; tempCheck2 = regTest.exec(statusCheck.user.logDetails[0]['timestamp']); if (tempCheck2 != null) { statusCheck.lastAction = tempCheck2.slice(1); } else { statusCheck.lastAction = false; } // convert both timestamps to seconds if (statusCheck.lastEdit != false) { var timeEdit = new Date; timeEdit.setFullYear(statusCheck.lastEdit[0], statusCheck.lastEdit[1] - 1, statusCheck.lastEdit[2]); timeEdit.setHours(statusCheck.lastEdit[3]); timeEdit.setMinutes(statusCheck.lastEdit[4]); timeEdit.setSeconds(statusCheck.lastEdit[5]); var lastEdit = (timeEdit.getTime / 1000); } else { var lastEdit = 0; } if (statusCheck.lastAction != false) { var timeAction = new Date; timeAction.setFullYear(statusCheck.lastAction[0], statusCheck.lastAction[1] - 1, statusCheck.lastAction[2]); timeAction.setHours(statusCheck.lastAction[3]); timeAction.setMinutes(statusCheck.lastAction[4]); timeAction.setSeconds(statusCheck.lastAction[5]); var lastAction = (timeAction.getTime / 1000); } else { var lastAction = 0; } var mostRecent; if (lastAction >= lastEdit) { mostRecent = lastAction; } else { mostRecent = lastEdit; } var currentTime = new Date; currentTime = ((currentTime.getTime / 1000) + (currentTime.getTimezoneOffset * 60)); if ((currentTime - mostRecent) > offlineAfter) { /*offline*/ statusCheck.online = false; } else { /*online*/ statusCheck.online = true; } // build interface statusCheck.runCheck('4'); break; case '4': if (statusCheck.online == true) { statusCheck.interface.win_bg		= '#bbddbb'; statusCheck.interface.win_bd		= '#99cc99'; statusCheck.interface.win_content	= 'online StatusCheck '; } else { statusCheck.interface.win_bg		= '#ddbbbb'; statusCheck.interface.win_bd		= '#cc9999'; statusCheck.interface.win_content	= 'offline StatusCheck '; }				statusCheck.interface.win_alpha 	= 0.95; statusCheck.interface.win_cursor	= 'pointer'; statusCheck.interface.win_func		= function { statusCheck.interface.fade(0.3); }; statusCheck.interface.applyAll; break; }	} } // -- run program function launchstatusCheck { // lib proto wa_window.prototype = new wa_document; wa_element.prototype = new wa_document; // init object var obj_statusCheck = new statusCheck; obj_statusCheck.launch; return true; } importScript('User:Ale_jrb/Scripts/waLib.js'); hookEvent('load', launchstatusCheck);
 * StatusCheck - JavaScript User Online Status Checker
 * for Wikipedia
 * Created by Alex Barley User:Ale_jrb
 * Created by Alex Barley User:Ale_jrb