Reddit - Waste Time Reminder

Simply shows a popup asking you if you want to keep wasting time on reddit every 10 minutes.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Reddit - Waste Time Reminder
// @description  Simply shows a popup asking you if you want to keep wasting time on reddit every 10 minutes.
// @namespace    https://azzurite.tv/
// @version      1.0
// @description  Reminds me to use less time on reddit
// @author       Azzurite
// @match        https://*.reddit.com/*
// @grant        none
// ==/UserScript==

(function() {
	'use strict';

	if (window.self !== window.top) {
		return;
	}

	const STARTED_BROWSING = `Azzu.startedBrowsing`;
	const MAX_BROWSING_TIME_MS = 10 * 60 * 1000;

	function getCurBrowseTime() {
		if (!localStorage.getItem(STARTED_BROWSING)) {
			localStorage.setItem(STARTED_BROWSING, Date.now());
		}

		return Date.now() - localStorage.getItem(STARTED_BROWSING);
	}

	function resetBrowseTime() {
		localStorage.setItem(STARTED_BROWSING, Date.now());
	}

	function keepBrowsingPrompt() {
		const wasteTime = confirm(`Do you want to waste more time browsing reddit?`);
		if (wasteTime) {
			resetBrowseTime();
		} else {
			close();
		}
	}

	function checkBrowseTime() {
		if (getCurBrowseTime() > MAX_BROWSING_TIME_MS) {
			keepBrowsingPrompt()
		}
		setTimeout(checkBrowseTime, 1000);
	}

	checkBrowseTime();
})();