Primedice 3 Faucet Timer

(Hide using Ctrl + Alt + Z)

当前为 2015-04-02 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Primedice 3 Faucet Timer
// @namespace    http://primedice.com
// @version      0.2
// @description  (Hide using Ctrl + Alt + Z)
// @author       Serlite
// @match        https://primedice.com/*
// @grant        none
// ==/UserScript==
/*
//	PD3 Faucet Timer
//	Created by Serlite, Uploaded to Greasy Fork by energ1zer
//
//	(Hide using Ctrl + Alt + Z)
*/

var sinceLastClaim = 0;
var $fTimer = null;
var $fTimerWrapper = null;
var fIntervalRef = null;
var fTimerHider = {17: false, 18: false, 90:false};

initializeTimer();

// Creates GUI and begins timer countdown
function initializeTimer(){

	if (!window.jQuery.ui){
		$("body").append("<script src='//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.js'></script>");
	}

	// Delay to allow jQuery UI to load
	setTimeout(function(){
		$("body").append("<div class='faucet-timer' style='background:#FFF; border:2px solid #b4b9cd; position:fixed; z-index:9999; top:100px; left:200px; color:#6d738c; padding:15px; font-size:1em'><p style='margin-bottom:10px;'>Since last claim:</p><p><span class='time-counter' style='font-weight:bold;'>00:00</span></p></div>");

		// Caching reference
		$fTimer = $(".faucet-timer .time-counter");
		$fTimerWrapper = $(".faucet-timer");
		$fTimerWrapper.draggable();

		fIntervalRef = setInterval(updateFaucetTime, 1000);

		// Reset timer if claim button is pressed
		$(document).on("click", "button.btn.btn--primary.btn--huge.btn--block", function(){
			if ($(this).text() == "Claim"){
				sinceLastClaim = 0;
				writeFaucetTime(formattedFaucetTime());
				setTimerCol();

				// Reset interval ensure precision
				clearInterval(fIntervalRef);
				fIntervalRef = setInterval(updateFaucetTime, 1000);
			}
		});

		// Register key down in combo
		$(document).keydown(function(e){
			if (e.keyCode in fTimerHider){
				fTimerHider[e.keyCode] = true;

				// Ctrl + Alt + Z, toggle visible
				if (fTimerHider[17] && fTimerHider[18] && fTimerHider[90]){
					$fTimerWrapper.toggle();
				}
			}
		});

		// Register key up in combo
		$(document).keyup(function(e){
			if (e.keyCode in fTimerHider){
				fTimerHider[e.keyCode] = false;
			}
		});

	}, 1500);
}

// Increment timer value
function updateFaucetTime(){
	sinceLastClaim++;
	writeFaucetTime(formattedFaucetTime());
	setTimerCol();
}

// Format time into more readable string
function formattedFaucetTime(){
	var minutes = Math.floor(sinceLastClaim/60).toString();
	var seconds = (sinceLastClaim%60).toString();

	// Adding leading zeroes
	if (minutes.length == 1){
		minutes = "0" + minutes;
	}
	if (seconds.length == 1){
		seconds = "0" + seconds;
	}

	return (minutes + ":" + seconds);
}

// Change timer text
function writeFaucetTime(faucetTime){
	$fTimer.text(faucetTime);
}

// Change colour according to time
function setTimerCol(){
	if (sinceLastClaim >= 180){
		$fTimer.css("color","#5fb365");
	}
	else{
		$fTimer.css("color","#6d738c");
	}
}