User:Decltype/status.js

// When looking at a page in "User" or "User talk", the script will // display how long the user has been idle. Based almost entirely on: /* ======================================================== *\ \* ======================================================== */
 * StatusCheck - JavaScript User Online Status Checker
 * for Wikipedia
 * Created by Alex Barley User:Ale_jrb
 * Created by Alex Barley User:Ale_jrb

// 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 ((mw.config.get('wgNamespaceNumber') == 2) || (mw.config.get('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 (mw.config.get('wgPageName') == 'Special:Contributions') { this.userName = window.location.href.substr(window.location.href.indexOf('Special:Contributions/') + 22).replace("&action=view",""); if (this.userName == '') return false; } else { if (mw.config.get('wgTitle').indexOf('/') > -1) { this.userName = mw.config.get('wgTitle').substr(0, mw.config.get('wgTitle').indexOf('/')); } else { this.userName = mw.config.get('wgTitle'); } }	this.runCheck = function(callback, value) { 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 = Math.max(lastAction, lastEdit);

var currentTime = new Date; currentTime = ((currentTime.getTime / 1000) + (currentTime.getTimezoneOffset * 60)); // build interface var seconds = currentTime - mostRecent; var minutes = seconds / 60; var hours = minutes / 60; var days = hours / 24; var toDisplay; if(days > 1.0) { toDisplay = days.toFixed(0) + " days"; } else if(hours > 1.0) { toDisplay = hours.toFixed(0) + " hours"; } else if(minutes > 1.0) { toDisplay = minutes.toFixed(0) + " minutes"; } else { toDisplay = seconds + " seconds"; }

statusCheck.runCheck('4', toDisplay); break; case '4': statusCheck.interface.win_bg		= '#bbddbb'; statusCheck.interface.win_bd		= '#99cc99'; statusCheck.interface.win_content	= 'Idle ' + value + ' 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'); $(launchstatusCheck);