IdlePixel Crit Tracker

Adds functionality to the combat window to show which hit you are on in your crit cycle.

// ==UserScript==
// @name         IdlePixel Crit Tracker
// @namespace    com.godofnades.idlepixel
// @version      1.1.1
// @description  Adds functionality to the combat window to show which hit you are on in your crit cycle.
// @author       GodofNades
// @license      MIT
// @match        *://idle-pixel.com/login/play*
// @grant        none
// @require      https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js?anticache=20220905
// ==/UserScript==

(function() {
    'use strict';

    var combatActive = false;
    var i = 0;

    class CritTrackerPlugin extends IdlePixelPlusPlugin {
        constructor() {
            super("crittracker", {
                about: {
                    name: GM_info.script.name + " (ver: " + GM_info.script.version + ")",
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                }
            });
        }

        onCombatStart() {
            combatActive = true;
        }

        onCombatEnd() {
            combatActive = false;
            i = 0;
        }

        onMessageReceived(data) {
            if(combatActive && data.startsWith("HITSPLAT_ON_MONSTER=") && !data.includes("heal_spell.png") && !data.includes("fire_icon.png") && !data.includes("poison.png") && !data.includes("reflect_spell.png") && !data.includes("cannonball.png")) {
                console.log(data);
                if(i == 3){
                    i++
                    $("#crit-text").text("4 - Crit Next");
                    $("#crit-box").css("background-color", "yellow");
                    $("#crit-text-static").css("color", "black");
                    $("#crit-text").css("color", "black");
                    $("#crit-text-static").css("font-weight", "bold");
                    $("#crit-text").css("font-weight", "bold");
                } else if(i == 4) {
                    i = 0;
                    $("#crit-text").text("5 - Crit");
                    $("#crit-box").css("background-color", "green");
                    $("#crit-text-static").css("color", "white");
                    $("#crit-text").css("color", "white");
                    $("#crit-text-static").css("font-weight", "bold");
                    $("#crit-text").css("font-weight", "bold");
                } else if(data.includes("rgba(255,128,0,0.6)")) {
                    i = 0;
                    $("#crit-text").text("5 - Crit");
                    $("#crit-box").css("background-color", "green");
                    $("#crit-text-static").css("color", "white");
                    $("#crit-text").css("color", "white");
                    $("#crit-text-static").css("font-weight", "bold");
                    $("#crit-text").css("font-weight", "bold");
                } else {
                    i++;
                    $("#crit-text").text(i);
                    $("#crit-box").css("background-color", "red");
                    $("#crit-text-static").css("color", "black");
                    $("#crit-text").css("color", "black");
                    $("#crit-text-static").css("font-weight", "bold");
                    $("#crit-text").css("font-weight", "bold");
                }
            }
        }

        onLogin() {
            $("#panel-combat-canvas > button").after(`
              <div id="crit-box" class="notification" style="margin-left: 400px; margin-bottom: 4px; display: inline-block; background-color: red;">
                <span id="crit-text-static" class="color-white">Hit Count: </span>
                <span id="crit-text" class="color-white">1</span>
              </div>`)
        }
    }

    const plugin = new CritTrackerPlugin();
    IdlePixelPlus.registerPlugin(plugin);

})();