GM_config 开源项目教程

GM_config 开源项目教程

GM_configA lightweight, reusable, cross-browser graphical settings framework for inclusion in user scripts.项目地址:https://gitcode.com/gh_mirrors/gm/GM_config

1. 项目的目录结构及介绍

GM_config 是一个轻量级的跨浏览器图形设置框架,用于用户脚本中。项目的目录结构如下:

GM_config/
├── LICENSE
├── README.md
├── gm_config.ico
├── gm_config.js
├── gm_config_icon.png
├── gm_config_icon_large.png
└── types/
    └── ...
  • LICENSE:项目遵循的 LGPL-3.0 许可证。
  • README.md:项目的介绍和使用说明。
  • gm_config.icogm_config_icon.png:项目的图标文件。
  • gm_config.js:项目的主要脚本文件。
  • gm_config_icon_large.png:项目的大图标文件。
  • types/:TypeScript 类型定义文件目录。

2. 项目的启动文件介绍

项目的启动文件是 gm_config.js。这个文件包含了 GM_config 框架的核心功能,允许用户在用户脚本中创建和使用图形设置对话框。

// @require https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant GM_getValue
// @grant GM_setValue

在用户脚本中,通过 @require 指令引入 gm_config.js 文件,并使用 @grant 指令授权 GM_getValueGM_setValue 权限。

3. 项目的配置文件介绍

GM_config 项目本身没有传统的配置文件,但可以通过在用户脚本中定义配置项来实现自定义配置。配置项通常在用户脚本的元数据块中定义,例如:

// ==UserScript==
// @name         Example Script
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://example.com/*
// @require      https://openuserjs.org/src/libs/sizzle/GM_config.js
// @grant        GM_getValue
// @grant        GM_setValue
// ==/UserScript==

(function() {
    'use strict';

    // Initialize GM_config
    GM_config.init({
        id: 'example_config',
        fields: {
            exampleField: {
                label: 'Example Field',
                type: 'text',
                default: 'Default Value'
            }
        }
    });

    // Use GM_config
    console.log(GM_config.get('exampleField'));
})();

在这个示例中,GM_config.init 方法用于初始化配置,定义了一个名为 exampleField 的字段,并设置了默认值。通过 GM_config.get 方法可以获取配置项的值。

GM_configA lightweight, reusable, cross-browser graphical settings framework for inclusion in user scripts.项目地址:https://gitcode.com/gh_mirrors/gm/GM_config

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

郁铎舒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值