// ==UserScript== // @name 简易专注模式 (Block Site Pure) // @namespace http://tampermonkey.net/ // @version 1.0 // @description 屏蔽特定网站,显示励志语录。不依赖任何外部库,轻量快速。 // @author werflala // @license MIT // @match *://*/* // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @grant GM_addStyle // @run-at document-start // @downloadURL none // ==/UserScript== (function() { 'use strict'; // ================= 配置区域 ================= // 默认显示的励志语录 const MOTTO_TITLE = "敢不敢,事上练"; const MOTTO_SUB = "选项: 练字、编程、阅读、运动"; // 样式:设置界面的CSS const UI_CSS = ` #block-site-settings-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 999999; display: flex; justify-content: center; align-items: center; font-family: sans-serif; } #block-site-settings-box { background: white; padding: 20px; border-radius: 8px; width: 400px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); } .bs-title { font-size: 18px; font-weight: bold; margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 5px;} .bs-textarea { width: 100%; height: 150px; margin-bottom: 10px; padding: 5px; box-sizing: border-box; } .bs-btn { padding: 5px 15px; cursor: pointer; border: none; border-radius: 4px; color: white; margin-right: 5px;} .bs-save { background: #409EFF; } .bs-close { background: #909399; } .bs-tip { font-size: 12px; color: #666; margin-bottom: 10px; } `; // 样式:拦截页面的CSS const BLOCK_CSS = ` body, html { margin: 0; padding: 0; height: 100%; overflow: hidden; background: #fdfdfd; } #block-focus-container { display: flex; flex-direction: column; justify-content: center; align-items: center; height: 100vh; font-family: "Microsoft YaHei", sans-serif; } .focus-title { font-size: 48px; color: #333; margin-bottom: 20px; font-weight: bold; letter-spacing: 2px;} .focus-sub { font-size: 24px; color: green; margin-bottom: 40px; } .focus-url { color: #999; font-size: 14px; } .unlock-btn { margin-top: 50px; opacity: 0; transition: opacity 2s; cursor: default; } .unlock-btn:hover { opacity: 1; cursor: pointer;} `; // ================= 逻辑区域 ================= // 1. 读取屏蔽列表 (存储为数组) function getBlockList() { return GM_getValue("blockList", []); } // 2. 检查当前网址是否在屏蔽列表中 function checkBlock() { const list = getBlockList(); const currentUrl = window.location.href; const currentHostname = window.location.hostname; for (let rule of list) { if (!rule) continue; // 简单的包含匹配,或者你可以写更复杂的正则 // 如果规则是 "bilibili.com",那么访问 "www.bilibili.com" 就会被拦截 if (currentHostname.includes(rule) || currentUrl.includes(rule)) { doBlockAction(rule); break; } } } // 3. 执行拦截动作 function doBlockAction(matchedRule) { console.log(`[Block Site] Blocked by rule: ${matchedRule}`); // 停止页面加载 (尽力而为) window.stop(); // 替换 Body 内容 const htmlContent = `