Dropchance Combat

Adds dropchance

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Dropchance Combat
// @namespace    com.anwinity.idlepixel.sample
// @version      1.0.1
// @description  Adds dropchance
// @author       LordHC
// @license      MIT
// @match        *://idle-pixel.com/login/play*
// @grant        none
// @require https://greasyfork.org/scripts/441206-idlepixel/code/IdlePixel+.js
// ==/UserScript==
(function() {
    'use strict';

    class dropChanceCombat extends IdlePixelPlusPlugin {
        constructor() {
            super("dropChanceCombat", { // unique plugin id, "sample"
                about: { // optional, but highly recommended
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                }
            });
        }


        onMessageReceived(data) {
            if (data.startsWith("COMBAT_LOG=")) {
                // Removes all charachters except numbers
                function removeText(text) {
                    var num = text.replace(/[^0-9]/g, '');
                    return num;
                }
                // Checking if the its a string and not undefined
                function checking(string) {
                    if (string) {
                        return removeText(string.innerHTML);
                    }
                }
                // Adding % of chance of item
                var calculatePrecentage = function(drops, kills) {
                    var num = Math.round(drops / kills * 100 * 100) / 100;
                    if (num > 100) {
                        if (num > 999) {
                            const firstTwoNumbers = String(num).substring(0, 2);
                            const dottedNum = firstTwoNumbers.slice(0, 2) + "." + firstTwoNumbers.slice(1, 2);
                            return dottedNum + "x";
                        } else {
                            const firstTwoNumbers = String(num).substring(0, 2);
                            const dottedNum = firstTwoNumbers.slice(0, 1) + "." + firstTwoNumbers.slice(1, 2);
                            return dottedNum + "x";
                        }
                    }
                    return num + "%"
                };

                function addingMonsterDropAverage() {
                    const monsters = $("[id^='combat-log-table-']").toArray().map(el => el.getAttribute("id"));
                    // Adds the precentage on every item
                    monsters.forEach(createPrecentageItem);

                    function createPrecentageItem(item) {
                        var idCombatLogMonster = document.getElementById(item).childNodes[0]
                        var monsterKills = removeText(document.getElementById(item).childNodes[0].rows[0].childNodes[3].innerHTML);

                        for (var i = 2, row; row = idCombatLogMonster.rows[i]; i++) {
                            //iterate through rows
                            var combatLogMonsterRow = row.childNodes[2];
                            var dropsHTML = row.childNodes[3].childNodes[3]
                            var dropsRaw = checking(dropsHTML);
                            var drops = (dropsRaw = dropsRaw ?? "0");

                            var dateSpan = document.createElement('span')
                            var br = document.createElement("br");
                            dateSpan.innerHTML = calculatePrecentage(drops, monsterKills);
                            dateSpan.className = "color-grey font-small";
                            combatLogMonsterRow.appendChild(br);
                            var br2 = br.cloneNode(true);
                            combatLogMonsterRow.appendChild(br2);
                            combatLogMonsterRow.appendChild(dateSpan);
                        }
                    }

                }
                addingMonsterDropAverage();




            }

        }



    }

    const plugin = new dropChanceCombat();
    IdlePixelPlus.registerPlugin(plugin); // register the plugin

})();