二 · 如何开启强力学术模式
除了代码都是手机上写的,不喜勿喷qwq
原文链接 : https://www.luogu.com.cn/article/qz17qcj8 。
因为文中所说的 Gooreplacer 下载不了(主要是作者懒得想办法了),所以本人写了一个篡改猴插件。
// ==UserScript==
// @name 洛谷强力学术
// @namespace http://tampermonkey.net/
// @version 1.0
// @auther Yt_4245
// @description 强制聚焦学习相关网站
// @match *://*/*
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// 允许的白名单规则
const ALLOW_RULES = [
// 洛谷核心功能
/^https:\/\/(www\.)?luogu\.com\.cn\/?$/i, // 首页
/^https:\/\/(www\.)?luogu\.com\.cn\/problem(\/list)?/i, // 题目列表
// DeepSeek 系列
/^https?:\/\/.*\.?deepseek\.com\/.*/i,
// 豆包系列
/^https?:\/\/.*\.?doubao\.com\/.*/i,
// 百度核心学习功能
/^https:\/\/fanyi\.baidu\.com\/.*/i, // 翻译
/^https:\/\/www\.baidu\.com\/s\?.*wd=.*/i, // 搜索(含关键词)
/^https:\/\/(ai|chat|knowledge)\.baidu\.com\/.*/i // AI相关
];
// 智能路径检测
function shouldAllow() {
const currentURL = window.location.href.toLowerCase();
// 白名单匹配检测
if (ALLOW_RULES.some(regex => regex.test(currentURL))) {
return true;
}
// 特殊放行逻辑
if (currentURL.startsWith('https://www.luogu.com.cn/problem/')) {
return true; // 放行具体题目页
}
return false;
}
// 执行重定向逻辑
if (!shouldAllow()) {
// 保留原网站信息用于调试
console.warn('[学术模式] 拦截非学习网站:', window.location.href);
// 清除当前页面内容
document.documentElement.innerHTML = '';
// 跳转至洛谷题库
window.location.replace('https://www.luogu.com.cn/problem/list');
}
})();
脚本经过了 AI 修改和注解,然后英文都是机翻,所以有点丑。
目前功能:
- 屏蔽大部分外部网站。
- 同时匹配国内站和国外站。
- 洛谷功能仅保留做题和用户设置。
- 保留搜索引擎和三个 AI 。
- 使用正则表达式,清晰易懂(雾
要修改(比如保留学校内网)的话操作较为简单,实在不会可以扔给 AI。
私货:正则表达式好可爱呢(指
https\/\/
)