autoBrowse-linux.do

Automatically browse posts in linux.do

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

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

QingJ © 2025

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