player 发表于 2022-7-27 21:57:24

怎么写可以在再次刷新时获取已经保存的GM_getValue

const arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g'];

GM_setValue("keyWord", arr);


const myKeyWord = arr => {

    arr = GM_getValue("keyWord");

    if (Array.isArray(arr)) {

      arr = [...new Set(arr)];

      const prompt = window.prompt("输入关键字");

      if (prompt != null && prompt != "") {

            if (arr.includes(prompt)) {

                window.confirm(`【${prompt}】已经存在`);

            } else {

                arr.push(prompt);
                GM_setValue("keyWord", arr);

                window.confirm(arr);

                console.log(arr);
            }
      }

    }

}

steven026 发表于 2022-7-27 22:15:41

```
// ==UserScript==
// @name         New Userscript
// @version      1.0
// @descriptiontry to take over the world!
// @match      https://bbs.tampermonkey.net.cn/
// @grant      GM_setValue
// @grant      GM_getValue
// ==/UserScript==

const myKeyWord = () => {
        let arr = GM_getValue("keyWord", ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c', 'd', 'e', 'f', 'g']);
        if(Array.isArray(arr)) {
                arr = [...new Set(arr)];
                const prompt = window.prompt("输入关键字");
                if(prompt != null && prompt != "") {
                        if(arr.includes(prompt)) {
                                window.confirm(`【${prompt}】已经存在`);
                        } else {
                                arr.push(prompt);
                                GM_setValue("keyWord", arr);
                                window.confirm(arr);
                                console.log(arr);
                        }
                }
        }
}
myKeyWord();
```
这样?没太看懂

李恒道 发表于 2022-7-27 22:29:23

steven026 发表于 2022-7-27 22:15
```
// ==UserScript==
// @name         New Userscript

哥哥好热心!
点赞!
(不会用评分
只能言语鼓励了

幸识 发表于 2022-7-27 22:51:27

李恒道 发表于 2022-7-27 22:29
哥哥好热心!
点赞!
(不会用评分


我也要像哥哥一样做一个水贴达人

steven026 发表于 2022-7-27 23:06:23

李恒道 发表于 2022-7-27 22:29
哥哥好热心!
点赞!
(不会用评分


我也想成为像哥哥一样这么热(da)心(shui)肠(bi)的人😄

cxxjackie 发表于 2022-7-27 23:14:46

myKeyWord是个函数,你光定义了函数却没有调用它。

王一之 发表于 2022-7-28 09:36:47

@cxxjackie @李恒道 原来开发者不能评分么。。。我一直不知道,我现在去修改一下配置。。。。
页: [1]
查看完整版本: 怎么写可以在再次刷新时获取已经保存的GM_getValue