Harpocrates

Helps the Olympian scripts when they need GreaseMonkey functions

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Harpocrates
// @namespace    mobiusevalon.tibbius.com
// @version      1.0-7
// @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 = {
	__name:"harpocrates",
	__version:"1.0-7",
	__href:"https://greasyfork.org/en/scripts/23157-harpocrates",
	__12_hrs:43200000,
	__stamp:function() {
		var s = (localStorage.harpocrates_login_timestamp*1);
		if($.type(s) === "number") return s;
		else return 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());
				GM_setValue("new_login","true");
			});
		}
		else {
			olympus.style.add(
				".red {color: #f00;}"+
				"#harpocrates_logout_time {margin-right: 4px;}"
			);
			if(GM_getValue("new_login","false") === "true") {
				localStorage.harpocrates_login_timestamp = GM_getValue("login_timestamp",0);
				GM_setValue("new_login","false");
			}
			$("span.header_links").append(
				$("<br/>"),
				$("<b/>")
					.attr({
						"id":"harpocrates_logout_time",
						"title":("You logged into Mechanical Turk on "+olympus.utilities.datetime.output(this.__stamp(),"d M \\a\\t H:i")+".\n\n"+
								 "The cookie for Mechanical Turk expires after 12 hours, which means you will be required to login again when this timer reaches zero.")
					})
			);
			this.update();
		}
	},
	update:function() {
		var stamp = olympus.harpocrates.__stamp();
		if(stamp > 0) {
			var time_left = ((olympus.harpocrates.__12_hrs-(Date.now()-stamp))/1000);
			$("#harpocrates_logout_time")
				.attr("class",((time_left <= 3600 ? " red" : "")+(time_left <= 1800 ? " anim_pulse" : "")))
				.text("Time to logout: "+(time_left <= 300 ? "any moment" : olympus.utilities.dhms(time_left)));
		}
		else $("#harpocrates_logout_time")
			.removeClass("red anim_pulse")
			.attr("title","")
			.text("");
		setTimeout(olympus.harpocrates.update,60000);
	}
};