Moomoo.io New cyan color

Adds a new cyan color to the color selection panel

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name Moomoo.io New cyan color
// @author Murka
// @description Adds a new cyan color to the color selection panel
// @icon https://moomoo.io/img/favicon.png?v=1
// @version 0.3
// @match *://moomoo.io/*
// @match *://*.moomoo.io/*
// @run-at document-start
// @grant none
// @license MIT
// @namespace https://greasyfork.org/users/919633
// ==/UserScript==
/* jshint esversion:6 */

/*
    Author: Murka
    Github: https://github.com/Murka007
    Discord: https://discord.gg/cPRFdcZkeD
    Greasyfork: https://greasyfork.org/en/users/919633
    MooMooForge: https://github.com/MooMooForge
*/

(function() {
    "use strict";

    const log = console.log;
    const storage = {
        get(key) {
            const value = localStorage.getItem(key);
            return value === null ? null : value;
        },
        set(key, value) {
            localStorage.setItem(key, typeof value !== "string" ? JSON.stringify(value) : value);
        }
    };

    // Unlock 100 resource bonus
    storage.set("moofoll", 1);

    function createHook(target, prop, setter) {
        const symbol = Symbol(prop);
        Object.defineProperty(target, prop, {
            get() {
                return this[symbol];
            },
            set(value) {
                setter(this, symbol, value);
            },
            configurable: true
        })
    }

    // Add cyan color to the skinColor array
    createHook(Object.prototype, "skinColors", function(that, symbol, value) {
        delete Object.prototype.skinColors;
        that.skinColors = [...value, "#91B2DB"];
    })

    // When choosing a color, replace index with "toString", so server will cause some error that will make your color cyan
    createHook(window, "selectSkinColor", function(that, symbol, value) {
        delete window.selectSkinColor;
        window.selectSkinColor = new Proxy(value, {
            apply(target, _this, args) {
                const [ skin ] = args;
                target.call(_this, skin === 10 ? "toString" : skin);

                storage.set("skinColor", skin);
                if (skin === 10) {
                    const skins = document.querySelectorAll("#skinColorHolder > *");
                    const last = skins[skins.length-1];
                    last.classList.add("activeSkin");
                }
            }
        })
    })

    // Select saved color on the load
    window.addEventListener("load", function() {
        const observer = new MutationObserver(mutations => {
            observer.disconnect();
            for (const mutation of mutations) {
                const index = storage.get("skinColor") || 0;
                mutation.addedNodes[index].click();
            }
        })
        observer.observe(document.querySelector("#skinColorHolder"), { childList: true, subtree: true });
    })

})();