User:Ale jrb/Scripts/statusCheck.js
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.
/* ======================================================== *\
** StatusCheck - JavaScript User Online Status Checker
** for Wikipedia
**
** 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);
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) {
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_fontsize = 10;
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 = '<div style="width: 100px; margin: auto; margin-top: 2px; text-align: center; font-size: 1.15em;">Checking status...</div><div style="width: 100px; margin: auto; margin-top: 7px; text-align: center; font-size: 0.85em;">StatusCheck</div>';
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':
var contribsLink = '(<a href="'+mw.config.get('wgServer')+mw.config.get('wgArticlePath').replace('$1','Special:Contributions')+'/'+statusCheck.userName+'">contribs</a>)';
if (statusCheck.online == true) {
statusCheck.interface.win_bg = '#bbddbb';
statusCheck.interface.win_bd = '#99cc99';
statusCheck.interface.win_content = '<div style="width: 100px; margin: auto; margin-top: 2px; text-align: center; font-size: 1.15em; color: #00aa00;">online</div><div style="width: 100px; margin: auto; margin-top: 7px; text-align: center; font-size: 0.85em;">StatusCheck '+contribsLink+'</div>';
} else {
statusCheck.interface.win_bg = '#ddbbbb';
statusCheck.interface.win_bd = '#cc9999';
statusCheck.interface.win_content = '<div style="width: 100px; margin: auto; margin-top: 2px; text-align: center; font-size: 1.15em; color: #dd3333;">offline</div><div style="width: 100px; margin: auto; margin-top: 7px; text-align: center; font-size: 0.85em;">StatusCheck '+contribsLink+'</div>';
}
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;
}
$.getScript("https://en.wikipedia.org/w/index.php?title=User:Ale_jrb/Scripts/waLib.js&action=raw&format=text/javascript", function() {$(document).ready(launchstatusCheck);});