DH3 Tick Pulse

Pulses each tick to aid in counting various things (e.g. shark bite).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         DH3 Tick Pulse
// @namespace    com.anwinity.dh3
// @version      1.2.5
// @description  Pulses each tick to aid in counting various things (e.g. shark bite).
// @author       Anwinity
// @match        dh3.diamondhunt.co
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const PULSE_DURATION = 500;
    const KEY_TOP = "dh3-tick-pulse-top";
    const KEY_LEFT = "dh3-tick-pulse-left";

    function init() {
        if(!window.var_username) {
            setTimeout(init, 1000);
            return;
        }

        let animationStart = Date.now();

        let fontAwesome = document.createElement("script");
        fontAwesome.src = "https://kit.fontawesome.com/044e12ee28.js"
        fontAwesome.crossorigin = "anonymous";
        fontAwesome.type = "text/javascript";
        $("head").append(fontAwesome);

        let top = localStorage.getItem(KEY_TOP);
        let left = localStorage.getItem(KEY_LEFT);

        const styles = document.createElement("style");
        styles.textContent = `
          #dh3-tick-pulse {
            min-width: 50px;
            min-height: 50px;
            position: absolute;
            left: ${left}px;
            top: ${top}px;
            z-index: 9999;
            padding: 0.25em;
            border: 1px solid rgb(64, 64, 64);
            border-radius: 2px;
            background-color: rgb(26, 26, 26);
            padding: 0px;
            margin: 0px;
          }
          #dh3-tick-pulse-circle-container {
            width: 40px;
            height: 40px;
          }
          #dh3-tick-pulse.collapsed > #dh3-tick-pulse-circle-container {
            display: none;
          }
          #dh3-tick-pulse-circle-container > .circle {
            width: 0px;
            height: 0px;
            margin-top: 0px;
            margin-left: 0px;
            -webkit-border-radius: 20px;
            -moz-border-radius: 20px;
            border-radius: 20px;
            background: rgb(42, 200, 200);
            opacity: 1;
            position: absolute;
            top: calc(20px + 0.25em);
            left: 50%;
          }
          #dh3-tick-pulse-animation-info {
            padding: 0.25em;
            text-align: center;
            font-size: 18pt;
          }

        `;
        $("head").append(styles);

        $("body").prepend(`
          <div id="dh3-tick-pulse">
            <div id="dh3-tick-pulse-circle-container"></div>
            <div id="dh3-tick-pulse-animation-info"></div>
          </div>
        `);

        let el = $("#dh3-tick-pulse");
        el.draggable({
            appendTo: "body",
            containment: "document",
            cursor: "pointer"
        });
        el.on("dragstop", function(event, ui) {
            localStorage.setItem(KEY_TOP, ui.position.top);
            localStorage.setItem(KEY_LEFT, ui.position.left);
        });

        function pulse() {
            let container = $("#dh3-tick-pulse-circle-container");
            let circle = $('<div class="circle"></div>');
            circle.animate({
                "width": "40px",
                "height": "40px",
                "margin-top": "-20px",
                "margin-left": "-20px",
                "opacity": 0
            }, PULSE_DURATION, "swing");
            container.append(circle);
            setTimeout(function() {
                circle.remove();
            }, PULSE_DURATION);
        };

        setInterval(function() {
            let monsterObj = window[`${var_monsterName}MonsterObj`];
            if(monsterObj) {
                let animation = monsterObj.currentAnimation;
                let delta = Date.now() - animationStart;
                let info = `${animation.name}: ${Math.floor(delta/1000)}`;
                $("#dh3-tick-pulse-animation-info").text(info);
            }
        }, 100);

        const originalSetItems = window.setItems;
        window.setItems = function(data) {
            originalSetItems.apply(this, arguments);
            const hideOrShow = function() {
                let el = $("#dh3-tick-pulse");
                if(el.is(":hidden") && window.var_monsterName != "none") {
                    el.show();
                }
                else if(el.is(":visible") && window.var_monsterName == "none") {
                    el.hide();
                }
            };
            hideOrShow();
            setTimeout(hideOrShow, 1500);

            if(data && data.includes("playtime~")) {
                try {
                    pulse();
                }
                catch(err) {
                    console.log("DH3 TICK PULSE - Error occurred on pulse()", err);
                }
            }

        }

        const originalStartMonsterAnimation = window.startMonsterAnimation;
        window.startMonsterAnimation = function() {
            originalStartMonsterAnimation.apply(this, arguments);
            animationStart = Date.now();
        }
    }

    $(init);
})();