The Ultimate Ratio Script (time, score/min, projected times for milestones based on current ratio)

Uses time from your computer to calculate your ratio and expected time to get milestones based on that

Pada tanggal 30 April 2021. Lihat %(latest_version_link).

// ==UserScript==
// @name         The Ultimate Ratio Script (time, score/min, projected times for milestones based on current ratio)
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Uses time from your computer to calculate your ratio and expected time to get milestones based on that
// @author       MrCheese#1337
// @match        https://diep.io/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    //Add text to screen
    const GUI1 = document.createElement("div");
    const GUI2 = document.createElement("div");
    const GUI3 = document.createElement("div");
    const GUI4 = document.createElement("div");
    const GUI5 = document.createElement("div");
    const GUI6 = document.createElement("div");
    GUI1.style = `pointer-events: none; position: fixed; bottom:357px; right:15px; font-family: Ubuntu; color: #FFFFFF; font-style: normal; font-size: 33px;  text-shadow: black 2px 0px, black -2px 0px, black 0px -2px, black 0px 2px, black 2px 2px, black -2px 2px, black 2px -2px, black -2px -2px, black 1px 2px, black -1px 2px, black 1px -2px, black -1px -2px, black 2px 1px, black -2px 1px, black 2px -1px, black -2px -1px;`;
    GUI2.style = `pointer-events: none; position: fixed; bottom:335px; right:15px; font-family: Ubuntu; color: #FFFFFF; font-style: normal; font-size: 20px;  text-shadow: black 2px 0px, black -2px 0px, black 0px -2px, black 0px 2px, black 2px 2px, black -2px 2px, black 2px -2px, black -2px -2px, black 1px 2px, black -1px 2px, black 1px -2px, black -1px -2px, black 2px 1px, black -2px 1px, black 2px -1px, black -2px -1px;`;
    GUI3.style = `pointer-events: none; position: fixed; bottom:313px; right:15px; font-family: Ubuntu; color: #FFFFFF; font-style: normal; font-size: 20px;  text-shadow: black 2px 0px, black -2px 0px, black 0px -2px, black 0px 2px, black 2px 2px, black -2px 2px, black 2px -2px, black -2px -2px, black 1px 2px, black -1px 2px, black 1px -2px, black -1px -2px, black 2px 1px, black -2px 1px, black 2px -1px, black -2px -1px;`;
    GUI4.style = `pointer-events: none; position: fixed; bottom:291px; right:15px; font-family: Ubuntu; color: #FFFFFF; font-style: normal; font-size: 20px;  text-shadow: black 2px 0px, black -2px 0px, black 0px -2px, black 0px 2px, black 2px 2px, black -2px 2px, black 2px -2px, black -2px -2px, black 1px 2px, black -1px 2px, black 1px -2px, black -1px -2px, black 2px 1px, black -2px 1px, black 2px -1px, black -2px -1px;`;
    GUI5.style = `pointer-events: none; position: fixed; bottom:269px; right:15px; font-family: Ubuntu; color: #FFFFFF; font-style: normal; font-size: 20px;  text-shadow: black 2px 0px, black -2px 0px, black 0px -2px, black 0px 2px, black 2px 2px, black -2px 2px, black 2px -2px, black -2px -2px, black 1px 2px, black -1px 2px, black 1px -2px, black -1px -2px, black 2px 1px, black -2px 1px, black 2px -1px, black -2px -1px;`;
    GUI6.style = `pointer-events: none; position: fixed; bottom:247px; right:15px; font-family: Ubuntu; color: #FFFFFF; font-style: normal; font-size: 20px;  text-shadow: black 2px 0px, black -2px 0px, black 0px -2px, black 0px 2px, black 2px 2px, black -2px 2px, black 2px -2px, black -2px -2px, black 1px 2px, black -1px 2px, black 1px -2px, black -1px -2px, black 2px 1px, black -2px 1px, black 2px -1px, black -2px -1px;`;
    document.body.appendChild(GUI1);
    document.body.appendChild(GUI2);
    document.body.appendChild(GUI3);
    document.body.appendChild(GUI4);
    document.body.appendChild(GUI5);
    document.body.appendChild(GUI6);
    GUI1.innerHTML = ' 00:00:00';
    resetTimes();

    //Set vaiables
    var curTime = '00:00:00';
    var rawTime = 0;
    var ratio = 0;
    var rawRatio = 0;

    //Reset times at the start of each round
    function resetTimes() {
        GUI2.innerHTML = '100k 00:00:00';
        GUI3.innerHTML = '500k 00:00:00';
        GUI4.innerHTML = '1.0m 00:00:00';
        GUI5.innerHTML = '2.0m 00:00:00';
        GUI6.innerHTML = '0/min';
    }

    //Get current score (by ABC)
    let _rScore = "0";
    CanvasRenderingContext2D.prototype.fillText = new Proxy(CanvasRenderingContext2D.prototype.fillText, {
        apply(fillRect, ctx, [text, x, y, ...blah]) {

            if (text.startsWith('Score: ')) _rScore = text

            fillRect.call(ctx, text, x, y, ...blah);
        }
    });

    const getScore = () => {
        if (!input.should_prevent_unload()) return -1;
        return parseFloat(_rScore.slice(7).replace(/,/g, ''));
    }

    //Parse time for projected score times
    function timeParse(score) {
        let time = (score / rawRatio) * 60;
        let hours = 0;
        let minutes = 0;
        let seconds = 0;

        if (time >= 3600) {
            hours = Math.round(time / 3600 - 0.5);
            time -= hours * 3600;
            if (hours < 10) hours = '0' + hours;
        } else hours = '00';

        if (time >= 60) {
            minutes = Math.round(time / 60 - 0.5);
            time -= minutes * 60;
            if (minutes < 10) minutes = '0' + minutes;
        } else minutes = '00';

        if (time !== 0) {
            seconds = Math.round(time);
            if (seconds < 10) seconds = '0' + seconds;
        } else seconds = '00';

        let parsedTime = hours + ':' + minutes + ':' + seconds;
        return parsedTime;
    }

    //Main code (runs once a second)
    setInterval(() => {

        //Get time and display on main timer
        if (input.should_prevent_unload() && GUI1.innerHTML == ' 00:00:00') {
            GUI1.innerHTML = `${curTime}`;
        } else if (input.should_prevent_unload()) {
            let [hours, minutes, seconds] = curTime.split(':');
            if (parseInt(seconds) + 1 !== 60) {
                let addZero = (parseInt(seconds) + 1).toString().length == 1 ? '0' : '';
                seconds = `${addZero}${parseInt(seconds) + 1}`;
                rawTime += 1;
            } else {
                if (parseInt(minutes) + 1 !== 60) {
                    let addZero = (parseInt(minutes) + 1).toString().length == 1 ? '0' : '';
                    seconds = '00';
                    minutes = `${addZero}${parseInt(minutes) + 1}`;
                } else {
                    let addZero = (parseInt(hours) + 1).toString().length == 1 ? '0' : '';
                    seconds = '00';
                    minutes = '00';
                    hours = `${addZero}${parseInt(hours) + 1}`;
                }
            }

            curTime = `${hours}:${minutes}:${seconds}`;
            GUI1.innerHTML = `${curTime}`;
        } else if (!input.should_prevent_unload()) {
            GUI1.innerHTML = ' 00:00:00';
            curTime = '00:00:00';
            rawTime = 0;
        }

        //Check if score is 0
        if (getScore() !== -1) {
            if (getScore() == 0) resetTimes()
            else {
                //Display projected score times
                if (getScore() <= 100000) GUI2.innerHTML = '100k ' + timeParse(100000);
                if (getScore() <= 500000) GUI3.innerHTML = '500k ' + timeParse(500000);
                if (getScore() <= 1000000) GUI4.innerHTML = '1.0m ' + timeParse(1000000);
                if (getScore() <= 2000000) GUI5.innerHTML = '2.0m ' + timeParse(2000000);

                //Calculate and display ratio
                if (rawTime != 0) ratio = getScore() / (rawTime / 60);
                    else ratio = 0;
                    rawRatio = ratio;

                if (ratio >= 1000000) {
                    ratio /= 1000000;
                    ratio = ratio.toFixed(2);
                    ratio = ratio + 'm';
                } else if (ratio >= 1000) {
                    ratio /= 1000;
                    ratio = ratio.toFixed(2);
                    ratio = ratio + 'k';
                } else ratio = Math.round(ratio);

                GUI6.innerHTML = ratio + '/min';
            }
        }
    }, 1000);
})();