一个好用的自律刷题插件

一个好用的自律刷题插件

不是我找的,是 Gemini 生成的

具体原理可以看注释

效果就是隐藏题解入口 10 分钟,然后提醒你可以看题解了再恢复入口(当然避免不了 F12 党与打链接的)

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// ==UserScript==
// @name 洛谷强制思考插件
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 进入题目20分钟后才允许查看题解
// @author You
// @match https://www.luogu.com.cn/problem/P*
// @grant none
// ==/UserScript==

(function() {
'use strict';
const WAIT_TIME = 10 * 60 * 1000; // 20分钟
const probId = window.location.pathname.split('/').pop();
const startTimeKey = `study_timer_${probId}`;

// 获取/设置本题开始时间
let startTime = localStorage.getItem(startTimeKey);
if (!startTime) {
startTime = Date.now();
localStorage.setItem(startTimeKey, startTime);
}

const checkTimer = setInterval(() => {
const elapsed = Date.now() - startTime;
// 定位“查看题解”按钮(洛谷的按钮类名可能会变,这里建议直接操作DOM)
const solutionBtn = document.querySelector('a[href*="solution"]');

if (solutionBtn) {
if (elapsed < WAIT_TIME) {
solutionBtn.style.display = 'none'; // 隐藏
// 可选:在按钮位置显示倒计时提示
} else {
solutionBtn.style.display = 'inline-block'; // 恢复
alert("10分钟到了,如果还没思路就看看题解吧!");
clearInterval(checkTimer);
}
}
}, 1000);
})();

时间可以自己改,这是油猴插件,有油猴的可以添加新脚本然后把这个拷贝进去再保存就可以了。没有油猴得先下载油猴。自律插件把。


一个好用的自律刷题插件
https://guaguaoier111.github.io/2026/04/22/一个好用的自律刷题插件/
作者
Guagua111
发布于
2026年4月22日
许可协议