Harpocrates

Helps the Olympian scripts when they need GreaseMonkey functions

当前为 2016-09-12 提交的版本,查看 最新版本

// ==UserScript==
// @name         Harpocrates
// @namespace    mobiusevalon.tibbius.com
// @version      0.2
// @author       Mobius Evalon
// @description  Helps the Olympian scripts when they need GreaseMonkey functions
// @license      Creative Commons Attribution-ShareAlike 4.0; http://creativecommons.org/licenses/by-sa/4.0/
// @include      /^https{0,1}:\/\/\w{0,}\.?mturk\.com.+/
// @include      /^https{0,1}:\/\/\w*\.amazon\.com\/ap\/signin.*(?:openid\.assoc_handle|pf_rd_i)=amzn_mturk/
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

// use of unsafeWindow is necessary to get harpocrates into the un-sandboxed
// space with the rest of the olympian scripts
if(unsafeWindow.olympus === undefined) unsafeWindow.olympus = {};

unsafeWindow.olympus.harpocrates = {
	__12_hrs:43200000,
	get login_timestamp() {
		return GM_getValue("login_timestamp",0);
	},
	__init:function() {
		console.log("harpocrates init");
		if(/^https{0,1}:\/\/\w{0,}\.amazon\.com\/ap\/signin/i.test(window.location.href)) {
			$("#signInSubmit-input").click(function() {
				GM_setValue("login_timestamp",Date.now());
			});
		}
		else {
			olympus.style.add(".red {color: #f00;}");
			this.display();
		}
	},
	display:function() {
		var login_time = (this.login_timestamp*1);
		if(login_time > 0) {
			var time_left = ((this.__12_hrs-(Date.now()-login_time))/1000);
			$("span.header_links").append(
				$("<br/>"),
				$("<b/>")
					.attr("class",("logout_time"+(time_left <= 3600 ? " red" : "")+(time_left <= 1800 ? " anim_pulse" : "")))
					.text("Time to logout: "+(time_left <= 300 ? "any moment" : olympus.utilities.dhms(time_left)))
			);
		}
	}
};