Primedice 3 Faucet Timer

Displays time since faucet claim button was last clicked, no more guessing when the timer is up!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name            Primedice 3 Faucet Timer
// @namespace       
// @description     Displays time since faucet claim button was last clicked, no more guessing when the timer is up!
// @include         *primedice.com*
// @exclude         
// @version         0.4
// @grant none
// @author Serlite
// ==/UserScript==

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");
	}
}