autoBrowse-linux.do

自动浏览linux.do的帖子和话题Automatically browse posts in linux.do

目前为 2024-06-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name autoBrowse-linux.do
  3. // @description 自动浏览linux.do的帖子和话题Automatically browse posts in linux.do
  4. // @namespace Violentmonkey Scripts
  5. // @match https://linux.do/*
  6. // @grant none
  7. // @version 1.1.7
  8. // @author quantumcat
  9. // @license MIT
  10. // @icon https://www.google.com/s2/favicons?domain=linux.do
  11. // ==/UserScript==
  12. function getRandomArbitrary(min, max) {
  13. return Math.random() * (max - min) + min;
  14. }
  15.  
  16. var scrollInterval;
  17. var pauseTimeout;
  18. var isScrolling = false;
  19. var accumulatedScrollTime = parseInt(localStorage.getItem('accumulatedScrollTime')) || 0;
  20. var lastScrollStartTime;
  21.  
  22. function navigateNextTopic() {
  23. const URLS = ["https://linux.do/new",
  24. "https://linux.do/unread",
  25. "https://linux.do/c/general/4/l/latest",
  26. "https://linux.do/top",
  27. "https://linux.do/latest"];
  28. const randomIndex = Math.floor(Math.random() * URLS.length);
  29. const newURL = URLS[randomIndex];
  30. console.log("Navigating to new URL: " + newURL);
  31. window.location.href = newURL;
  32. }
  33.  
  34. function startScrolling() {
  35. if (isScrolling) return;
  36. isScrolling = true;
  37. button.textContent = "停止";
  38. button.disabled = false;
  39. lastScrollStartTime = Date.now();
  40.  
  41. var speed = getRandomArbitrary(6, 10);
  42. scrollInterval = setInterval(function() {
  43. var scrollDistance = getRandomArbitrary(1, 5);
  44. window.scrollBy(0, scrollDistance);
  45. var scrollHeight = document.documentElement.scrollHeight;
  46. var totalScroll = window.innerHeight + window.scrollY;
  47. // console.log("Scroll Height: " + scrollHeight);
  48. // console.log("Total Scroll: " + totalScroll);
  49. if ((totalScroll + 1) >= scrollHeight) {
  50. console.log("Reached bottom. Navigating to new URL...");
  51. clearInterval(scrollInterval);
  52. accumulateScrollTime();
  53. navigateNextTopic();
  54. }
  55. }, speed);
  56.  
  57. var scrollDuration = getRandomArbitrary(800, 1200);
  58. pauseTimeout = setTimeout(function() {
  59. var pauseDuration = getRandomArbitrary(600, 1000);
  60. clearInterval(scrollInterval);
  61. accumulateScrollTime();
  62. isScrolling = false;
  63. setTimeout(startScrolling, pauseDuration);
  64. }, scrollDuration);
  65. }
  66.  
  67. function stopScrolling() {
  68. clearInterval(scrollInterval);
  69. clearTimeout(pauseTimeout);
  70. isScrolling = false;
  71. button.textContent = "开始";
  72. button.disabled = false;
  73. }
  74.  
  75. function accumulateScrollTime() {
  76. var now = Date.now();
  77. accumulatedScrollTime += now - lastScrollStartTime;
  78. localStorage.setItem('accumulatedScrollTime', accumulatedScrollTime);
  79. console.log("accumulatedScrollTime: " + accumulatedScrollTime)
  80. if (accumulatedScrollTime >= 3600000) { // 1 hour in milliseconds
  81. accumulatedScrollTime = 0;
  82. localStorage.setItem('accumulatedScrollTime', accumulatedScrollTime);
  83. pauseForTenMinutes();
  84. }
  85. }
  86.  
  87. function findLinkAndRedirect() {
  88. const topicPattern = "/t/topic";
  89. var links = document.links;
  90. var matchingLinks = [];
  91. for (var i = 0; i < links.length; i++) {
  92. if (links[i].href.indexOf(topicPattern) !== -1) {
  93. matchingLinks.push(links[i].href);
  94. }
  95. if (matchingLinks.length == 8) { // 找8个链接,随机挑一个
  96. break;
  97. }
  98. }
  99.  
  100. if (matchingLinks.length > 0) {
  101. var randomIndex = Math.floor(Math.random() * matchingLinks.length);
  102. var newLocation = matchingLinks[randomIndex];
  103.  
  104. // 滚动页面
  105. var speed = getRandomArbitrary(6, 10);
  106. var scrollInterval = setInterval(function() {
  107. var scrollDistance = getRandomArbitrary(1, 5);
  108. window.scrollBy(0, scrollDistance); // 每次滚动像素
  109. clearInterval(scrollInterval);
  110. }, speed); // 每1秒滚动一次
  111.  
  112. // 延长停顿时间,等待滚动结束后再跳转
  113. var pauseDuration = getRandomArbitrary(1600, 3000);
  114. setTimeout(function() {
  115. window.location.href = newLocation;
  116. }, pauseDuration); // 2秒后跳转
  117. }
  118. }
  119.  
  120. function setButtonDisabled() {
  121. button.textContent = "导航中";
  122. button.style.color = "#f0f0f0";
  123. button.disabled = true;
  124. }
  125.  
  126. function pauseForTenMinutes() {
  127. stopScrolling();
  128. console.log("Pausing for 10 minutes...");
  129. setTimeout(function() {
  130. console.log("Resuming after pause...");
  131. startScrolling();
  132. }, 10 * 60 * 1000); // 10 minutes in milliseconds
  133. }
  134.  
  135. // 添加“开始/停止”按钮
  136. var button = document.createElement("button");
  137. button.style.position = "fixed";
  138. button.style.right = "15%";
  139. button.style.bottom = "30%";
  140. button.style.transform = "translateY(-50%)";
  141. button.style.padding = "10px 20px";
  142. button.style.fontSize = "20px";
  143. button.style.backgroundColor = "white"; // 白色背景
  144. button.style.border = "1px solid #ddd"; // 浅灰色边框
  145. button.style.borderRadius = "5px"; // 圆角
  146. button.style.color = "black";
  147. button.textContent = "开始";
  148. document.body.appendChild(button);
  149.  
  150. button.addEventListener("click", function() {
  151. if (isScrolling) {
  152. stopScrolling();
  153. } else {
  154. startScrolling();
  155. }
  156. });
  157.  
  158. if (window.location.href.indexOf("/t/topic/") != -1) {
  159. // 如果在主题页面,默认就开始滚动
  160. startScrolling();
  161. } else {
  162. findLinkAndRedirect();
  163. setButtonDisabled();
  164. }
  165.  
  166.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址