| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| (function () { |
| ("use strict"); |
| |
| const possibleBaseURLs = [ |
| "https://meta.discourse.org", |
| "https://linux.do", |
| "https://meta.appinn.net", |
| "https://community.openai.com", |
| ]; |
|
|
| |
| const currentURL = window.location.href; |
|
|
| |
| let BASE_URL = possibleBaseURLs.find((url) => currentURL.startsWith(url)); |
|
|
| |
| if (!BASE_URL) { |
| BASE_URL = possibleBaseURLs[0]; |
| console.log("默认BASE_URL设置为: " + BASE_URL); |
| } else { |
| console.log("当前BASE_URL是: " + BASE_URL); |
| } |
|
|
| |
| console.log("脚本正在运行在: " + BASE_URL); |
| |
| |
| |
| function checkFirstRun() { |
| if (localStorage.getItem("isFirstRun") === null) { |
| |
| console.log("脚本第一次运行,执行初始化操作..."); |
| updateInitialData(); |
|
|
| |
| localStorage.setItem("isFirstRun", "false"); |
| } else { |
| |
| console.log("脚本非第一次运行"); |
| } |
| } |
|
|
| |
| function updateInitialData() { |
| localStorage.setItem("read", "true"); |
| localStorage.setItem("autoLikeEnabled", "true"); |
| console.log("执行了初始数据更新操作"); |
| } |
| const delay = 2000; |
| let scrollInterval = null; |
| let checkScrollTimeout = null; |
| let autoLikeInterval = null; |
|
|
| function scrollToBottomSlowly( |
| stopDistance = 9999999999, |
| callback = undefined, |
| distancePerStep = 20, |
| delayPerStep = 50 |
| ) { |
| if (scrollInterval !== null) { |
| clearInterval(scrollInterval); |
| } |
| scrollInterval = setInterval(() => { |
| if ( |
| window.innerHeight + window.scrollY >= |
| document.body.offsetHeight - 100 || |
| window.innerHeight + window.scrollY >= stopDistance |
| ) { |
| clearInterval(scrollInterval); |
| scrollInterval = null; |
| if (typeof callback === "function") { |
| callback(); |
| } |
| } else { |
| window.scrollBy(0, distancePerStep); |
| } |
| }, delayPerStep); |
| } |
| |
|
|
| function navigateToNextTopic() { |
| |
| const urls = [ |
| `${BASE_URL}/latest`, |
| `${BASE_URL}/top`, |
| `${BASE_URL}/latest?ascending=false&order=posts`, |
| |
| ]; |
|
|
| |
| const randomIndex = Math.floor(Math.random() * urls.length); |
|
|
| |
| const nextTopicURL = urls[randomIndex]; |
| localStorage.setItem("navigatingToNextTopic", "true"); |
| |
| window.location.href = nextTopicURL; |
| } |
|
|
| |
| function checkScroll() { |
| if (localStorage.getItem("read")) { |
| if ( |
| window.innerHeight + window.scrollY >= |
| document.body.offsetHeight - 100 |
| ) { |
| console.log("已滚动到底部"); |
| navigateToNextTopic(); |
| } else { |
| scrollToBottomSlowly(); |
| if (checkScrollTimeout !== null) { |
| clearTimeout(checkScrollTimeout); |
| } |
| checkScrollTimeout = setTimeout(checkScroll, delay); |
| } |
| } |
| } |
|
|
| |
| window.addEventListener("load", () => { |
| checkFirstRun(); |
| console.log( |
| "autoRead", |
| localStorage.getItem("read"), |
| "autoLikeEnabled", |
| localStorage.getItem("autoLikeEnabled") |
| ); |
| if (localStorage.getItem("read") === "true") { |
| |
| if (localStorage.getItem("navigatingToNextTopic") === "true") { |
| console.log("正在导航到下一个话题"); |
| |
| |
| localStorage.removeItem("navigatingToNextTopic"); |
| |
| setTimeout(() => { |
| |
| scrollToBottomSlowly( |
| Math.random() * document.body.offsetHeight * 3, |
| searchLinkClick, |
| 20, |
| 20 |
| ); |
| }, 2000); |
| } else { |
| console.log("执行正常的滚动和检查逻辑"); |
| |
| checkScroll(); |
| if (isAutoLikeEnabled()) { |
| |
| autoLike(); |
| } |
| } |
| } |
| }); |
| |
| function searchLinkClick() { |
| |
| |
| const links = document.querySelectorAll('a[href^="/t/"]'); |
| |
| |
| |
|
|
| |
| const unreadLinks = Array.from(links).filter((link) => { |
| |
| |
| |
| |
| |
|
|
| |
| let parent = link.parentElement; |
| let times = 0; |
| while (parent && times < 3) { |
| if (parent.classList.contains("visited")) { |
| |
| return false; |
| } |
| parent = parent.parentElement; |
| times++; |
| } |
|
|
| |
| return true; |
| }); |
|
|
| |
| if (unreadLinks.length > 0) { |
| |
| const randomIndex = Math.floor(Math.random() * unreadLinks.length); |
| const link = unreadLinks[randomIndex]; |
| |
| console.log("Found link:", link.href); |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| |
| window.location.href = link.href; |
| } else { |
| |
| console.log("No link with the specified format was found."); |
| scrollToBottomSlowly( |
| Math.random() * document.body.offsetHeight * 3, |
| searchLinkClick |
| ); |
| } |
| } |
| |
| const currentTime = Date.now(); |
| |
| const defaultTimestamp = new Date("1999-01-01T00:00:00Z").getTime(); |
| const storedTime = parseInt( |
| localStorage.getItem("clickCounterTimestamp") || |
| defaultTimestamp.toString(), |
| 10 |
| ); |
|
|
| |
| let clickCounter = parseInt(localStorage.getItem("clickCounter") || "0", 10); |
| |
| if (currentTime - storedTime > 24 * 60 * 60 * 1000) { |
| |
| clickCounter = 0; |
| localStorage.setItem("clickCounter", "0"); |
| localStorage.setItem("clickCounterTimestamp", currentTime.toString()); |
| } |
|
|
| console.log(`Initial clickCounter: ${clickCounter}`); |
| function triggerClick(button) { |
| const event = new MouseEvent("click", { |
| bubbles: true, |
| cancelable: true, |
| view: window, |
| }); |
| button.dispatchEvent(event); |
| } |
|
|
| function autoLike() { |
| console.log(`Initial clickCounter: ${clickCounter}`); |
| |
| const buttons = document.querySelectorAll( |
| ".discourse-reactions-reaction-button" |
| ); |
| if (buttons.length === 0) { |
| console.error( |
| "No buttons found with the selector '.discourse-reactions-reaction-button'" |
| ); |
| return; |
| } |
| console.log(`Found ${buttons.length} buttons.`); |
|
|
| |
| buttons.forEach((button, index) => { |
| if ( |
| (button.title !== "点赞此帖子" && button.title !== "Like this post") || |
| clickCounter >= 50 |
| ) { |
| return; |
| } |
|
|
| |
| autoLikeInterval = setTimeout(() => { |
| |
| triggerClick(button); |
| console.log(`Clicked like button ${index + 1}`); |
| clickCounter++; |
| |
| localStorage.setItem("clickCounter", clickCounter.toString()); |
| |
| if (clickCounter === 50) { |
| console.log("Reached 50 likes, setting the like variable to false."); |
| localStorage.setItem("autoLikeEnabled", "false"); |
| } else { |
| console.log("clickCounter:", clickCounter); |
| } |
| }, index * 3000); |
| }); |
| } |
| const button = document.createElement("button"); |
| |
| button.textContent = |
| localStorage.getItem("read") === "true" ? "停止阅读" : "开始阅读"; |
| button.style.position = "fixed"; |
| button.style.bottom = "10px"; |
| button.style.left = "10px"; |
| button.style.zIndex = 1000; |
| button.style.backgroundColor = "#f0f0f0"; |
| button.style.color = "#000"; |
| button.style.border = "1px solid #ddd"; |
| button.style.padding = "5px 10px"; |
| button.style.borderRadius = "5px"; |
| |
|
|
| button.onclick = function () { |
| const currentlyReading = localStorage.getItem("read") === "true"; |
| const newReadState = !currentlyReading; |
| localStorage.setItem("read", newReadState.toString()); |
| button.textContent = newReadState ? "停止阅读" : "开始阅读"; |
| if (!newReadState) { |
| if (scrollInterval !== null) { |
| clearInterval(scrollInterval); |
| scrollInterval = null; |
| } |
| if (checkScrollTimeout !== null) { |
| clearTimeout(checkScrollTimeout); |
| checkScrollTimeout = null; |
| } |
| localStorage.removeItem("navigatingToNextTopic"); |
| } else { |
| |
| if (BASE_URL == "https://linux.do") { |
| window.location.href = "https://linux.do/t/topic/13716/340"; |
| } else if (BASE_URL == "https://meta.appinn.net") { |
| window.location.href = "https://meta.appinn.net/t/topic/52006"; |
| } else { |
| window.location.href = `${BASE_URL}/t/topic/1`; |
| } |
| checkScroll(); |
| } |
| }; |
|
|
| |
| |
| const toggleAutoLikeButton = document.createElement("button"); |
| toggleAutoLikeButton.textContent = isAutoLikeEnabled() |
| ? "禁用自动点赞" |
| : "启用自动点赞"; |
| toggleAutoLikeButton.style.position = "fixed"; |
| toggleAutoLikeButton.style.bottom = "50px"; |
| toggleAutoLikeButton.style.left = "10px"; |
| toggleAutoLikeButton.style.zIndex = "1000"; |
| toggleAutoLikeButton.style.backgroundColor = "#f0f0f0"; |
| toggleAutoLikeButton.style.color = "#000"; |
| toggleAutoLikeButton.style.border = "1px solid #ddd"; |
| toggleAutoLikeButton.style.padding = "5px 10px"; |
| toggleAutoLikeButton.style.borderRadius = "5px"; |
| |
|
|
| |
| toggleAutoLikeButton.addEventListener("click", () => { |
| const isEnabled = !isAutoLikeEnabled(); |
| setAutoLikeEnabled(isEnabled); |
| toggleAutoLikeButton.textContent = isEnabled |
| ? "禁用自动点赞" |
| : "启用自动点赞"; |
| }); |
| |
| function isAutoLikeEnabled() { |
| |
| return localStorage.getItem("autoLikeEnabled") !== "false"; |
| } |
|
|
| |
| function setAutoLikeEnabled(enabled) { |
| localStorage.setItem("autoLikeEnabled", enabled ? "true" : "false"); |
| } |
| })(); |
|
|