User:Vikarna/ol.js

function wgUXS (wg, hans, hant, cn, tw, hk, sg, zh, mo, my) { var ret = { 'zh': zh || hans || hant || cn || tw || hk || sg || mo || my, 'zh-hans': hans || cn || sg || my, 'zh-hant': hant || tw || hk || mo, 'zh-cn': cn || hans || sg || my, 'zh-sg': sg || hans || cn || my, 'zh-tw': tw || hant || hk || mo, 'zh-hk': hk || hant || mo || tw, 'zh-mo': mo || hant || hk || tw   }; return ret[wg] || zh || hans || hant || cn || tw || hk || sg || mo || my; //保證每一語言有值 }

function wgULS (hans, hant, cn, tw, hk, sg, zh, mo, my) { return wgUXS(mw.config.get('wgUserVariant'), hans, hant, cn, tw, hk, sg, zh, mo, my); }

(function(mw) {   // 只在用户或用户讨论名字空间显示    var username = mw.config.get('wgRelevantUserName');    if ( username ) {    	var msg = '';    	var string;    	var string1 = wgULS("时间：", "時間：");    	var string2 = wgULS("在线", "在綫", undefined, "在線");    	var string3 = wgULS("上线", "上綫", undefined, "上線");    	var string4 = wgULS("最后", "最後");        // 需要元素        var div = document.getElementById('content').insertBefore(document.createElement('div'), document.getElementById('bodyContent'));        div.style.display = "none";    	div.id = 'mw-status';    	div.align = 'right';    	div.appendChild(document.createTextNode(string2 + wgULS('情况：', '情況：')));    	var img = div.appendChild(document.createElement('img'));    	img.src = "https://upload.wikimedia.org/wikipedia/commons/";        var showtime = false;

var api = new mw.Api; // API:RecentChanges, API:LogEvents, API:Blocks api.get({           format: 'json',            action: 'query',            list: 'usercontribs|logevents|blocks',            ucuser: username,            leuser: username,            bkusers: username,            ucprop: 'timestamp',            leprop: 'timestamp',            uclimit: 1,            lelimit: 1,            bklimit: 1        }).done(function (data) {        	var time = data.query;        	{            	if ( ( time.usercontribs.length + time.logevents.length ) !== 0 ) {            		string = string3 + string1;            		showtime = true;            		if ( time.logevents.length === 0 ) {            			time.logevents[0] = {"timestamp": 1};            		}

// 比較大小 var hist = ( new Date(time.usercontribs[0].timestamp) > new Date(time.logevents[0].timestamp) ? time.usercontribs[0].timestamp : time.logevents[0].timestamp ); var diff = ( new Date.getTime ) - ( new Date(hist).getTime ); // 最後更改時間 string += hist.replace("T", " ").replace("Z", ""); // 離綫用紅點，可能離綫用黃點，在綫用綠點，非活躍用戶用藍點 if ( diff < 300000 ) { img.src += "7/74/Disc_Plain_green.svg"; msg = string2; }               	else if ( diff < 600000 ) { img.src += "7/75/Disc_Plain_yellow_dark.svg"; msg = wgULS("可能" + string2, "可能" + string2) + "；"; string = string4 + string; }               	else if ( diff > 2592000000 ) { img.src += "0/02/Disc_Plain_blue.svg"; msg = wgULS("非活跃", "非活躍；"); string = string4 + string; }               	else { img.src += "1/13/Disc_Plain_red.svg"; msg = wgULS("离线；", "離綫；", undefined, "離線；"); string = string4 + string; }           	}            }            var p = document.createElement("p"); p.innerHTML = msg; if ( showtime ) p.innerHTML += " " + string + " (UTC)"; p.innerHTML += " (留言)"; img.onclick = function { mw.notify(p); };            img.width = img.height = 25; img.alt = msg; div.style.display = "block"; });   } })(mw);