Reddit-WasteTimeReminder

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

当前为 2021-02-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Reddit-WasteTimeReminder
// @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();
})();