Coub.com Auto Scroll

Auto-scroll in Coub.com all 20 Seconds.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Coub.com Auto Scroll
// @namespace    coub-auto-scroll-h1ghsyst3m
// @version      0.6
// @license      MIT
// @description  Auto-scroll in Coub.com all 20 Seconds.
// @author       H1ghSyst3m
// @match        https://coub.com
// @match        https://coub.com/*
// @exclude      https://coub.com/view/*
// @exclude      https://coub.com/embed/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var scrollInterval;
    var intervalTime = 20000; // 20 seconds
    var isAutoScrollPaused = false;

    function setScrollInterval() {
        clearScrollInterval();
        if (!isAutoScrollPaused) {
            scrollInterval = setInterval(scrollNextCoub, intervalTime);
        }
    }

    function clearScrollInterval() {
        clearInterval(scrollInterval);
    }

    function scrollNextCoub() {
        var nextCoub = document.querySelector("div.coub.active").nextSibling;
        nextCoub.scrollIntoView({ behavior: 'smooth', block: 'end' });
        setScrollInterval();
    }

    function scrollPrevCoub() {
        var prevCoub = document.querySelector("div.coub.active").previousSibling;
        prevCoub.scrollIntoView({ behavior: 'smooth', block: 'end' });
        setScrollInterval();
    }

    function toggleAutoScroll() {
        isAutoScrollPaused = !isAutoScrollPaused;
        isAutoScrollPaused ? clearScrollInterval() : setScrollInterval();
        pauseButton.innerHTML = isAutoScrollPaused ? '▶' : '⏸';
    }

    // Add scroll controls
    var scrollDown = createButton('↓', scrollNextCoub);
    var scrollUp = createButton('↑', scrollPrevCoub);
    var pauseButton = createButton('⏸', toggleAutoScroll);

    // Utility function to create a button
    function createButton(symbol, onClickFunction) {
        var button = document.createElement("div");
        button.style = "position:fixed;z-index:9900;right:20px;bottom:100px;opacity:70%;background-color:#2196F3;color:white;border:2px solid white;font-weight:bold;display:flex;align-items:center;justify-content:center;width:50px;height:50px;border-radius:25px;font-size:20pt;cursor:pointer;margin-bottom:10px;";
        button.innerHTML = symbol;
        button.onclick = onClickFunction;
        document.body.appendChild(button);
        return button;
    }

    // Positioning the buttons
    scrollDown.style.bottom = '100px';
    scrollUp.style.bottom = '160px';
    pauseButton.style.bottom = '220px';

    // Initialize the auto-scroll interval
    setScrollInterval();
})();