Greasy Fork is available in English.
提醒你保持正念,控制浏览网站的时间。按Ctrl+M查看设置。
- // ==UserScript==// @name 正念浏览控制 (Ctrl+M)// @namespace http://tampermonkey.net/// @version 1.3// @description 提醒你保持正念,控制浏览网站的时间。按Ctrl+M查看设置。// @author KQ yang// @match *://*/*// @license MIT// ==/UserScript==(function() {'use strict';// 默认配置const DEFAULT_CONFIG = {startHour: 12,endHour: 14,restrictedSites: {},messageStyle: "background-color: white; font-size:48px; color: #333; text-align: center; padding-top: 30vh;"};let CONFIG = JSON.parse(localStorage.getItem('mindfulnessConfig')) || DEFAULT_CONFIG;// 添加样式function addStyles() {const styleSheet = document.createElement("style");styleSheet.textContent = `.mindfulness-panel {position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);background: white;padding: 20px;border-radius: 10px;box-shadow: 0 10px 25px rgba(0,0,0,0.2);z-index: 999999;min-width: 300px;font-family: sans-serif;}.mindfulness-panel h2 {font-size: 24px;text-align: center;margin-bottom: 20px;color: #333;}.mindfulness-panel input[type="number"] {width: 50px;padding: 8px;margin-top: 10px;border: 1px solid #ddd;border-radius: 5px;font-size: 16px;}.mindfulness-panel .button-group {display: flex;justify-content: space-evenly;margin-top: 20px;}.mindfulness-panel button {padding: 8px 15px;border: none;border-radius: 5px;background-color: #4CAF50;color: white;font-size: 14px;cursor: pointer;}.mindfulness-panel button.cancel {background-color: #f44336;}.mindfulness-panel button:hover {opacity: 0.8;}`;document.head.appendChild(styleSheet);}// 创建配置面板function createConfigPanel() {const panel = document.createElement('div');panel.className = 'mindfulness-panel';const currentHost = window.location.hostname;const isRestricted = CONFIG.restrictedSites[currentHost];panel.innerHTML = `<h2>正念设置</h2><div>当前网站: ${currentHost}</div><div><label>限制网站:<input type="checkbox" id="restrictSite" ${isRestricted ? 'checked' : ''}></label></div><div><label>访问时间:</label><input type="number" id="startHour" value="${CONFIG.startHour}" min="0" max="23"> -<input type="number" id="endHour" value="${CONFIG.endHour}" min="0" max="23"></div><div class="button-group"><button id="saveConfig">保存</button><button class="cancel" id="cancelConfig">取消</button></div>`;panel.querySelector('#saveConfig').addEventListener('click', saveConfiguration);panel.querySelector('#cancelConfig').addEventListener('click', () => panel.remove());document.body.appendChild(panel);}// 保存配置function saveConfiguration() {const panel = document.querySelector('.mindfulness-panel');const currentHost = window.location.hostname;CONFIG.startHour = parseInt(panel.querySelector('#startHour').value);CONFIG.endHour = parseInt(panel.querySelector('#endHour').value);CONFIG.restrictedSites[currentHost] = panel.querySelector('#restrictSite').checked;localStorage.setItem('mindfulnessConfig', JSON.stringify(CONFIG));panel.remove();checkAndApplyRestriction();}// 检查并应用访问限制function checkAndApplyRestriction() {const currentHost = window.location.hostname;if (!CONFIG.restrictedSites[currentHost]) {return;}const now = new Date();const hours = now.getHours();if (hours < CONFIG.startHour || hours >= CONFIG.endHour) {document.body.innerHTML = `<div style="${CONFIG.messageStyle}"><h1>亲#的自己</h1><p>请回归正念,暂时离开此页面。</p><p>该站点仅可在 ${CONFIG.startHour}:00 - ${CONFIG.endHour}:00 之间访问。</p></div>`;}}// 监听快捷键document.addEventListener('keydown', function(e) {if (e.ctrlKey && e.key.toLowerCase() === 'm') {e.preventDefault();createConfigPanel();}});// 初始化addStyles();checkAndApplyRestriction();})();