IdlePixelPlus Config Backup

Creates a panel for backing up IP+ Configs

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         IdlePixelPlus Config Backup
// @namespace    lbtechnology.info
// @version      1.1.0
// @description  Creates a panel for backing up IP+ Configs
// @author       Lux-Ferre
// @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';
 
    class IPPBackupPlugin extends IdlePixelPlusPlugin {
        constructor() {
            super("IPPBackup", {
                about: {
                    name: GM_info.script.name,
                    version: GM_info.script.version,
                    author: GM_info.script.author,
                    description: GM_info.script.description
                }
            });
            this.previous = "";
        }

        createPanel(){
            IdlePixelPlus.addPanel("ippbackup", "Backup/Restore Panel", function() {
                let content = `<div>`
                    content += `<br/>`
                    IdlePixelPlus.forEachPlugin(plugin=>{
                        const id = plugin.id
                        content += `<div>`
                            content += `<label for='${id}_text'><p style="-webkit-text-stroke:1px cadetblue;">${id}:&nbsp&nbsp</p></label>`
                            content += `<input id="${id}_text" type="text" style="width: 90%; float:right" readonly>`
                        content += `</div>`
                    })

                    content += `<input type="button" value="Load All" onClick="IdlePixelPlus.plugins.IPPBackup.loadAll()" id="load_all_button">`
                    content += `<input type="button" value="Restore" onClick="IdlePixelPlus.plugins.IPPBackup.restoreAll()" id="restore_all_button">`
                content += `</div>`
                content += `<div>`
                    content += `<label for='allConfigs'><p style="-webkit-text-stroke:1px cadetblue;">All Configs:&nbsp&nbsp</p></label>`
                    content += `<input id="allConfigs" type="text" style="width: 90%; float:right" readonly>`
                content += `</div>`
                return content
            });
        }

        loadAll(){
            var data = {}
            IdlePixelPlus.forEachPlugin(plugin=>{
                var sub_data = {}
                const id = plugin.id
                const plugin_textbox = `#${id}_text`
                let stored = localStorage.getItem(`idlepixelplus.${id}.config`);
                if (stored == null){
                    sub_data = "";
                }
                else {
                    sub_data[id] = stored
                    data[id] = stored;
                }
                $(plugin_textbox).val(JSON.stringify(sub_data))
            })

            const allConfigs = $("#allConfigs")
            allConfigs.val(JSON.stringify(data))
        }

        restoreAll(){
            var data = {}
            const raw_input = prompt("Paste backup here:")

            if (raw_input == null){return;}

            const config_obj = JSON.parse(raw_input)

            for (const [key, value] of Object.entries(config_obj)) {
                localStorage.setItem(`idlepixelplus.${key}.config`, value);
            }
        }

        onLogin(){
            this.createPanel()
            const lastMenuItem = $("#menu-bar-buttons > .hover-menu-bar-item").last();
            lastMenuItem.after(`
                <div onclick="IdlePixelPlus.setPanel('ippbackup')" class="hover hover-menu-bar-item">
                    <p>💾 PLUGIN BACKUP</p>
                </div>
            `)
        }
     }
    
    const plugin = new IPPBackupPlugin();
    IdlePixelPlus.registerPlugin(plugin);
 
})();