上一主题 下一主题
ScriptCat,新一代的脚本管理器脚本站,与全世界分享你的用户脚本油猴脚本开发指南教程目录
返回列表 发新帖
楼主: tansuo - 

zustand开发文档

[复制链接]
  • TA的每日心情
    开心
    2023-12-25 06:51
  • 签到天数: 35 天

    [LV.5]常住居民I

    9

    主题

    56

    回帖

    67

    积分

    初级工程师

    积分
    67

    油中3周年

    发表于 2023-10-29 11:29:30 | 显示全部楼层
    李恒道 发表于 2023-10-29 03:02
    只接受第一个middaren导致的
    你应该用错库了
    跟我上边说的第一个问题貌似是一个原理

    大神,库应该没错,我是研究这个脚本代码https://greasyfork.org/scripts/450169-weread-scraper/code/WeRead%20Scraper.user.js 里面就使用这两个库,但原理一直不明白,所以在论坛发了两个帖子来了解这两个库,头一个帖子,虽然运行没问题,但打印是什么内容不明白,而那个脚本确可以打印存储canvas上的内容,求大神继续指导
    回复
    订阅

    使用道具 举报

  • TA的每日心情
    开心
    2023-2-28 23:59
  • 签到天数: 191 天

    [LV.7]常住居民III

    637

    主题

    5202

    回帖

    6082

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6082

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2023-10-29 11:59:00 | 显示全部楼层
    tansuo 发表于 2023-10-29 11:29
    大神,库应该没错,我是研究这个脚本代码https://greasyfork.org/scripts/450169-weread-scraper/code/We ...

    这个已经被删除了
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2023-12-25 06:51
  • 签到天数: 35 天

    [LV.5]常住居民I

    9

    主题

    56

    回帖

    67

    积分

    初级工程师

    积分
    67

    油中3周年

    发表于 2023-10-29 12:26:33 | 显示全部楼层

    李恒道 发表于 2023-10-29 11:59

    这个已经被删除了

    不要在有油猴的浏览器打开,它会下载一个js,另外大神加我QQ2448640323,我发给你😊

    回复

    使用道具 举报

  • TA的每日心情
    开心
    2023-12-25 06:51
  • 签到天数: 35 天

    [LV.5]常住居民I

    9

    主题

    56

    回帖

    67

    积分

    初级工程师

    积分
    67

    油中3周年

    发表于 2023-10-29 17:24:44 | 显示全部楼层
    李恒道 发表于 2023-10-29 11:59
    这个已经被删除了


    大神下面是脚本代码 报如下错误Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'createStore')
    // ==UserScript==
    // @name         WeRead Scraper1
    // @namespace    https://github.com/Sec-ant/weread-scraper
    // @version      1.4.1
    // @author       Ze-Zheng Wu
    // @description  Scrape WeRead books and save them as HTML files
    // @license      MIT
    // @match        https://weread.qq.com/web/reader/*
    // @match        https://weread.qq.com/web/book/read*
    // @require      https://fastly.jsdelivr.net/npm/zustand@4.4.1/umd/vanilla.production.js
    // @require      https://fastly.jsdelivr.net/npm/zustand@4.4.1/umd/middleware.production.js
    // @run-at       document-start
    // ==/UserScript==
    (function () {
      const scraperSessionInitialState = {
        scraping: false,
        chapterLevelList: {}
      };

      const scraperSessionStore = this.zustandVanilla.createStore()(
        middleware.subscribeWithSelector(
          middleware.persist(() => scraperSessionInitialState, {
            name: "scraper-session-storage",
            storage: middleware.createJSONStorage(() => sessionStorage)
          })
        )
      );
      console.log(scraperSessionStore.getState().scraping);
      console.log(scraperSessionStore.getState().chapterLevelList);
    })();
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2023-2-28 23:59
  • 签到天数: 191 天

    [LV.7]常住居民III

    637

    主题

    5202

    回帖

    6082

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6082

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2023-10-29 17:55:02 | 显示全部楼层
    tansuo 发表于 2023-10-29 17:24
    大神下面是脚本代码 报如下错误Uncaught (in promise) TypeError: Cannot read properties of undefined ...

    删除iffe闭包函数
    善用debugger调试

    iffe会创建this作为新作用域
    而umd设置的是tampermonkey的this作用域

    标准的混淆作用域问题
    出现这种情况应该考虑补基础了...



    // ==UserScript==
    // @name         WeRead Scraper1
    // @namespace    https://github.com/Sec-ant/weread-scraper
    // @version      1.4.1
    // @author       Ze-Zheng Wu
    // @description  Scrape WeRead books and save them as HTML files
    // @license      MIT
    // @match        https://weread.qq.com/web/reader/*
    // @match        https://weread.qq.com/web/book/read*
    // @require      https://fastly.jsdelivr.net/npm/ ... nilla.production.js
    // @require      https://fastly.jsdelivr.net/npm/ ... eware.production.js
    // @run-at       document-start
    // ==/UserScript==

      const scraperSessionInitialState = {
        scraping: false,
        chapterLevelList: {}
      };

      const scraperSessionStore = this.zustandVanilla.createStore()(
        middleware.subscribeWithSelector(
          middleware.persist(() => scraperSessionInitialState, {
            name: "scraper-session-storage",
            storage: middleware.createJSONStorage(() => sessionStorage)
          })
        )
      );
      console.log(scraperSessionStore.getState().scraping);
      console.log(scraperSessionStore.getState().chapterLevelList);
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2023-2-28 23:59
  • 签到天数: 191 天

    [LV.7]常住居民III

    637

    主题

    5202

    回帖

    6082

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6082

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2023-10-29 17:56:12 | 显示全部楼层
    李恒道 发表于 2023-10-29 17:55
    删除iffe闭包函数
    善用debugger调试

    middleware也没改
    按前边说的umd改
    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2023-12-25 06:51
  • 签到天数: 35 天

    [LV.5]常住居民I

    9

    主题

    56

    回帖

    67

    积分

    初级工程师

    积分
    67

    油中3周年

    发表于 2023-10-29 18:18:51 | 显示全部楼层
    李恒道 发表于 2023-10-28 15:52
    这跟昨天的问题一样...
    这种小库不用看文档的,直接读源代码就可以了

    对于小菜来说读源码还是有难度
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2023-12-25 06:51
  • 签到天数: 35 天

    [LV.5]常住居民I

    9

    主题

    56

    回帖

    67

    积分

    初级工程师

    积分
    67

    油中3周年

    发表于 2023-10-29 18:25:28 | 显示全部楼层
    李恒道 发表于 2023-10-29 17:56
    middleware也没改
    按前边说的umd改

    也是加this吗?报错Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'subscribeWithSelector')
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2023-2-28 23:59
  • 签到天数: 191 天

    [LV.7]常住居民III

    637

    主题

    5202

    回帖

    6082

    积分

    管理员

    非物质文化遗产社会摇传承人

    积分
    6082

    荣誉开发者管理员油中2周年生态建设者喜迎中秋

    发表于 2023-10-29 18:48:31 | 显示全部楼层
    tansuo 发表于 2023-10-29 18:25
    也是加this吗?报错Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 's ...

    没处理umd格式获取,参考我第一次的回答
    这个算课后小作业了
    如果哥哥没搞懂说明一开始就没听哦

    混的人。
    ------------------------------------------
    進撃!永遠の帝国の破壊虎---李恒道

    入驻了爱发电https://afdian.net/a/lihengdao666
    个人宣言:この世界で私に胜てる人とコードはまだ生まれていません。死ぬのが怖くなければ来てください。
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2023-12-25 06:51
  • 签到天数: 35 天

    [LV.5]常住居民I

    9

    主题

    56

    回帖

    67

    积分

    初级工程师

    积分
    67

    油中3周年

    发表于 2023-10-29 20:13:57 | 显示全部楼层
    李恒道 发表于 2023-10-29 18:48
    没处理umd格式获取,参考我第一次的回答
    这个算课后小作业了
    如果哥哥没搞懂说明一开始就没听哦

    大佬 没有错误了 第一个值获取到了,但还是不明白这个状态管理器,如何用于存储网络爬虫的会话信息。这个中间件功能是什么,请大佬指导方向
    // ==UserScript==
    // @name         WeRead Scraper1
    // @namespace    https://github.com/Sec-ant/weread-scraper
    // @version      1.4.1
    // @author       Ze-Zheng Wu
    // @description  Scrape WeRead books and save them as HTML files
    // @license      MIT
    // @match        https://weread.qq.com/web/reader/*
    // @match        https://weread.qq.com/web/book/read*
    // @require      https://fastly.jsdelivr.net/npm/zustand@4.4.1/umd/vanilla.production.js
    // @require      https://fastly.jsdelivr.net/npm/zustand@4.4.1/umd/middleware.production.js
    // @run-at       document-start
    // ==/UserScript==

      const scraperSessionInitialState = {
        scraping: false,
        chapterLevelList: {}
      };
      const scraperSessionStore = this.zustandVanilla.createStore()(
         this.zustandMiddleware.subscribeWithSelector(
          this.zustandMiddleware.persist(() => scraperSessionInitialState, {
            name: "scraper-session-storage",
            storage: this.zustandMiddleware.createJSONStorage(() => sessionStorage)
          })
        )
      );
      console.log(scraperSessionStore.getState().scraping);
      console.log(scraperSessionStore.getState().chapterLevelList);
    回复

    使用道具 举报

    发表回复

    本版积分规则

    快速回复 返回顶部 返回列表