@jackwener/opencli 1.6.8 → 1.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +117 -59
- package/README.zh-CN.md +123 -79
- package/dist/clis/_shared/common.d.ts +3 -0
- package/dist/clis/_shared/common.js +22 -0
- package/dist/clis/bilibili/hot.d.ts +1 -0
- package/dist/clis/bilibili/hot.js +35 -0
- package/dist/clis/bluesky/feeds.d.ts +1 -0
- package/dist/clis/bluesky/feeds.js +27 -0
- package/dist/clis/bluesky/followers.d.ts +1 -0
- package/dist/clis/bluesky/followers.js +27 -0
- package/dist/clis/bluesky/following.d.ts +1 -0
- package/dist/clis/bluesky/following.js +27 -0
- package/dist/clis/bluesky/profile.d.ts +1 -0
- package/dist/clis/bluesky/profile.js +29 -0
- package/dist/clis/bluesky/search.d.ts +1 -0
- package/dist/clis/bluesky/search.js +28 -0
- package/dist/clis/bluesky/starter-packs.d.ts +1 -0
- package/dist/clis/bluesky/starter-packs.js +28 -0
- package/dist/clis/bluesky/thread.d.ts +1 -0
- package/dist/clis/bluesky/thread.js +30 -0
- package/dist/clis/bluesky/trending.d.ts +1 -0
- package/dist/clis/bluesky/trending.js +19 -0
- package/dist/clis/bluesky/user.d.ts +1 -0
- package/dist/clis/bluesky/user.js +33 -0
- package/dist/clis/cnki/search.d.ts +1 -0
- package/dist/clis/cnki/search.js +60 -0
- package/dist/clis/cnki/search.test.d.ts +1 -0
- package/dist/clis/cnki/search.test.js +18 -0
- package/dist/clis/devto/tag.d.ts +1 -0
- package/dist/clis/devto/tag.js +32 -0
- package/dist/clis/devto/top.d.ts +1 -0
- package/dist/clis/devto/top.js +26 -0
- package/dist/clis/devto/user.d.ts +1 -0
- package/dist/clis/devto/user.js +31 -0
- package/dist/clis/dictionary/examples.d.ts +1 -0
- package/dist/clis/dictionary/examples.js +27 -0
- package/dist/clis/dictionary/search.d.ts +1 -0
- package/dist/clis/dictionary/search.js +29 -0
- package/dist/clis/dictionary/synonyms.d.ts +1 -0
- package/dist/clis/dictionary/synonyms.js +27 -0
- package/dist/clis/douban/subject.d.ts +1 -0
- package/dist/clis/douban/subject.js +118 -0
- package/dist/clis/douban/top250.d.ts +1 -0
- package/dist/clis/douban/top250.js +67 -0
- package/dist/clis/facebook/add-friend.d.ts +1 -0
- package/dist/clis/facebook/add-friend.js +43 -0
- package/dist/clis/facebook/events.d.ts +1 -0
- package/dist/clis/facebook/events.js +40 -0
- package/dist/clis/facebook/feed.d.ts +1 -0
- package/dist/clis/facebook/feed.js +59 -0
- package/dist/clis/facebook/friends.d.ts +1 -0
- package/dist/clis/facebook/friends.js +38 -0
- package/dist/clis/facebook/groups.d.ts +1 -0
- package/dist/clis/facebook/groups.js +46 -0
- package/dist/clis/facebook/join-group.d.ts +1 -0
- package/dist/clis/facebook/join-group.js +44 -0
- package/dist/clis/facebook/memories.d.ts +1 -0
- package/dist/clis/facebook/memories.js +35 -0
- package/dist/clis/facebook/notifications.d.ts +1 -0
- package/dist/clis/facebook/notifications.js +36 -0
- package/dist/clis/facebook/profile.d.ts +1 -0
- package/dist/clis/facebook/profile.js +37 -0
- package/dist/clis/facebook/search.d.ts +1 -0
- package/dist/clis/facebook/search.js +38 -0
- package/dist/clis/facebook/search.test.d.ts +1 -1
- package/dist/clis/facebook/search.test.js +6 -9
- package/dist/clis/gitee/index.d.ts +3 -0
- package/dist/clis/gitee/index.js +3 -0
- package/dist/clis/gitee/search.d.ts +1 -0
- package/dist/clis/gitee/search.js +136 -0
- package/dist/clis/gitee/trending.d.ts +1 -0
- package/dist/clis/gitee/trending.js +567 -0
- package/dist/clis/gitee/user.d.ts +1 -0
- package/dist/clis/gitee/user.js +199 -0
- package/dist/clis/gitee/user.test.d.ts +1 -0
- package/dist/clis/gitee/user.test.js +63 -0
- package/dist/clis/hackernews/ask.d.ts +1 -0
- package/dist/clis/hackernews/ask.js +29 -0
- package/dist/clis/hackernews/best.d.ts +1 -0
- package/dist/clis/hackernews/best.js +29 -0
- package/dist/clis/hackernews/jobs.d.ts +1 -0
- package/dist/clis/hackernews/jobs.js +27 -0
- package/dist/clis/hackernews/new.d.ts +1 -0
- package/dist/clis/hackernews/new.js +29 -0
- package/dist/clis/hackernews/search.d.ts +1 -0
- package/dist/clis/hackernews/search.js +36 -0
- package/dist/clis/hackernews/show.d.ts +1 -0
- package/dist/clis/hackernews/show.js +29 -0
- package/dist/clis/hackernews/top.d.ts +1 -0
- package/dist/clis/hackernews/top.js +29 -0
- package/dist/clis/hackernews/user.d.ts +1 -0
- package/dist/clis/hackernews/user.js +22 -0
- package/dist/clis/hupu/hot.d.ts +1 -0
- package/dist/clis/hupu/hot.js +40 -0
- package/dist/clis/instagram/comment.d.ts +1 -0
- package/dist/clis/instagram/comment.js +47 -0
- package/dist/clis/instagram/explore.d.ts +1 -0
- package/dist/clis/instagram/explore.js +41 -0
- package/dist/clis/instagram/follow.d.ts +1 -0
- package/dist/clis/instagram/follow.js +43 -0
- package/dist/clis/instagram/followers.d.ts +1 -0
- package/dist/clis/instagram/followers.js +45 -0
- package/dist/clis/instagram/following.d.ts +1 -0
- package/dist/clis/instagram/following.js +45 -0
- package/dist/clis/instagram/like.d.ts +1 -0
- package/dist/clis/instagram/like.js +45 -0
- package/dist/clis/instagram/profile.d.ts +1 -0
- package/dist/clis/instagram/profile.js +39 -0
- package/dist/clis/instagram/save.d.ts +1 -0
- package/dist/clis/instagram/save.js +45 -0
- package/dist/clis/instagram/saved.d.ts +1 -0
- package/dist/clis/instagram/saved.js +38 -0
- package/dist/clis/instagram/search.d.ts +1 -0
- package/dist/clis/instagram/search.js +38 -0
- package/dist/clis/instagram/unfollow.d.ts +1 -0
- package/dist/clis/instagram/unfollow.js +40 -0
- package/dist/clis/instagram/unlike.d.ts +1 -0
- package/dist/clis/instagram/unlike.js +45 -0
- package/dist/clis/instagram/unsave.d.ts +1 -0
- package/dist/clis/instagram/unsave.js +45 -0
- package/dist/clis/instagram/user.d.ts +1 -0
- package/dist/clis/instagram/user.js +48 -0
- package/dist/clis/jd/add-cart.d.ts +1 -0
- package/dist/clis/jd/add-cart.js +71 -0
- package/dist/clis/jd/cart.d.ts +1 -0
- package/dist/clis/jd/cart.js +79 -0
- package/dist/clis/jd/commands.test.d.ts +5 -0
- package/dist/clis/jd/commands.test.js +64 -0
- package/dist/clis/jd/detail.d.ts +1 -0
- package/dist/clis/jd/detail.js +62 -0
- package/dist/clis/jd/reviews.d.ts +1 -0
- package/dist/clis/jd/reviews.js +54 -0
- package/dist/clis/jd/search.d.ts +1 -0
- package/dist/clis/jd/search.js +65 -0
- package/dist/clis/jianyu/search.d.ts +14 -0
- package/dist/clis/jianyu/search.js +135 -0
- package/dist/clis/jianyu/search.test.d.ts +1 -0
- package/dist/clis/jianyu/search.test.js +23 -0
- package/dist/clis/jike/post.d.ts +1 -0
- package/dist/clis/jike/post.js +61 -0
- package/dist/clis/jike/topic.d.ts +1 -0
- package/dist/clis/jike/topic.js +51 -0
- package/dist/clis/jike/user.d.ts +1 -0
- package/dist/clis/jike/user.js +50 -0
- package/dist/clis/jimeng/generate.d.ts +1 -0
- package/dist/clis/jimeng/generate.js +83 -0
- package/dist/clis/jimeng/history.d.ts +1 -0
- package/dist/clis/jimeng/history.js +47 -0
- package/dist/clis/jimeng/new.d.ts +1 -0
- package/dist/clis/jimeng/new.js +43 -0
- package/dist/clis/jimeng/workspaces.d.ts +1 -0
- package/dist/clis/jimeng/workspaces.js +41 -0
- package/dist/clis/linux-do/categories.d.ts +1 -0
- package/dist/clis/linux-do/categories.js +65 -0
- package/dist/clis/linux-do/search.d.ts +1 -0
- package/dist/clis/linux-do/search.js +41 -0
- package/dist/clis/linux-do/tags.d.ts +1 -0
- package/dist/clis/linux-do/tags.js +39 -0
- package/dist/clis/linux-do/topic-content.test.js +5 -5
- package/dist/clis/linux-do/topic.d.ts +1 -0
- package/dist/clis/linux-do/topic.js +56 -0
- package/dist/clis/linux-do/user-posts.d.ts +1 -0
- package/dist/clis/linux-do/user-posts.js +61 -0
- package/dist/clis/linux-do/user-topics.d.ts +1 -0
- package/dist/clis/linux-do/user-topics.js +48 -0
- package/dist/clis/lobsters/active.d.ts +1 -0
- package/dist/clis/lobsters/active.js +26 -0
- package/dist/clis/lobsters/hot.d.ts +1 -0
- package/dist/clis/lobsters/hot.js +26 -0
- package/dist/clis/lobsters/newest.d.ts +1 -0
- package/dist/clis/lobsters/newest.js +26 -0
- package/dist/clis/lobsters/tag.d.ts +1 -0
- package/dist/clis/lobsters/tag.js +32 -0
- package/dist/clis/pixiv/detail.d.ts +1 -0
- package/dist/clis/pixiv/detail.js +58 -0
- package/dist/clis/pixiv/ranking.d.ts +1 -0
- package/dist/clis/pixiv/ranking.js +59 -0
- package/dist/clis/pixiv/user.d.ts +1 -0
- package/dist/clis/pixiv/user.js +52 -0
- package/dist/clis/quark/ls.d.ts +1 -0
- package/dist/clis/quark/ls.js +63 -0
- package/dist/clis/quark/mkdir.d.ts +1 -0
- package/dist/clis/quark/mkdir.js +36 -0
- package/dist/clis/quark/mv.d.ts +1 -0
- package/dist/clis/quark/mv.js +53 -0
- package/dist/clis/quark/rename.d.ts +1 -0
- package/dist/clis/quark/rename.js +26 -0
- package/dist/clis/quark/rm.d.ts +1 -0
- package/dist/clis/quark/rm.js +24 -0
- package/dist/clis/quark/save.d.ts +1 -0
- package/dist/clis/quark/save.js +80 -0
- package/dist/clis/quark/share-tree.d.ts +1 -0
- package/dist/clis/quark/share-tree.js +45 -0
- package/dist/clis/quark/utils.d.ts +50 -0
- package/dist/clis/quark/utils.js +146 -0
- package/dist/clis/quark/utils.test.d.ts +1 -0
- package/dist/clis/quark/utils.test.js +58 -0
- package/dist/clis/reddit/frontpage.d.ts +1 -0
- package/dist/clis/reddit/frontpage.js +31 -0
- package/dist/clis/reddit/hot.d.ts +1 -0
- package/dist/clis/reddit/hot.js +45 -0
- package/dist/clis/reddit/popular.d.ts +1 -0
- package/dist/clis/reddit/popular.js +41 -0
- package/dist/clis/reddit/search.d.ts +1 -0
- package/dist/clis/reddit/search.js +65 -0
- package/dist/clis/reddit/subreddit.d.ts +1 -0
- package/dist/clis/reddit/subreddit.js +52 -0
- package/dist/clis/reddit/user-comments.d.ts +1 -0
- package/dist/clis/reddit/user-comments.js +44 -0
- package/dist/clis/reddit/user-posts.d.ts +1 -0
- package/dist/clis/reddit/user-posts.js +42 -0
- package/dist/clis/reddit/user.d.ts +1 -0
- package/dist/clis/reddit/user.js +37 -0
- package/dist/clis/stackoverflow/bounties.d.ts +1 -0
- package/dist/clis/stackoverflow/bounties.js +27 -0
- package/dist/clis/stackoverflow/hot.d.ts +1 -0
- package/dist/clis/stackoverflow/hot.js +24 -0
- package/dist/clis/stackoverflow/search.d.ts +1 -0
- package/dist/clis/stackoverflow/search.js +27 -0
- package/dist/clis/stackoverflow/unanswered.d.ts +1 -0
- package/dist/clis/stackoverflow/unanswered.js +26 -0
- package/dist/clis/steam/top-sellers.d.ts +1 -0
- package/dist/clis/steam/top-sellers.js +25 -0
- package/dist/clis/taobao/add-cart.d.ts +1 -0
- package/dist/clis/taobao/add-cart.js +149 -0
- package/dist/clis/taobao/cart.d.ts +1 -0
- package/dist/clis/taobao/cart.js +95 -0
- package/dist/clis/taobao/commands.test.d.ts +5 -0
- package/dist/clis/taobao/commands.test.js +64 -0
- package/dist/clis/taobao/detail.d.ts +1 -0
- package/dist/clis/taobao/detail.js +70 -0
- package/dist/clis/taobao/reviews.d.ts +1 -0
- package/dist/clis/taobao/reviews.js +76 -0
- package/dist/clis/taobao/search.d.ts +1 -0
- package/dist/clis/taobao/search.js +96 -0
- package/dist/clis/tiktok/comment.d.ts +1 -0
- package/dist/clis/tiktok/comment.js +57 -0
- package/dist/clis/tiktok/explore.d.ts +1 -0
- package/dist/clis/tiktok/explore.js +35 -0
- package/dist/clis/tiktok/follow.d.ts +1 -0
- package/dist/clis/tiktok/follow.js +39 -0
- package/dist/clis/tiktok/following.d.ts +1 -0
- package/dist/clis/tiktok/following.js +42 -0
- package/dist/clis/tiktok/friends.d.ts +1 -0
- package/dist/clis/tiktok/friends.js +43 -0
- package/dist/clis/tiktok/like.d.ts +1 -0
- package/dist/clis/tiktok/like.js +33 -0
- package/dist/clis/tiktok/live.d.ts +1 -0
- package/dist/clis/tiktok/live.js +47 -0
- package/dist/clis/tiktok/notifications.d.ts +1 -0
- package/dist/clis/tiktok/notifications.js +49 -0
- package/dist/clis/tiktok/profile.d.ts +1 -0
- package/dist/clis/tiktok/profile.js +54 -0
- package/dist/clis/tiktok/save.d.ts +1 -0
- package/dist/clis/tiktok/save.js +29 -0
- package/dist/clis/tiktok/search.d.ts +1 -0
- package/dist/clis/tiktok/search.js +39 -0
- package/dist/clis/tiktok/unfollow.d.ts +1 -0
- package/dist/clis/tiktok/unfollow.js +44 -0
- package/dist/clis/tiktok/unlike.d.ts +1 -0
- package/dist/clis/tiktok/unlike.js +33 -0
- package/dist/clis/tiktok/unsave.d.ts +1 -0
- package/dist/clis/tiktok/unsave.js +31 -0
- package/dist/clis/tiktok/user.d.ts +1 -0
- package/dist/clis/tiktok/user.js +41 -0
- package/dist/clis/twitter/reply.js +3 -8
- package/dist/clis/twitter/reply.test.js +5 -5
- package/dist/clis/v2ex/hot.d.ts +1 -0
- package/dist/clis/v2ex/hot.js +25 -0
- package/dist/clis/v2ex/latest.d.ts +1 -0
- package/dist/clis/v2ex/latest.js +25 -0
- package/dist/clis/v2ex/member.d.ts +1 -0
- package/dist/clis/v2ex/member.js +27 -0
- package/dist/clis/v2ex/node.d.ts +1 -0
- package/dist/clis/v2ex/node.js +38 -0
- package/dist/clis/v2ex/nodes.d.ts +1 -0
- package/dist/clis/v2ex/nodes.js +25 -0
- package/dist/clis/v2ex/replies.d.ts +1 -0
- package/dist/clis/v2ex/replies.js +26 -0
- package/dist/clis/v2ex/topic.d.ts +1 -0
- package/dist/clis/v2ex/topic.js +30 -0
- package/dist/clis/v2ex/user.d.ts +1 -0
- package/dist/clis/v2ex/user.js +33 -0
- package/dist/clis/xiaoe/catalog.d.ts +1 -0
- package/dist/clis/xiaoe/catalog.js +125 -0
- package/dist/clis/xiaoe/content.d.ts +1 -0
- package/dist/clis/xiaoe/content.js +39 -0
- package/dist/clis/xiaoe/courses.d.ts +1 -0
- package/dist/clis/xiaoe/courses.js +69 -0
- package/dist/clis/xiaoe/detail.d.ts +1 -0
- package/dist/clis/xiaoe/detail.js +35 -0
- package/dist/clis/xiaoe/play-url.d.ts +1 -0
- package/dist/clis/xiaoe/play-url.js +120 -0
- package/dist/clis/xiaohongshu/feed.d.ts +1 -0
- package/dist/clis/xiaohongshu/feed.js +32 -0
- package/dist/clis/xiaohongshu/note.js +8 -3
- package/dist/clis/xiaohongshu/note.test.js +11 -0
- package/dist/clis/xiaohongshu/notifications.d.ts +1 -0
- package/dist/clis/xiaohongshu/notifications.js +38 -0
- package/dist/clis/xueqiu/earnings-date.d.ts +1 -0
- package/dist/clis/xueqiu/earnings-date.js +61 -0
- package/dist/clis/xueqiu/feed.d.ts +1 -0
- package/dist/clis/xueqiu/feed.js +48 -0
- package/dist/clis/xueqiu/groups.d.ts +1 -0
- package/dist/clis/xueqiu/groups.js +25 -0
- package/dist/clis/xueqiu/hot-stock.d.ts +1 -0
- package/dist/clis/xueqiu/hot-stock.js +44 -0
- package/dist/clis/xueqiu/hot.d.ts +1 -0
- package/dist/clis/xueqiu/hot.js +44 -0
- package/dist/clis/xueqiu/kline.d.ts +1 -0
- package/dist/clis/xueqiu/kline.js +64 -0
- package/dist/clis/xueqiu/search.d.ts +1 -0
- package/dist/clis/xueqiu/search.js +49 -0
- package/dist/clis/xueqiu/stock.d.ts +1 -0
- package/dist/clis/xueqiu/stock.js +72 -0
- package/dist/clis/xueqiu/watchlist.d.ts +1 -0
- package/dist/clis/xueqiu/watchlist.js +45 -0
- package/dist/clis/zhihu/answer.d.ts +1 -0
- package/dist/clis/zhihu/answer.js +194 -0
- package/dist/clis/zhihu/answer.test.d.ts +1 -0
- package/dist/clis/zhihu/answer.test.js +81 -0
- package/dist/clis/zhihu/comment.d.ts +1 -0
- package/dist/clis/zhihu/comment.js +335 -0
- package/dist/clis/zhihu/comment.test.d.ts +1 -0
- package/dist/clis/zhihu/comment.test.js +54 -0
- package/dist/clis/zhihu/favorite.d.ts +1 -0
- package/dist/clis/zhihu/favorite.js +224 -0
- package/dist/clis/zhihu/favorite.test.d.ts +1 -0
- package/dist/clis/zhihu/favorite.test.js +196 -0
- package/dist/clis/zhihu/follow.d.ts +1 -0
- package/dist/clis/zhihu/follow.js +80 -0
- package/dist/clis/zhihu/follow.test.d.ts +1 -0
- package/dist/clis/zhihu/follow.test.js +45 -0
- package/dist/clis/zhihu/hot.d.ts +1 -0
- package/dist/clis/zhihu/hot.js +43 -0
- package/dist/clis/zhihu/like.d.ts +1 -0
- package/dist/clis/zhihu/like.js +91 -0
- package/dist/clis/zhihu/like.test.d.ts +1 -0
- package/dist/clis/zhihu/like.test.js +64 -0
- package/dist/clis/zhihu/search.d.ts +1 -0
- package/dist/clis/zhihu/search.js +52 -0
- package/dist/clis/zhihu/target.d.ts +24 -0
- package/dist/clis/zhihu/target.js +91 -0
- package/dist/clis/zhihu/target.test.d.ts +1 -0
- package/dist/clis/zhihu/target.test.js +77 -0
- package/dist/clis/zhihu/write-shared.d.ts +32 -0
- package/dist/clis/zhihu/write-shared.js +221 -0
- package/dist/clis/zhihu/write-shared.test.d.ts +1 -0
- package/dist/clis/zhihu/write-shared.test.js +175 -0
- package/dist/src/browser/bridge.d.ts +2 -0
- package/dist/src/browser/bridge.js +30 -24
- package/dist/src/browser/daemon-client.d.ts +30 -10
- package/dist/src/browser/daemon-client.js +42 -27
- package/dist/src/browser/daemon-client.test.js +32 -25
- package/dist/src/browser/dom-helpers.test.js +3 -2
- package/dist/src/browser/errors.d.ts +26 -1
- package/dist/src/browser/errors.js +40 -7
- package/dist/src/browser/errors.test.d.ts +1 -0
- package/dist/src/browser/errors.test.js +51 -0
- package/dist/src/browser/index.d.ts +2 -1
- package/dist/src/browser/index.js +1 -1
- package/dist/src/browser/page.d.ts +9 -8
- package/dist/src/browser/page.js +33 -31
- package/dist/src/browser.test.js +27 -8
- package/dist/src/build-manifest.d.ts +5 -11
- package/dist/src/build-manifest.js +6 -75
- package/dist/src/build-manifest.test.js +1 -39
- package/dist/src/cascade.js +3 -2
- package/dist/src/cli.d.ts +3 -3
- package/dist/src/cli.js +73 -65
- package/dist/src/cli.test.js +20 -15
- package/dist/src/clis/binance/asks.d.ts +1 -0
- package/dist/src/clis/binance/asks.js +20 -0
- package/dist/src/clis/binance/commands.test.d.ts +3 -0
- package/dist/src/clis/binance/commands.test.js +58 -0
- package/dist/src/clis/binance/depth.d.ts +1 -0
- package/dist/src/clis/binance/depth.js +20 -0
- package/dist/src/clis/binance/gainers.d.ts +1 -0
- package/dist/src/clis/binance/gainers.js +21 -0
- package/dist/src/clis/binance/klines.d.ts +1 -0
- package/dist/src/clis/binance/klines.js +20 -0
- package/dist/src/clis/binance/losers.d.ts +1 -0
- package/dist/src/clis/binance/losers.js +21 -0
- package/dist/src/clis/binance/pairs.d.ts +1 -0
- package/dist/src/clis/binance/pairs.js +20 -0
- package/dist/src/clis/binance/price.d.ts +1 -0
- package/dist/src/clis/binance/price.js +17 -0
- package/dist/src/clis/binance/prices.d.ts +1 -0
- package/dist/src/clis/binance/prices.js +18 -0
- package/dist/src/clis/binance/ticker.d.ts +1 -0
- package/dist/src/clis/binance/ticker.js +20 -0
- package/dist/src/clis/binance/top.d.ts +1 -0
- package/dist/src/clis/binance/top.js +20 -0
- package/dist/src/clis/binance/trades.d.ts +1 -0
- package/dist/src/clis/binance/trades.js +19 -0
- package/dist/src/commanderAdapter.js +19 -6
- package/dist/src/completion-fast.d.ts +25 -0
- package/dist/src/completion-fast.js +140 -0
- package/dist/src/completion.d.ts +1 -0
- package/dist/src/completion.js +1 -0
- package/dist/src/diagnostic.d.ts +1 -0
- package/dist/src/diagnostic.js +64 -2
- package/dist/src/diagnostic.test.js +93 -3
- package/dist/src/discovery.d.ts +3 -3
- package/dist/src/discovery.js +34 -97
- package/dist/src/doctor.d.ts +2 -0
- package/dist/src/doctor.js +59 -31
- package/dist/src/doctor.test.js +89 -16
- package/dist/src/download/index.d.ts +1 -1
- package/dist/src/engine.test.js +4 -19
- package/dist/src/execution.js +1 -13
- package/dist/src/explore.js +1 -1
- package/dist/src/generate-verified.d.ts +105 -0
- package/dist/src/generate-verified.js +696 -0
- package/dist/src/generate-verified.test.d.ts +1 -0
- package/dist/src/generate-verified.test.js +925 -0
- package/dist/src/generate.d.ts +11 -6
- package/dist/src/generate.js +4 -7
- package/dist/src/main.js +65 -12
- package/dist/src/pipeline/steps/download.d.ts +1 -17
- package/dist/src/pipeline/steps/download.js +20 -31
- package/dist/src/pipeline/steps/intercept.d.ts +1 -1
- package/dist/src/pipeline/steps/intercept.js +1 -1
- package/dist/src/pipeline/steps/tap.d.ts +1 -1
- package/dist/src/pipeline/steps/tap.js +1 -1
- package/dist/src/plugin-scaffold.d.ts +2 -2
- package/dist/src/plugin-scaffold.js +24 -21
- package/dist/src/plugin-scaffold.test.js +1 -1
- package/dist/src/plugin.d.ts +3 -2
- package/dist/src/plugin.js +29 -14
- package/dist/src/plugin.test.js +47 -32
- package/dist/src/record.js +26 -25
- package/dist/src/runtime-detect.js +3 -7
- package/dist/src/scripts/framework.d.ts +3 -0
- package/dist/src/scripts/framework.js +8 -4
- package/dist/src/scripts/store.d.ts +5 -1
- package/dist/src/scripts/store.js +5 -1
- package/dist/src/skill-generate.d.ts +30 -0
- package/dist/src/skill-generate.js +75 -0
- package/dist/src/skill-generate.test.d.ts +1 -0
- package/dist/src/skill-generate.test.js +173 -0
- package/dist/src/synthesize.d.ts +1 -1
- package/dist/src/synthesize.js +7 -8
- package/dist/src/types.d.ts +3 -1
- package/package.json +5 -5
- package/dist/clis/bilibili/hot.yaml +0 -38
- package/dist/clis/bluesky/feeds.yaml +0 -29
- package/dist/clis/bluesky/followers.yaml +0 -33
- package/dist/clis/bluesky/following.yaml +0 -33
- package/dist/clis/bluesky/profile.yaml +0 -27
- package/dist/clis/bluesky/search.yaml +0 -34
- package/dist/clis/bluesky/starter-packs.yaml +0 -34
- package/dist/clis/bluesky/thread.yaml +0 -32
- package/dist/clis/bluesky/trending.yaml +0 -27
- package/dist/clis/bluesky/user.yaml +0 -34
- package/dist/clis/devto/tag.yaml +0 -34
- package/dist/clis/devto/top.yaml +0 -29
- package/dist/clis/devto/user.yaml +0 -33
- package/dist/clis/dictionary/examples.yaml +0 -25
- package/dist/clis/dictionary/search.yaml +0 -27
- package/dist/clis/dictionary/synonyms.yaml +0 -25
- package/dist/clis/douban/subject.yaml +0 -107
- package/dist/clis/douban/top250.yaml +0 -70
- package/dist/clis/facebook/add-friend.yaml +0 -43
- package/dist/clis/facebook/events.yaml +0 -44
- package/dist/clis/facebook/feed.yaml +0 -63
- package/dist/clis/facebook/friends.yaml +0 -42
- package/dist/clis/facebook/groups.yaml +0 -50
- package/dist/clis/facebook/join-group.yaml +0 -44
- package/dist/clis/facebook/memories.yaml +0 -39
- package/dist/clis/facebook/notifications.yaml +0 -40
- package/dist/clis/facebook/profile.yaml +0 -37
- package/dist/clis/facebook/search.yaml +0 -47
- package/dist/clis/hackernews/ask.yaml +0 -38
- package/dist/clis/hackernews/best.yaml +0 -38
- package/dist/clis/hackernews/jobs.yaml +0 -36
- package/dist/clis/hackernews/new.yaml +0 -38
- package/dist/clis/hackernews/search.yaml +0 -44
- package/dist/clis/hackernews/show.yaml +0 -38
- package/dist/clis/hackernews/top.yaml +0 -38
- package/dist/clis/hackernews/user.yaml +0 -25
- package/dist/clis/hupu/hot.yaml +0 -43
- package/dist/clis/instagram/comment.yaml +0 -52
- package/dist/clis/instagram/explore.yaml +0 -43
- package/dist/clis/instagram/follow.yaml +0 -41
- package/dist/clis/instagram/followers.yaml +0 -51
- package/dist/clis/instagram/following.yaml +0 -51
- package/dist/clis/instagram/like.yaml +0 -46
- package/dist/clis/instagram/profile.yaml +0 -42
- package/dist/clis/instagram/save.yaml +0 -46
- package/dist/clis/instagram/saved.yaml +0 -40
- package/dist/clis/instagram/search.yaml +0 -44
- package/dist/clis/instagram/unfollow.yaml +0 -38
- package/dist/clis/instagram/unlike.yaml +0 -46
- package/dist/clis/instagram/unsave.yaml +0 -46
- package/dist/clis/instagram/user.yaml +0 -54
- package/dist/clis/jike/post.yaml +0 -59
- package/dist/clis/jike/topic.yaml +0 -53
- package/dist/clis/jike/user.yaml +0 -52
- package/dist/clis/jimeng/generate.yaml +0 -85
- package/dist/clis/jimeng/history.yaml +0 -46
- package/dist/clis/linux-do/categories.yaml +0 -70
- package/dist/clis/linux-do/search.yaml +0 -48
- package/dist/clis/linux-do/tags.yaml +0 -41
- package/dist/clis/linux-do/topic.yaml +0 -62
- package/dist/clis/linux-do/user-posts.yaml +0 -67
- package/dist/clis/linux-do/user-topics.yaml +0 -54
- package/dist/clis/lobsters/active.yaml +0 -29
- package/dist/clis/lobsters/hot.yaml +0 -29
- package/dist/clis/lobsters/newest.yaml +0 -29
- package/dist/clis/lobsters/tag.yaml +0 -34
- package/dist/clis/pixiv/detail.yaml +0 -49
- package/dist/clis/pixiv/ranking.yaml +0 -53
- package/dist/clis/pixiv/user.yaml +0 -46
- package/dist/clis/reddit/frontpage.yaml +0 -30
- package/dist/clis/reddit/hot.yaml +0 -47
- package/dist/clis/reddit/popular.yaml +0 -40
- package/dist/clis/reddit/search.yaml +0 -61
- package/dist/clis/reddit/subreddit.yaml +0 -50
- package/dist/clis/reddit/user-comments.yaml +0 -46
- package/dist/clis/reddit/user-posts.yaml +0 -44
- package/dist/clis/reddit/user.yaml +0 -40
- package/dist/clis/stackoverflow/bounties.yaml +0 -29
- package/dist/clis/stackoverflow/hot.yaml +0 -28
- package/dist/clis/stackoverflow/search.yaml +0 -33
- package/dist/clis/stackoverflow/unanswered.yaml +0 -28
- package/dist/clis/steam/top-sellers.yaml +0 -29
- package/dist/clis/tiktok/comment.yaml +0 -66
- package/dist/clis/tiktok/explore.yaml +0 -39
- package/dist/clis/tiktok/follow.yaml +0 -39
- package/dist/clis/tiktok/following.yaml +0 -46
- package/dist/clis/tiktok/friends.yaml +0 -47
- package/dist/clis/tiktok/like.yaml +0 -38
- package/dist/clis/tiktok/live.yaml +0 -51
- package/dist/clis/tiktok/notifications.yaml +0 -52
- package/dist/clis/tiktok/profile.yaml +0 -45
- package/dist/clis/tiktok/save.yaml +0 -34
- package/dist/clis/tiktok/search.yaml +0 -47
- package/dist/clis/tiktok/unfollow.yaml +0 -44
- package/dist/clis/tiktok/unlike.yaml +0 -38
- package/dist/clis/tiktok/unsave.yaml +0 -36
- package/dist/clis/tiktok/user.yaml +0 -44
- package/dist/clis/v2ex/hot.yaml +0 -28
- package/dist/clis/v2ex/latest.yaml +0 -28
- package/dist/clis/v2ex/member.yaml +0 -29
- package/dist/clis/v2ex/node.yaml +0 -34
- package/dist/clis/v2ex/nodes.yaml +0 -31
- package/dist/clis/v2ex/replies.yaml +0 -32
- package/dist/clis/v2ex/topic.yaml +0 -33
- package/dist/clis/v2ex/user.yaml +0 -34
- package/dist/clis/xiaoe/catalog.yaml +0 -129
- package/dist/clis/xiaoe/content.yaml +0 -43
- package/dist/clis/xiaoe/courses.yaml +0 -73
- package/dist/clis/xiaoe/detail.yaml +0 -39
- package/dist/clis/xiaoe/play-url.yaml +0 -124
- package/dist/clis/xiaohongshu/feed.yaml +0 -31
- package/dist/clis/xiaohongshu/notifications.yaml +0 -37
- package/dist/clis/xueqiu/earnings-date.yaml +0 -69
- package/dist/clis/xueqiu/feed.yaml +0 -53
- package/dist/clis/xueqiu/groups.yaml +0 -23
- package/dist/clis/xueqiu/hot-stock.yaml +0 -49
- package/dist/clis/xueqiu/hot.yaml +0 -46
- package/dist/clis/xueqiu/kline.yaml +0 -65
- package/dist/clis/xueqiu/search.yaml +0 -55
- package/dist/clis/xueqiu/stock.yaml +0 -69
- package/dist/clis/xueqiu/watchlist.yaml +0 -46
- package/dist/clis/zhihu/hot.yaml +0 -46
- package/dist/clis/zhihu/search.yaml +0 -59
- package/dist/src/browser/discover.d.ts +0 -15
- package/dist/src/browser/discover.js +0 -19
- package/dist/src/yaml-schema.d.ts +0 -29
- package/dist/src/yaml-schema.js +0 -22
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
import { CliError, CommandExecutionError } from '@jackwener/opencli/errors';
|
|
2
|
+
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
3
|
+
import { assertAllowedKinds, parseTarget } from './target.js';
|
|
4
|
+
import { buildResultRow, requireExecute, resolveCurrentUserIdentity, resolvePayload } from './write-shared.js';
|
|
5
|
+
const COMMENT_AUTHOR_SCOPE_SELECTOR = '.CommentItemV2-head, .CommentItem-head, .CommentItemV2-meta, .CommentItem-meta, .CommentItemV2-metaSibling, [data-comment-author], [itemprop="author"]';
|
|
6
|
+
cli({
|
|
7
|
+
site: 'zhihu',
|
|
8
|
+
name: 'comment',
|
|
9
|
+
description: 'Create a top-level comment on a Zhihu answer or article',
|
|
10
|
+
domain: 'zhihu.com',
|
|
11
|
+
strategy: Strategy.UI,
|
|
12
|
+
browser: true,
|
|
13
|
+
args: [
|
|
14
|
+
{ name: 'target', positional: true, required: true, help: 'Zhihu target URL or typed target' },
|
|
15
|
+
{ name: 'text', positional: true, help: 'Comment text' },
|
|
16
|
+
{ name: 'file', help: 'Comment text file path' },
|
|
17
|
+
{ name: 'execute', type: 'boolean', help: 'Actually perform the write action' },
|
|
18
|
+
],
|
|
19
|
+
columns: ['status', 'outcome', 'message', 'target_type', 'target', 'author_identity', 'created_url', 'created_proof'],
|
|
20
|
+
func: async (page, kwargs) => {
|
|
21
|
+
if (!page)
|
|
22
|
+
throw new CommandExecutionError('Browser session required for zhihu comment');
|
|
23
|
+
requireExecute(kwargs);
|
|
24
|
+
const rawTarget = String(kwargs.target);
|
|
25
|
+
const target = assertAllowedKinds('comment', parseTarget(rawTarget));
|
|
26
|
+
const payload = await resolvePayload(kwargs);
|
|
27
|
+
await page.goto(target.url);
|
|
28
|
+
const authorIdentity = await resolveCurrentUserIdentity(page);
|
|
29
|
+
const entryPath = await page.evaluate(`(() => {
|
|
30
|
+
const targetKind = ${JSON.stringify(target.kind)};
|
|
31
|
+
const targetQuestionId = ${JSON.stringify(target.kind === 'answer' ? target.questionId : null)};
|
|
32
|
+
const targetAnswerId = ${JSON.stringify(target.kind === 'answer' ? target.id : null)};
|
|
33
|
+
const restoredDraft = !!document.querySelector('[contenteditable="true"][data-draft-restored], textarea[data-draft-restored]');
|
|
34
|
+
let scope = document;
|
|
35
|
+
if (targetKind === 'answer') {
|
|
36
|
+
const block = Array.from(document.querySelectorAll('article, .AnswerItem, [data-zop-question-answer]')).find((node) => {
|
|
37
|
+
const dataAnswerId = node.getAttribute('data-answerid') || node.getAttribute('data-zop-question-answer') || '';
|
|
38
|
+
if (dataAnswerId && dataAnswerId.includes(targetAnswerId)) return true;
|
|
39
|
+
return Array.from(node.querySelectorAll('a[href*="/answer/"]')).some((link) => {
|
|
40
|
+
const href = link.getAttribute('href') || '';
|
|
41
|
+
return href.includes('/question/' + targetQuestionId + '/answer/' + targetAnswerId);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
if (!block) return { entryPathSafe: false, wrongAnswer: true };
|
|
45
|
+
scope = block;
|
|
46
|
+
} else {
|
|
47
|
+
scope =
|
|
48
|
+
document.querySelector('article')
|
|
49
|
+
|| document.querySelector('.Post-Main')
|
|
50
|
+
|| document.querySelector('[itemprop="articleBody"]')
|
|
51
|
+
|| document;
|
|
52
|
+
}
|
|
53
|
+
const topLevelCandidates = Array.from(scope.querySelectorAll('[contenteditable="true"], textarea')).map((editor) => {
|
|
54
|
+
const container = editor.closest('form, .CommentEditor, .CommentForm, .CommentsV2-footer, [data-comment-editor]') || editor.parentElement;
|
|
55
|
+
const replyHint = editor.getAttribute('data-reply-to') || '';
|
|
56
|
+
const text = 'value' in editor ? editor.value || '' : (editor.textContent || '');
|
|
57
|
+
const nestedReply = Boolean(container?.closest('[data-comment-id], .CommentItem'));
|
|
58
|
+
return { editor, container, replyHint, text, nestedReply };
|
|
59
|
+
}).filter((candidate) => candidate.container && !candidate.nestedReply);
|
|
60
|
+
return {
|
|
61
|
+
entryPathSafe: topLevelCandidates.length === 1
|
|
62
|
+
&& !restoredDraft
|
|
63
|
+
&& !topLevelCandidates[0].replyHint
|
|
64
|
+
&& !String(topLevelCandidates[0].text || '').trim(),
|
|
65
|
+
wrongAnswer: false,
|
|
66
|
+
};
|
|
67
|
+
})()`);
|
|
68
|
+
if (entryPath.wrongAnswer) {
|
|
69
|
+
throw new CliError('TARGET_NOT_FOUND', 'Resolved answer target no longer matches the requested answer:<questionId>:<answerId>');
|
|
70
|
+
}
|
|
71
|
+
if (!entryPath.entryPathSafe) {
|
|
72
|
+
throw new CliError('ACTION_NOT_AVAILABLE', 'Comment entry path was not proven side-effect free');
|
|
73
|
+
}
|
|
74
|
+
const beforeSubmitSnapshot = await page.evaluate(`(() => {
|
|
75
|
+
const normalize = (value) => value.replace(/\\s+/g, ' ').trim();
|
|
76
|
+
const targetKind = ${JSON.stringify(target.kind)};
|
|
77
|
+
const targetQuestionId = ${JSON.stringify(target.kind === 'answer' ? target.questionId : null)};
|
|
78
|
+
const targetAnswerId = ${JSON.stringify(target.kind === 'answer' ? target.id : null)};
|
|
79
|
+
let scope = document;
|
|
80
|
+
if (targetKind === 'answer') {
|
|
81
|
+
const block = Array.from(document.querySelectorAll('article, .AnswerItem, [data-zop-question-answer]')).find((node) => {
|
|
82
|
+
const dataAnswerId = node.getAttribute('data-answerid') || node.getAttribute('data-zop-question-answer') || '';
|
|
83
|
+
if (dataAnswerId && dataAnswerId.includes(targetAnswerId)) return true;
|
|
84
|
+
return Array.from(node.querySelectorAll('a[href*="/answer/"]')).some((link) => {
|
|
85
|
+
const href = link.getAttribute('href') || '';
|
|
86
|
+
return href.includes('/question/' + targetQuestionId + '/answer/' + targetAnswerId);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
if (!block) return { wrongAnswer: true, rows: [], commentLinks: [] };
|
|
90
|
+
scope = block;
|
|
91
|
+
} else {
|
|
92
|
+
scope =
|
|
93
|
+
document.querySelector('article')
|
|
94
|
+
|| document.querySelector('.Post-Main')
|
|
95
|
+
|| document.querySelector('[itemprop="articleBody"]')
|
|
96
|
+
|| document;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
wrongAnswer: false,
|
|
100
|
+
rows: Array.from(scope.querySelectorAll('[data-comment-id], .CommentItem')).map((node) => ({
|
|
101
|
+
id: node.getAttribute('data-comment-id') || '',
|
|
102
|
+
text: normalize(node.textContent || ''),
|
|
103
|
+
})),
|
|
104
|
+
commentLinks: Array.from(scope.querySelectorAll('a[href*="/comment/"]'))
|
|
105
|
+
.map((node) => node.getAttribute('href') || '')
|
|
106
|
+
.filter(Boolean),
|
|
107
|
+
};
|
|
108
|
+
})()`);
|
|
109
|
+
if (beforeSubmitSnapshot.wrongAnswer) {
|
|
110
|
+
throw new CliError('TARGET_NOT_FOUND', 'Resolved answer target no longer matches the requested answer:<questionId>:<answerId>');
|
|
111
|
+
}
|
|
112
|
+
const composer = await page.evaluate(`(async () => {
|
|
113
|
+
const targetKind = ${JSON.stringify(target.kind)};
|
|
114
|
+
const targetQuestionId = ${JSON.stringify(target.kind === 'answer' ? target.questionId : null)};
|
|
115
|
+
const targetAnswerId = ${JSON.stringify(target.kind === 'answer' ? target.id : null)};
|
|
116
|
+
let scope = document;
|
|
117
|
+
if (targetKind === 'answer') {
|
|
118
|
+
const block = Array.from(document.querySelectorAll('article, .AnswerItem, [data-zop-question-answer]')).find((node) => {
|
|
119
|
+
const dataAnswerId = node.getAttribute('data-answerid') || node.getAttribute('data-zop-question-answer') || '';
|
|
120
|
+
if (dataAnswerId && dataAnswerId.includes(targetAnswerId)) return true;
|
|
121
|
+
return Array.from(node.querySelectorAll('a[href*="/answer/"]')).some((link) => {
|
|
122
|
+
const href = link.getAttribute('href') || '';
|
|
123
|
+
return href.includes('/question/' + targetQuestionId + '/answer/' + targetAnswerId);
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
if (!block) return { composerState: 'wrong_answer' };
|
|
127
|
+
scope = block;
|
|
128
|
+
} else {
|
|
129
|
+
scope =
|
|
130
|
+
document.querySelector('article')
|
|
131
|
+
|| document.querySelector('.Post-Main')
|
|
132
|
+
|| document.querySelector('[itemprop="articleBody"]')
|
|
133
|
+
|| document;
|
|
134
|
+
}
|
|
135
|
+
const topLevelCandidates = Array.from(scope.querySelectorAll('[contenteditable="true"], textarea')).map((editor) => {
|
|
136
|
+
const container = editor.closest('form, .CommentEditor, .CommentForm, .CommentsV2-footer, [data-comment-editor]') || editor.parentElement;
|
|
137
|
+
const replyHint = editor.getAttribute('data-reply-to') || '';
|
|
138
|
+
const text = 'value' in editor ? editor.value || '' : (editor.textContent || '');
|
|
139
|
+
const nestedReply = Boolean(container?.closest('[data-comment-id], .CommentItem'));
|
|
140
|
+
return { editor, container, replyHint, text, nestedReply };
|
|
141
|
+
}).filter((candidate) => candidate.container && !candidate.nestedReply);
|
|
142
|
+
if (topLevelCandidates.length !== 1) return { composerState: 'unsafe' };
|
|
143
|
+
return {
|
|
144
|
+
composerState: !topLevelCandidates[0].replyHint && !topLevelCandidates[0].text.trim() ? 'fresh_top_level' : 'unsafe',
|
|
145
|
+
};
|
|
146
|
+
})()`);
|
|
147
|
+
if (composer.composerState === 'wrong_answer') {
|
|
148
|
+
throw new CliError('TARGET_NOT_FOUND', 'Resolved answer target no longer matches the requested answer:<questionId>:<answerId>');
|
|
149
|
+
}
|
|
150
|
+
if (composer.composerState !== 'fresh_top_level') {
|
|
151
|
+
throw new CliError('ACTION_NOT_AVAILABLE', 'Comment composer was not a fresh top-level composer');
|
|
152
|
+
}
|
|
153
|
+
const editorCheck = await page.evaluate(`(async () => {
|
|
154
|
+
const textToInsert = ${JSON.stringify(payload)};
|
|
155
|
+
const targetKind = ${JSON.stringify(target.kind)};
|
|
156
|
+
const targetQuestionId = ${JSON.stringify(target.kind === 'answer' ? target.questionId : null)};
|
|
157
|
+
const targetAnswerId = ${JSON.stringify(target.kind === 'answer' ? target.id : null)};
|
|
158
|
+
let scope = document;
|
|
159
|
+
if (targetKind === 'answer') {
|
|
160
|
+
const block = Array.from(document.querySelectorAll('article, .AnswerItem, [data-zop-question-answer]')).find((node) => {
|
|
161
|
+
const dataAnswerId = node.getAttribute('data-answerid') || node.getAttribute('data-zop-question-answer') || '';
|
|
162
|
+
if (dataAnswerId && dataAnswerId.includes(targetAnswerId)) return true;
|
|
163
|
+
return Array.from(node.querySelectorAll('a[href*="/answer/"]')).some((link) => {
|
|
164
|
+
const href = link.getAttribute('href') || '';
|
|
165
|
+
return href.includes('/question/' + targetQuestionId + '/answer/' + targetAnswerId);
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
if (!block) return { editorContent: '', mode: 'wrong_answer' };
|
|
169
|
+
scope = block;
|
|
170
|
+
} else {
|
|
171
|
+
scope =
|
|
172
|
+
document.querySelector('article')
|
|
173
|
+
|| document.querySelector('.Post-Main')
|
|
174
|
+
|| document.querySelector('[itemprop="articleBody"]')
|
|
175
|
+
|| document;
|
|
176
|
+
}
|
|
177
|
+
const topLevelCandidates = Array.from(scope.querySelectorAll('[contenteditable="true"], textarea')).map((editor) => {
|
|
178
|
+
const container = editor.closest('form, .CommentEditor, .CommentForm, .CommentsV2-footer, [data-comment-editor]') || editor.parentElement;
|
|
179
|
+
const nestedReply = Boolean(container?.closest('[data-comment-id], .CommentItem'));
|
|
180
|
+
return { editor, container, nestedReply };
|
|
181
|
+
}).filter((candidate) => candidate.container && !candidate.nestedReply);
|
|
182
|
+
if (topLevelCandidates.length !== 1) return { editorContent: '', mode: 'missing' };
|
|
183
|
+
const { editor } = topLevelCandidates[0];
|
|
184
|
+
editor.focus();
|
|
185
|
+
if ('value' in editor) {
|
|
186
|
+
editor.value = '';
|
|
187
|
+
editor.dispatchEvent(new Event('input', { bubbles: true }));
|
|
188
|
+
editor.value = textToInsert;
|
|
189
|
+
editor.dispatchEvent(new Event('input', { bubbles: true }));
|
|
190
|
+
} else {
|
|
191
|
+
editor.textContent = '';
|
|
192
|
+
document.execCommand('insertText', false, textToInsert);
|
|
193
|
+
editor.dispatchEvent(new InputEvent('input', { bubbles: true, data: textToInsert, inputType: 'insertText' }));
|
|
194
|
+
}
|
|
195
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
196
|
+
const content = 'value' in editor ? editor.value : (editor.textContent || '');
|
|
197
|
+
const replyHint = editor.getAttribute('data-reply-to') || '';
|
|
198
|
+
return { editorContent: content, mode: replyHint ? 'reply' : 'top_level' };
|
|
199
|
+
})()`);
|
|
200
|
+
if (editorCheck.mode === 'wrong_answer') {
|
|
201
|
+
throw new CliError('TARGET_NOT_FOUND', 'Resolved answer target no longer matches the requested answer:<questionId>:<answerId>');
|
|
202
|
+
}
|
|
203
|
+
if (editorCheck.mode !== 'top_level' || editorCheck.editorContent !== payload) {
|
|
204
|
+
throw new CliError('OUTCOME_UNKNOWN', 'Comment editor content did not exactly match the requested payload before submit');
|
|
205
|
+
}
|
|
206
|
+
const proof = await page.evaluate(`(async () => {
|
|
207
|
+
const normalize = (value) => value.replace(/\\s+/g, ' ').trim();
|
|
208
|
+
const commentAuthorScopeSelector = ${JSON.stringify(COMMENT_AUTHOR_SCOPE_SELECTOR)};
|
|
209
|
+
const readCommentAuthorSlug = (node) => {
|
|
210
|
+
const authorScopes = Array.from(node.querySelectorAll(commentAuthorScopeSelector));
|
|
211
|
+
const slugs = Array.from(new Set(authorScopes
|
|
212
|
+
.flatMap((scope) => Array.from(scope.querySelectorAll('a[href^="/people/"]')))
|
|
213
|
+
.map((link) => (link.getAttribute('href') || '').match(/^\\/people\\/([A-Za-z0-9_-]+)/)?.[1] || null)
|
|
214
|
+
.filter(Boolean)));
|
|
215
|
+
return slugs.length === 1 ? slugs[0] : null;
|
|
216
|
+
};
|
|
217
|
+
const targetKind = ${JSON.stringify(target.kind)};
|
|
218
|
+
const targetQuestionId = ${JSON.stringify(target.kind === 'answer' ? target.questionId : null)};
|
|
219
|
+
const targetAnswerId = ${JSON.stringify(target.kind === 'answer' ? target.id : null)};
|
|
220
|
+
let scope = document;
|
|
221
|
+
if (targetKind === 'answer') {
|
|
222
|
+
const block = Array.from(document.querySelectorAll('article, .AnswerItem, [data-zop-question-answer]')).find((node) => {
|
|
223
|
+
const dataAnswerId = node.getAttribute('data-answerid') || node.getAttribute('data-zop-question-answer') || '';
|
|
224
|
+
if (dataAnswerId && dataAnswerId.includes(targetAnswerId)) return true;
|
|
225
|
+
return Array.from(node.querySelectorAll('a[href*="/answer/"]')).some((link) => {
|
|
226
|
+
const href = link.getAttribute('href') || '';
|
|
227
|
+
return href.includes('/question/' + targetQuestionId + '/answer/' + targetAnswerId);
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
if (!block) return { proofType: 'wrong_answer' };
|
|
231
|
+
scope = block;
|
|
232
|
+
} else {
|
|
233
|
+
scope =
|
|
234
|
+
document.querySelector('article')
|
|
235
|
+
|| document.querySelector('.Post-Main')
|
|
236
|
+
|| document.querySelector('[itemprop="articleBody"]')
|
|
237
|
+
|| document;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const topLevelCandidates = Array.from(scope.querySelectorAll('[contenteditable="true"], textarea')).map((editor) => {
|
|
241
|
+
const container = editor.closest('form, [role="dialog"], .CommentEditor, .CommentForm, .CommentsV2-footer, [data-comment-editor]') || editor.parentElement;
|
|
242
|
+
const nestedReply = Boolean(container?.closest('[data-comment-id], .CommentItem'));
|
|
243
|
+
return { editor, container, nestedReply };
|
|
244
|
+
}).filter((candidate) => candidate.container && !candidate.nestedReply);
|
|
245
|
+
if (topLevelCandidates.length !== 1) return { proofType: 'unknown' };
|
|
246
|
+
const submitScope = topLevelCandidates[0].container || scope;
|
|
247
|
+
const submit = Array.from(submitScope.querySelectorAll('button')).find((node) => /发布|评论|发送/.test(node.textContent || ''));
|
|
248
|
+
submit && submit.click();
|
|
249
|
+
await new Promise((resolve) => setTimeout(resolve, 1200));
|
|
250
|
+
const createdLink = Array.from(scope.querySelectorAll('a[href*="/comment/"]')).find((node) => {
|
|
251
|
+
const href = node.getAttribute('href') || '';
|
|
252
|
+
return href.includes('/comment/') && !${JSON.stringify(beforeSubmitSnapshot.commentLinks ?? [])}.includes(href);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
if (createdLink) {
|
|
256
|
+
const card = createdLink.closest('[data-comment-id], .CommentItem, li');
|
|
257
|
+
const authorSlug = card ? readCommentAuthorSlug(card) : null;
|
|
258
|
+
const contentNode =
|
|
259
|
+
card?.querySelector('[data-comment-content], .RichContent-inner, .CommentItemV2-content, .CommentContent')
|
|
260
|
+
|| card;
|
|
261
|
+
const text = normalize(contentNode?.textContent || '');
|
|
262
|
+
const nestedReply = Boolean(card?.closest('ul ul, ol ol, li li') || card?.parentElement?.closest('[data-comment-id], .CommentItem'));
|
|
263
|
+
return {
|
|
264
|
+
proofType: 'stable_url',
|
|
265
|
+
createdUrl: new URL(createdLink.getAttribute('href') || '', location.origin).href,
|
|
266
|
+
commentScope: nestedReply ? 'nested_reply' : 'top_level_only',
|
|
267
|
+
authorIdentity: authorSlug,
|
|
268
|
+
targetMatches: text === normalize(${JSON.stringify(payload)}),
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const currentUserSlug = ${JSON.stringify(authorIdentity)};
|
|
273
|
+
const beforeIds = new Set(${JSON.stringify((beforeSubmitSnapshot.rows ?? []).map((row) => row.id).filter(Boolean))});
|
|
274
|
+
const beforeTexts = new Set(${JSON.stringify((beforeSubmitSnapshot.rows ?? []).map((row) => row.text).filter(Boolean))});
|
|
275
|
+
const normalizedPayload = normalize(${JSON.stringify(payload)});
|
|
276
|
+
const after = Array.from(scope.querySelectorAll('[data-comment-id], .CommentItem')).map((node) => {
|
|
277
|
+
return {
|
|
278
|
+
id: node.getAttribute('data-comment-id') || '',
|
|
279
|
+
text: normalize(node.textContent || ''),
|
|
280
|
+
authorSlug: readCommentAuthorSlug(node),
|
|
281
|
+
topLevel: !node.closest('ul ul, ol ol, li li') && !node.parentElement?.closest('[data-comment-id], .CommentItem'),
|
|
282
|
+
};
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
const matching = after.filter((row) =>
|
|
286
|
+
!beforeIds.has(row.id)
|
|
287
|
+
&& row.authorSlug === currentUserSlug
|
|
288
|
+
&& row.topLevel
|
|
289
|
+
&& row.text === normalizedPayload
|
|
290
|
+
&& !beforeTexts.has(row.text)
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
return matching.length === 1
|
|
294
|
+
? {
|
|
295
|
+
proofType: 'fallback',
|
|
296
|
+
createdProof: {
|
|
297
|
+
proof_type: 'comment_fallback',
|
|
298
|
+
author_scope: 'current_user',
|
|
299
|
+
target_scope: 'requested_target',
|
|
300
|
+
comment_scope: 'top_level_only',
|
|
301
|
+
content_match: 'exact_normalized',
|
|
302
|
+
observed_after_submit: true,
|
|
303
|
+
present_in_pre_submit_snapshot: false,
|
|
304
|
+
new_matching_entries: 1,
|
|
305
|
+
post_submit_matching_entries: after.filter((row) =>
|
|
306
|
+
row.authorSlug === currentUserSlug && row.topLevel && row.text === normalizedPayload
|
|
307
|
+
).length,
|
|
308
|
+
snapshot_scope: ${JSON.stringify(target.kind === 'answer'
|
|
309
|
+
? 'stabilized_expanded_target_answer_comment_list'
|
|
310
|
+
: 'stabilized_expanded_target_article_comment_list')},
|
|
311
|
+
},
|
|
312
|
+
}
|
|
313
|
+
: { proofType: 'unknown' };
|
|
314
|
+
})()`);
|
|
315
|
+
if (proof.proofType === 'wrong_answer') {
|
|
316
|
+
throw new CliError('TARGET_NOT_FOUND', 'Resolved answer target no longer matches the requested answer:<questionId>:<answerId>');
|
|
317
|
+
}
|
|
318
|
+
if (proof.proofType === 'fallback') {
|
|
319
|
+
return buildResultRow(`Commented on ${target.kind}`, target.kind, rawTarget, 'created', {
|
|
320
|
+
author_identity: authorIdentity,
|
|
321
|
+
created_proof: proof.createdProof,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
if (proof.proofType !== 'stable_url') {
|
|
325
|
+
throw new CliError('OUTCOME_UNKNOWN', 'Comment submit was dispatched, but the created object could not be proven safely');
|
|
326
|
+
}
|
|
327
|
+
if (proof.commentScope !== 'top_level_only' || proof.authorIdentity !== authorIdentity || !proof.targetMatches) {
|
|
328
|
+
throw new CliError('OUTCOME_UNKNOWN', 'Stable comment URL was found, but authorship or top-level scope could not be proven safely');
|
|
329
|
+
}
|
|
330
|
+
return buildResultRow(`Commented on ${target.kind}`, target.kind, rawTarget, 'created', {
|
|
331
|
+
author_identity: authorIdentity,
|
|
332
|
+
created_url: proof.createdUrl,
|
|
333
|
+
});
|
|
334
|
+
},
|
|
335
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './comment.js';
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { getRegistry } from '@jackwener/opencli/registry';
|
|
3
|
+
import './comment.js';
|
|
4
|
+
describe('zhihu comment', () => {
|
|
5
|
+
it('rejects composer paths that are not proven side-effect free', async () => {
|
|
6
|
+
const cmd = getRegistry().get('zhihu/comment');
|
|
7
|
+
expect(cmd?.func).toBeTypeOf('function');
|
|
8
|
+
const page = {
|
|
9
|
+
goto: vi.fn().mockResolvedValue(undefined),
|
|
10
|
+
evaluate: vi.fn()
|
|
11
|
+
.mockResolvedValueOnce({ slug: 'alice' })
|
|
12
|
+
.mockResolvedValueOnce({ entryPathSafe: false })
|
|
13
|
+
.mockResolvedValueOnce({ wrongAnswer: false, rows: [], commentLinks: [] }),
|
|
14
|
+
};
|
|
15
|
+
await expect(cmd.func(page, { target: 'answer:1:2', text: 'hello', execute: true })).rejects.toMatchObject({ code: 'ACTION_NOT_AVAILABLE' });
|
|
16
|
+
});
|
|
17
|
+
it('requires exact editor replacement before accepting fallback proof', async () => {
|
|
18
|
+
const cmd = getRegistry().get('zhihu/comment');
|
|
19
|
+
const page = {
|
|
20
|
+
goto: vi.fn().mockResolvedValue(undefined),
|
|
21
|
+
evaluate: vi.fn()
|
|
22
|
+
.mockResolvedValueOnce({ slug: 'alice' })
|
|
23
|
+
.mockResolvedValueOnce({ entryPathSafe: true })
|
|
24
|
+
.mockResolvedValueOnce({ wrongAnswer: false, rows: [], commentLinks: [] })
|
|
25
|
+
.mockResolvedValueOnce({ composerState: 'fresh_top_level' })
|
|
26
|
+
.mockResolvedValueOnce({ editorContent: 'hello', mode: 'top_level' })
|
|
27
|
+
.mockResolvedValueOnce({
|
|
28
|
+
proofType: 'fallback',
|
|
29
|
+
createdProof: {
|
|
30
|
+
proof_type: 'comment_fallback',
|
|
31
|
+
author_scope: 'current_user',
|
|
32
|
+
target_scope: 'requested_target',
|
|
33
|
+
comment_scope: 'top_level_only',
|
|
34
|
+
content_match: 'exact_normalized',
|
|
35
|
+
observed_after_submit: true,
|
|
36
|
+
present_in_pre_submit_snapshot: false,
|
|
37
|
+
new_matching_entries: 1,
|
|
38
|
+
post_submit_matching_entries: 1,
|
|
39
|
+
snapshot_scope: 'stabilized_expanded_target_comment_list',
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
};
|
|
43
|
+
await expect(cmd.func(page, { target: 'answer:1:2', text: 'hello', execute: true })).resolves.toEqual([
|
|
44
|
+
expect.objectContaining({ outcome: 'created', author_identity: 'alice', created_proof: expect.any(Object) }),
|
|
45
|
+
]);
|
|
46
|
+
expect(page.evaluate.mock.calls[1][0]).toContain('topLevelCandidates.length === 1');
|
|
47
|
+
expect(page.evaluate.mock.calls[1][0]).not.toContain('commentTrigger');
|
|
48
|
+
expect(page.evaluate.mock.calls[2][0]).toContain("node.getAttribute('data-answerid')");
|
|
49
|
+
expect(page.evaluate.mock.calls[2][0]).toContain("node.getAttribute('data-zop-question-answer')");
|
|
50
|
+
expect(page.evaluate.mock.calls[5][0]).toContain('const readCommentAuthorSlug = (node) =>');
|
|
51
|
+
expect(page.evaluate.mock.calls[5][0]).toContain('const commentAuthorScopeSelector = ".CommentItemV2-head, .CommentItem-head, .CommentItemV2-meta, .CommentItem-meta, .CommentItemV2-metaSibling, [data-comment-author], [itemprop=\\"author\\"]"');
|
|
52
|
+
expect(page.evaluate.mock.calls[5][0]).not.toContain("card?.querySelector('a[href^=\"/people/\"]')");
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { CliError, CommandExecutionError } from '@jackwener/opencli/errors';
|
|
2
|
+
import { cli, Strategy } from '@jackwener/opencli/registry';
|
|
3
|
+
import { assertAllowedKinds, parseTarget } from './target.js';
|
|
4
|
+
import { buildResultRow, requireExecute } from './write-shared.js';
|
|
5
|
+
function rowKey(row) {
|
|
6
|
+
return row.id || `name:${normalizeCollectionName(row.name)}`;
|
|
7
|
+
}
|
|
8
|
+
function normalizeCollectionName(value) {
|
|
9
|
+
return value
|
|
10
|
+
.replace(/\s+/g, ' ')
|
|
11
|
+
.replace(/\s+\d+\s*(条内容|个内容|items?)$/i, '')
|
|
12
|
+
.replace(/\s+(公开|私密|默认)$/i, '')
|
|
13
|
+
.trim();
|
|
14
|
+
}
|
|
15
|
+
cli({
|
|
16
|
+
site: 'zhihu',
|
|
17
|
+
name: 'favorite',
|
|
18
|
+
description: 'Favorite a Zhihu answer or article into a specific collection',
|
|
19
|
+
domain: 'zhihu.com',
|
|
20
|
+
strategy: Strategy.UI,
|
|
21
|
+
browser: true,
|
|
22
|
+
args: [
|
|
23
|
+
{ name: 'target', positional: true, required: true, help: 'Zhihu target URL or typed target' },
|
|
24
|
+
{ name: 'collection', help: 'Collection name' },
|
|
25
|
+
{ name: 'collection-id', help: 'Stable collection id' },
|
|
26
|
+
{ name: 'execute', type: 'boolean', help: 'Actually perform the write action' },
|
|
27
|
+
],
|
|
28
|
+
columns: ['status', 'outcome', 'message', 'target_type', 'target', 'collection_name', 'collection_id'],
|
|
29
|
+
func: async (page, kwargs) => {
|
|
30
|
+
if (!page)
|
|
31
|
+
throw new CommandExecutionError('Browser session required for zhihu favorite');
|
|
32
|
+
requireExecute(kwargs);
|
|
33
|
+
const rawTarget = String(kwargs.target);
|
|
34
|
+
const target = assertAllowedKinds('favorite', parseTarget(rawTarget));
|
|
35
|
+
const collectionName = typeof kwargs.collection === 'string' ? kwargs.collection : undefined;
|
|
36
|
+
const collectionId = typeof kwargs['collection-id'] === 'string' ? kwargs['collection-id'] : undefined;
|
|
37
|
+
if ((collectionName ? 1 : 0) + (collectionId ? 1 : 0) !== 1) {
|
|
38
|
+
throw new CliError('INVALID_INPUT', 'Use exactly one of --collection or --collection-id');
|
|
39
|
+
}
|
|
40
|
+
await page.goto(target.url);
|
|
41
|
+
const preflight = await page.evaluate(`(async () => {
|
|
42
|
+
const targetKind = ${JSON.stringify(target.kind)};
|
|
43
|
+
const targetQuestionId = ${JSON.stringify(target.kind === 'answer' ? target.questionId : null)};
|
|
44
|
+
const targetAnswerId = ${JSON.stringify(target.kind === 'answer' ? target.id : null)};
|
|
45
|
+
const wantedName = ${JSON.stringify(collectionName ?? null)};
|
|
46
|
+
const wantedId = ${JSON.stringify(collectionId ?? null)};
|
|
47
|
+
|
|
48
|
+
let scope = document;
|
|
49
|
+
if (targetKind === 'answer') {
|
|
50
|
+
const block = Array.from(document.querySelectorAll('article, .AnswerItem, [data-zop-question-answer]')).find((node) => {
|
|
51
|
+
const dataAnswerId = node.getAttribute('data-answerid') || node.getAttribute('data-zop-question-answer') || '';
|
|
52
|
+
if (dataAnswerId && dataAnswerId.includes(targetAnswerId)) return true;
|
|
53
|
+
return Array.from(node.querySelectorAll('a[href*="/answer/"]')).some((link) => {
|
|
54
|
+
const href = link.getAttribute('href') || '';
|
|
55
|
+
return href.includes('/question/' + targetQuestionId + '/answer/' + targetAnswerId);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
if (!block) return { wrongAnswer: true, chooserRows: [] };
|
|
59
|
+
scope = block;
|
|
60
|
+
} else {
|
|
61
|
+
scope =
|
|
62
|
+
document.querySelector('article')
|
|
63
|
+
|| document.querySelector('.Post-Main')
|
|
64
|
+
|| document.querySelector('[itemprop="articleBody"]')
|
|
65
|
+
|| document;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const favoriteButton = Array.from(scope.querySelectorAll('button')).find((node) => /收藏/.test(node.textContent || ''));
|
|
69
|
+
if (!favoriteButton) return { wrongAnswer: false, missingChooser: true, chooserRows: [] };
|
|
70
|
+
favoriteButton.click();
|
|
71
|
+
await new Promise((resolve) => setTimeout(resolve, 600));
|
|
72
|
+
|
|
73
|
+
const chooserRows = Array.from(document.querySelectorAll('[role="dialog"] li, [role="dialog"] [role="checkbox"], [role="dialog"] button'))
|
|
74
|
+
.map((node) => {
|
|
75
|
+
const text = (node.textContent || '').trim();
|
|
76
|
+
const id = node.getAttribute('data-id') || node.getAttribute('data-collection-id') || '';
|
|
77
|
+
const selected = node.getAttribute('aria-checked') === 'true'
|
|
78
|
+
|| node.getAttribute('aria-pressed') === 'true'
|
|
79
|
+
|| /已选|已收藏/.test(text);
|
|
80
|
+
return text ? { id, name: text, selected } : null;
|
|
81
|
+
})
|
|
82
|
+
.filter(Boolean);
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
wrongAnswer: false,
|
|
86
|
+
missingChooser: chooserRows.length === 0,
|
|
87
|
+
chooserRows,
|
|
88
|
+
targetRowId: wantedId,
|
|
89
|
+
targetRowName: wantedName,
|
|
90
|
+
};
|
|
91
|
+
})()`);
|
|
92
|
+
if (preflight.wrongAnswer) {
|
|
93
|
+
throw new CliError('TARGET_NOT_FOUND', 'Resolved answer target no longer matches the requested answer:<questionId>:<answerId>');
|
|
94
|
+
}
|
|
95
|
+
if (preflight.missingChooser) {
|
|
96
|
+
throw new CliError('ACTION_NOT_AVAILABLE', 'Favorite chooser did not open on the requested target');
|
|
97
|
+
}
|
|
98
|
+
const matchingRows = preflight.chooserRows.filter((row) => (collectionId
|
|
99
|
+
? row.id === collectionId
|
|
100
|
+
: normalizeCollectionName(row.name) === normalizeCollectionName(collectionName || '')));
|
|
101
|
+
if (collectionId && !matchingRows.some((row) => row.id === collectionId)) {
|
|
102
|
+
throw new CliError('ACTION_NOT_AVAILABLE', 'Favorite chooser could not confirm the requested stable collection id');
|
|
103
|
+
}
|
|
104
|
+
if (!collectionId && matchingRows.length !== 1) {
|
|
105
|
+
throw new CliError('ACTION_NOT_AVAILABLE', 'Favorite chooser could not prove that the requested collection name is globally unique');
|
|
106
|
+
}
|
|
107
|
+
const targetRow = matchingRows[0];
|
|
108
|
+
const targetRowKey = rowKey(targetRow);
|
|
109
|
+
const selectedBefore = preflight.chooserRows.filter((row) => row.selected).map(rowKey);
|
|
110
|
+
const verify = await page.evaluate(`(async () => {
|
|
111
|
+
const targetKind = ${JSON.stringify(target.kind)};
|
|
112
|
+
const targetQuestionId = ${JSON.stringify(target.kind === 'answer' ? target.questionId : null)};
|
|
113
|
+
const targetAnswerId = ${JSON.stringify(target.kind === 'answer' ? target.id : null)};
|
|
114
|
+
const targetWasSelected = ${JSON.stringify(targetRow.selected)};
|
|
115
|
+
const wantedName = ${JSON.stringify(collectionName ?? null)};
|
|
116
|
+
const wantedId = ${JSON.stringify(collectionId ?? null)};
|
|
117
|
+
const normalizeCollectionName = (value) => String(value || '')
|
|
118
|
+
.replace(/\\s+/g, ' ')
|
|
119
|
+
.replace(/\\s+\\d+\\s*(条内容|个内容|items?)$/i, '')
|
|
120
|
+
.replace(/\\s+(公开|私密|默认)$/i, '')
|
|
121
|
+
.trim();
|
|
122
|
+
const rowKey = (row) => row.id || 'name:' + normalizeCollectionName(row.name);
|
|
123
|
+
|
|
124
|
+
const chooserSelector = '[role="dialog"] li, [role="dialog"] [role="checkbox"], [role="dialog"] button';
|
|
125
|
+
const readChooserRows = () => Array.from(document.querySelectorAll(chooserSelector))
|
|
126
|
+
.map((node) => {
|
|
127
|
+
const text = (node.textContent || '').trim();
|
|
128
|
+
const id = node.getAttribute('data-id') || node.getAttribute('data-collection-id') || '';
|
|
129
|
+
const selected = node.getAttribute('aria-checked') === 'true'
|
|
130
|
+
|| node.getAttribute('aria-pressed') === 'true'
|
|
131
|
+
|| /已选|已收藏/.test(text);
|
|
132
|
+
return text ? { id, name: text, selected } : null;
|
|
133
|
+
})
|
|
134
|
+
.filter(Boolean);
|
|
135
|
+
const waitForChooserRows = async (expectedPresent) => {
|
|
136
|
+
for (let attempt = 0; attempt < 10; attempt += 1) {
|
|
137
|
+
const rows = readChooserRows();
|
|
138
|
+
if (expectedPresent ? rows.length > 0 : rows.length === 0) return rows;
|
|
139
|
+
await new Promise((resolve) => setTimeout(resolve, 150));
|
|
140
|
+
}
|
|
141
|
+
return readChooserRows();
|
|
142
|
+
};
|
|
143
|
+
const closeChooser = async () => {
|
|
144
|
+
const closeButton = Array.from(document.querySelectorAll('[role="dialog"] button, [role="dialog"] [role="button"]')).find((node) => {
|
|
145
|
+
const text = (node.textContent || '').trim();
|
|
146
|
+
const aria = node.getAttribute('aria-label') || '';
|
|
147
|
+
return /关闭|取消|收起/.test(text) || /关闭|cancel|close/i.test(aria);
|
|
148
|
+
});
|
|
149
|
+
closeButton && closeButton.click();
|
|
150
|
+
return waitForChooserRows(false);
|
|
151
|
+
};
|
|
152
|
+
const reopenChooser = async () => {
|
|
153
|
+
let scope = document;
|
|
154
|
+
if (targetKind === 'answer') {
|
|
155
|
+
const block = Array.from(document.querySelectorAll('article, .AnswerItem, [data-zop-question-answer]')).find((node) => {
|
|
156
|
+
const dataAnswerId = node.getAttribute('data-answerid') || node.getAttribute('data-zop-question-answer') || '';
|
|
157
|
+
if (dataAnswerId && dataAnswerId.includes(targetAnswerId)) return true;
|
|
158
|
+
return Array.from(node.querySelectorAll('a[href*="/answer/"]')).some((link) => {
|
|
159
|
+
const href = link.getAttribute('href') || '';
|
|
160
|
+
return href.includes('/question/' + targetQuestionId + '/answer/' + targetAnswerId);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
if (!block) return [];
|
|
164
|
+
scope = block;
|
|
165
|
+
} else {
|
|
166
|
+
scope =
|
|
167
|
+
document.querySelector('article')
|
|
168
|
+
|| document.querySelector('.Post-Main')
|
|
169
|
+
|| document.querySelector('[itemprop="articleBody"]')
|
|
170
|
+
|| document;
|
|
171
|
+
}
|
|
172
|
+
const favoriteButton = Array.from(scope.querySelectorAll('button')).find((node) => /收藏/.test(node.textContent || ''));
|
|
173
|
+
favoriteButton && favoriteButton.click();
|
|
174
|
+
return waitForChooserRows(true);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
let chooserRows = readChooserRows();
|
|
178
|
+
let sawChooserClose = false;
|
|
179
|
+
if (!targetWasSelected) {
|
|
180
|
+
const row = Array.from(document.querySelectorAll('[role="dialog"] li, [role="dialog"] [role="checkbox"], [role="dialog"] button')).find((node) => {
|
|
181
|
+
const text = (node.textContent || '').trim();
|
|
182
|
+
const id = node.getAttribute('data-id') || node.getAttribute('data-collection-id') || '';
|
|
183
|
+
return wantedId ? id === wantedId : normalizeCollectionName(text) === normalizeCollectionName(wantedName);
|
|
184
|
+
});
|
|
185
|
+
row && row.click();
|
|
186
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
187
|
+
const submit = Array.from(document.querySelectorAll('[role="dialog"] button')).find((node) => /完成|确定|保存/.test(node.textContent || ''));
|
|
188
|
+
submit && submit.click();
|
|
189
|
+
chooserRows = await waitForChooserRows(false);
|
|
190
|
+
sawChooserClose = chooserRows.length === 0;
|
|
191
|
+
} else {
|
|
192
|
+
chooserRows = await closeChooser();
|
|
193
|
+
sawChooserClose = chooserRows.length === 0;
|
|
194
|
+
}
|
|
195
|
+
if (sawChooserClose) {
|
|
196
|
+
chooserRows = await reopenChooser();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return {
|
|
200
|
+
persisted: sawChooserClose && chooserRows.length > 0,
|
|
201
|
+
readbackSource: sawChooserClose && chooserRows.length > 0 ? 'reopened_chooser' : (chooserRows.length > 0 ? 'same_modal' : 'missing'),
|
|
202
|
+
selectedAfter: chooserRows.filter((row) => row.selected).map(rowKey),
|
|
203
|
+
targetSelected: chooserRows.some((row) => rowKey(row) === ${JSON.stringify(targetRowKey)} && row.selected),
|
|
204
|
+
};
|
|
205
|
+
})()`);
|
|
206
|
+
if (!verify.persisted) {
|
|
207
|
+
throw new CliError('OUTCOME_UNKNOWN', 'Favorite action may have been applied, but persisted read-back was unavailable');
|
|
208
|
+
}
|
|
209
|
+
if (verify.readbackSource !== 'reopened_chooser') {
|
|
210
|
+
throw new CliError('OUTCOME_UNKNOWN', 'Favorite state was not re-read from a reopened chooser after submit');
|
|
211
|
+
}
|
|
212
|
+
if (!verify.targetSelected) {
|
|
213
|
+
throw new CliError('OUTCOME_UNKNOWN', 'Favorite chooser remained readable, but the requested collection was not confirmed as selected');
|
|
214
|
+
}
|
|
215
|
+
if (!selectedBefore.every((row) => verify.selectedAfter.includes(row))) {
|
|
216
|
+
throw new CliError('OUTCOME_UNKNOWN', `Favorite action changed unrelated collection membership: before=${JSON.stringify(selectedBefore)} after=${JSON.stringify(verify.selectedAfter)}`);
|
|
217
|
+
}
|
|
218
|
+
const outcome = targetRow.selected ? 'already_applied' : 'applied';
|
|
219
|
+
return buildResultRow(targetRow.selected ? `Already favorited ${target.kind}` : `Favorited ${target.kind}`, target.kind, rawTarget, outcome, {
|
|
220
|
+
collection_name: collectionName ?? targetRow.name,
|
|
221
|
+
...(targetRow.id ? { collection_id: targetRow.id } : {}),
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './favorite.js';
|