Reddit saved autoscroller

Script to scroll automatically to the bottom of Reddit's saved page

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Reddit saved autoscroller
// @match       https://www.reddit.com/user/*/saved*
// @grant       none
// @version     1.2.1
// @author      AdrianSkar
// @description Script to scroll automatically to the bottom of Reddit's saved page
// @namespace https://greasyfork.org/users/564765
// ==/UserScript==
/*jshint esversion: 6 */

(function () {
	setTimeout(() => {
		let isScrolling = false;
		let intervalId;
		let time;

		// Scroll fn
		function autoScroll(time) {
			isScrolling = true;
			intervalId = window.setInterval(() => {
				if (
					window.scrollY + window.screen.height >=
					document.body.scrollHeight
				) {
					alert('done scrolling');
					clearInterval(intervalId);
					isScrolling = false;
					toggleButtonText();
					return;
				} else window.scrollTo(0, document.body.scrollHeight);
			}, time);
		}

		// Stop scrolling
		function stopScroll() {
			clearInterval(intervalId);
			isScrolling = false;
			toggleButtonText();
		}

		// Toggle button text between "Start" and "Stop"
		function toggleButtonText() {
			const scrollButton = document.getElementById('scroll-button');
			if (isScrolling) {
				scrollButton.textContent = '⏹';
			} else {
				scrollButton.textContent = '↓';
			}
		}

		// Create and display new button
		const scrollButton = document.createElement('button');
		scrollButton.id = 'scroll-button';
		scrollButton.style = `
			position: fixed;
			background-color: rgba(250, 250, 250, 0.9);
			color: black;
			font-weight: bold;
			font-size: 1rem;
			bottom: 0.6rem;
			right: 6rem;
			padding: 0.4rem;
			border-radius: 11px;
			font-family: Noto Sans, Arial, sans-serif;
			z-index: 9;
		`;
		scrollButton.textContent = '↓';

		// Listen for click and perform autoScroll or stopScroll
		scrollButton.addEventListener('click', ev => {
			ev.preventDefault();
			if (isScrolling) {
				stopScroll();
			} else {
				time = time || prompt("Speed in ms (you'l get an alert when done):");
				autoScroll(time);
				toggleButtonText();
			}
		});

		document.body.appendChild(scrollButton);
	}, 2000);
})();