IB Lineage Emoji Generator

Adds option to add emojis automatically

当前为 2025-01-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         IB Lineage Emoji Generator
// @namespace    http://tampermonkey.net/
// @version      1.1
// @license      MIT
// @description  Adds option to add emojis automatically
// @icon         https://i.imgur.com/WlkWOkU.png
// @author       @activetutorial on discord
// @match        https://infinibrowser.wiki/tools/lineage-maker
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    (window.AT ||= {}).lineageemojis = {
        mappings: null,
        buttons: {
            setEmojisButton: {
                id: "set-emojis",
                className: "btn",
                textContent: "Set Emojis"
            },
            resetEmojisButton: {
                id: "reset-emojis",
                className: "btn",
                textContent: "Reset Emojis"
            }
        },
        createButtons: function() {
            this.setEmojisButton = document.createElement("button");
            Object.assign(this.setEmojisButton, this.buttons.setEmojisButton);

            this.resetEmojisButton = document.createElement("button");
            Object.assign(this.resetEmojisButton, this.buttons.resetEmojisButton);

            const btnElement = document.querySelectorAll(".btn")[1];
            btnElement.parentElement.appendChild(this.setEmojisButton);
            btnElement.parentElement.appendChild(document.createTextNode(" "));
            btnElement.parentElement.appendChild(this.resetEmojisButton);
        },
        setEmojis: async function() {
            [...document.querySelector(".recipes").children].forEach(i => {
                [...i.children].slice(0, -1).forEach(async j => {
                    if (j.firstChild.innerHTML == "⬜") {
                        const response = await fetch("https://infinibrowser.wiki/api/item?id=" + encodeURIComponent(j.childNodes[1].textContent));
                        const data = await response.json();
                        this.mappings.set(data.text, data.emoji);
                        j.firstChild.innerHTML = (data.emoji || "⬜");
                    }
                });
            });
        },
        resetEmojis: function() {
            [...document.querySelector(".recipes").children].forEach(i => {
                [...i.children].slice(0, -1).forEach(j => {
                    this.mappings.set(j.childNodes[1].textContent, "⬜");
                    j.firstChild.innerHTML = "⬜";
                });
            });
        },
        start: function () {
            if (document.querySelector('.btn')) {
                this.createButtons();
                this.setEmojisButton.addEventListener("click", this.setEmojis.bind(this));
                this.resetEmojisButton.addEventListener("click", this.resetEmojis.bind(this));

                const originalGet = Map.prototype.get;
                Map.prototype.get = function(key) {
                    window.AT.lineageemojis.mappings = this;
                    return originalGet.call(this, key);
                };
            } else {
                setTimeout(this.start.bind(this), 200);
            }
        }
    };

    window.AT.lineageemojis.start();
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址