🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

gm-import-export

Helper functions for importing and exporting stored values.

Ovu skriptu ne treba izravno instalirati. To je biblioteka za druge skripte koje se uključuju u meta direktivu // @require https://update.greasyfork.org/scripts/487244/1326878/gm-import-export.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name               gm-import-export
// @description        Helper functions for importing and exporting stored values.
// @author             Jason Kwok
// @namespace          https://jasonhk.dev/
// @version            1.0.0
// @license            MIT
// ==/UserScript==

function GM_importValues(values, cleanImport = false)
{
    if (cleanImport)
    {
        for (const key of GM_listValues())
        {
            GM_deleteValue(key);
        }
    }

    for (const key of Object.keys(values))
    {
        GM_setValue(key, values[key]);
    }
}

function GM_exportValues()
{
    const values = {};
    for (const key of GM_listValues())
    {
        values[key] = GM_getValue(key);
    }

    return values;
}

GM.importValues = async function importValues(values, cleanImport = false)
{
    if (cleanImport)
    {
        const promises = [];
        for (const key of await GM.listValues())
        {
            promises.push(GM.deleteValue(key));
        }

        await Promise.all(promises);
    }

    const promises = [];
    for (const key of Object.keys(values))
    {
        promises.push(GM.setValue(key, values[key]));
    }

    await Promise.all(promises);
}

GM.exportValues = async function exportValues()
{
    const keys = await GM.listValues();

    const promises = [];
    for (const key of keys)
    {
        promises.push(GM.getValue(key));
    }

    const values = await Promise.all(promises);
    return Object.fromEntries(keys.map((key, i) => [key, values[i]]));
}