Greasy Fork is available in English.

知乎评论展开

滚动到底部若干次,然后模拟点击展开所有评论,供singlefile保存用

  1. // ==UserScript==
  2. // @name 知乎评论展开
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-05-032
  5. // @description 滚动到底部若干次,然后模拟点击展开所有评论,供singlefile保存用
  6. // @author You
  7. // @match https://www.zhihu.com/question/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=zhihu.com
  9. // @grant none
  10. // @license GPL-3.0 License
  11. // ==/UserScript==
  12.  
  13. // setInterval(() => {
  14. // // window.scrollTo(0, document.documentElement.scrollHeight - window.innerHeight);
  15. // window.scrollTo(0, document.documentElement.scrollHeight);
  16. // window.scrollBy(0,-100);
  17. // }, 5000);
  18.  
  19. const sleep = (delay) => new Promise((resolve) => setTimeout(resolve, delay))
  20.  
  21. let count = 0; // 计数器,用于记录执行次数
  22.  
  23. const intervalId = setInterval(() => {
  24. window.scrollTo(0, document.documentElement.scrollHeight);
  25. window.scrollBy(0,-100);
  26. count++; // 每次执行计数器加 1
  27.  
  28. // 如果执行次数达到 10 次,则停止定时器
  29. if (count === 10) {
  30. clearInterval(intervalId); // 清除定时器
  31. }
  32. }, 1000);
  33.  
  34.  
  35. setTimeout(async () => {
  36. let nodelist = document.querySelectorAll("div.ContentItem-actions > button:nth-child(2)");
  37. nodelist.forEach(element => {
  38. element.click()
  39. });
  40. await sleep(3000)
  41. document.querySelector("div.css-1aq8hf9 > button").click()
  42. }, 11000);