🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

autoBrowse-linux.do

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

От 12.06.2024. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name        autoBrowse-linux.do
// @description 自动浏览linux.do的帖子和话题Automatically browse posts in linux.do
// @namespace   Violentmonkey Scripts
// @match       https://linux.do/*
// @grant       none
// @version     1.1.7
// @author      quantumcat
// @license      MIT
// @icon         https://www.google.com/s2/favicons?domain=linux.do
// ==/UserScript==
function getRandomArbitrary(min, max) {
    return Math.random() * (max - min) + min;
}

var scrollInterval;
var pauseTimeout;
var isScrolling = false;
var accumulatedScrollTime = parseInt(localStorage.getItem('accumulatedScrollTime')) || 0;
var lastScrollStartTime;

function navigateNextTopic() {
    const URLS = ["https://linux.do/new",
                  "https://linux.do/unread",
                  "https://linux.do/c/general/4/l/latest",
                  "https://linux.do/top",
                  "https://linux.do/latest"];
    const randomIndex = Math.floor(Math.random() * URLS.length);
    const newURL = URLS[randomIndex];
    console.log("Navigating to new URL: " + newURL);
    window.location.href = newURL;
}

function startScrolling() {
    if (isScrolling) return;
    isScrolling = true;
    button.textContent = "停止";
    button.disabled = false;
    lastScrollStartTime = Date.now();

    var speed = getRandomArbitrary(6, 10);
    scrollInterval = setInterval(function() {
        var scrollDistance = getRandomArbitrary(1, 5);
        window.scrollBy(0, scrollDistance);
        var scrollHeight = document.documentElement.scrollHeight;
        var totalScroll = window.innerHeight + window.scrollY;
        // console.log("Scroll Height: " + scrollHeight);
        // console.log("Total Scroll: " + totalScroll);
        if ((totalScroll + 1) >= scrollHeight) {
            console.log("Reached bottom. Navigating to new URL...");
            clearInterval(scrollInterval);
            accumulateScrollTime();
            navigateNextTopic();
        }
    }, speed);

    var scrollDuration = getRandomArbitrary(800, 1200);
    pauseTimeout = setTimeout(function() {
        var pauseDuration = getRandomArbitrary(600, 1000);
        clearInterval(scrollInterval);
        accumulateScrollTime();
        isScrolling = false;
        setTimeout(startScrolling, pauseDuration);
    }, scrollDuration);
}

function stopScrolling() {
    clearInterval(scrollInterval);
    clearTimeout(pauseTimeout);
    isScrolling = false;
    button.textContent = "开始";
    button.disabled = false;
}

function accumulateScrollTime() {
    var now = Date.now();
    accumulatedScrollTime += now - lastScrollStartTime;
    localStorage.setItem('accumulatedScrollTime', accumulatedScrollTime);
    console.log("accumulatedScrollTime: " + accumulatedScrollTime)
    if (accumulatedScrollTime >= 3600000) { // 1 hour in milliseconds
        accumulatedScrollTime = 0;
        localStorage.setItem('accumulatedScrollTime', accumulatedScrollTime);
        pauseForTenMinutes();
    }
}

function findLinkAndRedirect() {
    const topicPattern = "/t/topic";
    var links = document.links;
    var matchingLinks = [];
    for (var i = 0; i < links.length; i++) {
        if (links[i].href.indexOf(topicPattern) !== -1) {
            matchingLinks.push(links[i].href);
        }
        if (matchingLinks.length == 8) { // 找8个链接,随机挑一个
            break;
        }
    }

    if (matchingLinks.length > 0) {
        var randomIndex = Math.floor(Math.random() * matchingLinks.length);
        var newLocation = matchingLinks[randomIndex];

        // 滚动页面
        var speed = getRandomArbitrary(6, 10);
        var scrollInterval = setInterval(function() {
            var scrollDistance = getRandomArbitrary(1, 5);
            window.scrollBy(0, scrollDistance);  // 每次滚动像素
            clearInterval(scrollInterval);
        }, speed);  // 每1秒滚动一次

        // 延长停顿时间,等待滚动结束后再跳转
        var pauseDuration = getRandomArbitrary(1600, 3000);
        setTimeout(function() {
            window.location.href = newLocation;
        }, pauseDuration);  // 2秒后跳转
    }
}

function setButtonDisabled() {
    button.textContent = "导航中";
    button.style.color = "#f0f0f0";
    button.disabled = true;
}

function pauseForTenMinutes() {
    stopScrolling();
    console.log("Pausing for 10 minutes...");
    setTimeout(function() {
        console.log("Resuming after pause...");
        startScrolling();
    }, 10 * 60 * 1000); // 10 minutes in milliseconds
}

// 添加“开始/停止”按钮
var button = document.createElement("button");
button.style.position = "fixed";
button.style.right = "15%";
button.style.bottom = "30%";
button.style.transform = "translateY(-50%)";
button.style.padding = "10px 20px";
button.style.fontSize = "20px";
button.style.backgroundColor = "white"; // 白色背景
button.style.border = "1px solid #ddd"; // 浅灰色边框
button.style.borderRadius = "5px"; // 圆角
button.style.color = "black";
button.textContent = "开始";
document.body.appendChild(button);

button.addEventListener("click", function() {
    if (isScrolling) {
        stopScrolling();
    } else {
        startScrolling();
    }
});

if (window.location.href.indexOf("/t/topic/") != -1) {
    // 如果在主题页面,默认就开始滚动
    startScrolling();
} else {
    findLinkAndRedirect();
    setButtonDisabled();
}