版本比较
插件
标题
增加 1 行删除 1 行
11LJM的好用插件插件正文
增加 1684 行删除 0 行
3,396 行未改动全部展开3397339833993400340134023403340434051,339 行未改动全部展开474547464747474847494750475147524753882 行未改动全部展开5636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073213,396 行未改动全部展开
在访问他人主页时,刷新一遍就会自动显示,无需保存站或国际站。在首页会增加输入用户名自动跳转主页的功能。此外,还有更多功能等你发现。
:::success[代码]```// ==UserScript==// @name Better Luogu!// @namespace https://www.luogu.com.cn/user/772464// @version 1.14.81,339 行未改动全部展开 } else jumpFlag=1; },1000);})();```:::
## 专栏导出PDF
882 行未改动全部展开 });})();```:::
## 点击特效
鼠标点击就有特效。
:::success[第一个]```// ==UserScript==// @name 点击特效// @namespace http://tampermonkey.net/// @version 1.12.3// @description Long press for surprises! Enjoy clicking ~// @author Super_Diu// @match *://*/*// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==// @grant none// @downloadURL https://update.greasyfork.org/scripts/565081/Amazing%20click%20effect%21.user.js// @updateURL https://update.greasyfork.org/scripts/565081/Amazing%20click%20effect%21.meta.js// ==/UserScript==
(function() { 'use strict';
function clickTriangleEffect() { let tris = []; // 存储三角形实例 let dots = []; // 存储长按蓄力小圆点实例 let cvs, ctx; // 画布和上下文 let w, h; // 画布宽高 // 纯蓝色系配色 const blueColors = ["#1E90FF", "#4169E1", "#00BFFF", "#87CEFA", "#6495ED", "#0099FF", "#7B68EE"]; // 三角形类型 const triTypes = ["acute", "right", "obtuse", "isosceles", "equilateral"]; // 尾迹轨迹点 const MAX_TRACK = 10; const DOT_TRACK = 5;
// 长按核心参数(0.8s触发蓄力) let pressStart = 0; let isPress = false; let px = 0, py = 0; const LONG_PRESS = 800; // 进阶特效上限 const MAX_SIZE = 20; const MAX_SPEED = 15; const MIN_ALPHA_SPEED = 8;
// 三角形数量随长按递增 const BASE_COUNT = 12; const MAX_COUNT = 30; const SCALE_DUR = 3000;
// 蓄力小圆点配置 const DOT_R_MIN = 1; const DOT_R_MAX = 3; const DOT_INTERVAL = 150; const DOT_INIT_SPD = 1.2; const DOT_ACCEL = 0.2; const DOT_ALPHA_SPD = 0.02; const DOT_FADE_BASE = 0.03; const DOT_SPAWN_R_MIN = 180; const DOT_SPAWN_R_MAX = 280; const SPEED_ALPHA_FACTOR = 0.0001; let lastDotSpawn = 0;
// 创建画布 cvs = document.createElement("canvas"); document.body.appendChild(cvs); cvs.setAttribute("style", "width: 100%; height: 100%; top: 0; left: 0; z-index: 99999; position: fixed; pointer-events: none;");
// 初始化画布 if (cvs.getContext && window.addEventListener) { ctx = cvs.getContext("2d"); updateCvsSize(); window.addEventListener('resize', updateCvsSize, false); requestAnimationFrame(loop);
// 鼠标事件 window.addEventListener("mousedown", function(e) { isPress = true; pressStart = Date.now(); px = e.clientX; py = e.clientY; lastDotSpawn = Date.now(); }, false); window.addEventListener("mouseup", createEffect, false); window.addEventListener("mouseout", function() { isPress = false; pressStart = 0; dots.forEach(dot => dot.needFade = true); }, false);
} else { console.log("当前浏览器不支持Canvas或addEventListener!"); }
// 画布大小更新 function updateCvsSize() { cvs.width = window.innerWidth * 2; cvs.height = window.innerHeight * 2; cvs.style.width = window.innerWidth + 'px'; cvs.style.height = window.innerHeight + 'px'; ctx.scale(2, 2); w = window.innerWidth; h = window.innerHeight; }
// 工具方法 function alphaToHex(alpha) { const hex = Math.floor(Math.max(0, Math.min(255, alpha * 255))).toString(16); return hex.length === 1 ? '0' + hex : hex; } function randInt(min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } function randFloat(min, max) { return Math.random() * (max - min) + min; }
// 生成三角形特效 function createEffect() { if (!isPress) return; const pressDur = Date.now() - pressStart; isPress = false; pressStart = 0; dots.forEach(dot => dot.needFade = true);
let sizeMin = 7, sizeMax = 13; let spdMin = 4, spdMax = 9; let alphaSpdMin = 25, alphaSpdMax = 35; let createCnt = BASE_COUNT;
if (pressDur >= LONG_PRESS) { const overThresh = pressDur - LONG_PRESS; const scale = Math.min(1, overThresh / SCALE_DUR); createCnt = Math.floor(BASE_COUNT + scale * (MAX_COUNT - BASE_COUNT)); sizeMax = 13 + scale * (MAX_SIZE - 13); spdMax = 9 + scale * (MAX_SPEED - 9); alphaSpdMin = 25 - scale * (25 - MIN_ALPHA_SPEED); alphaSpdMax = 35 - scale * (35 - MIN_ALPHA_SPEED); }
// 生成三角形 for (let i = 0; i < createCnt; i++) { const triSpd = randInt(spdMin, spdMax); let triAlphaSpd = randInt(alphaSpdMin, alphaSpdMax); triAlphaSpd = triAlphaSpd + triSpd * 2; triAlphaSpd = Math.min(triAlphaSpd, 50);
tris.push(new Triangle( px, py, randInt(sizeMin, sizeMax), triSpd, triAlphaSpd / 1000 )); } }
// 蓄力小圆点类 class Dot { constructor(tx, ty) { this.tx = tx; this.ty = ty; const r = randFloat(DOT_SPAWN_R_MIN, DOT_SPAWN_R_MAX); const angle = randFloat(0, Math.PI * 2); this.x = tx + Math.cos(angle) * r; this.y = ty + Math.sin(angle) * r; this.r = randFloat(DOT_R_MIN, DOT_R_MAX); this.color = blueColors[Math.floor(Math.random() * blueColors.length)]; this.alpha = 0; this.spd = DOT_INIT_SPD; this.accel = DOT_ACCEL; this.needFade = false; this.angle = Math.atan2(ty - this.y, tx - this.x); this.track = []; this.arrived = false; }
addTrack() { if (this.arrived) return; this.track.push({ x: this.x, y: this.y, alpha: this.alpha, r: this.r }); if (this.track.length > DOT_TRACK) this.track.shift(); }
update() { if (this.arrived) { this.alpha = 0; return; } this.addTrack();
// 速度关联显隐/消失速度 const spdFactor = 1 + this.spd * SPEED_ALPHA_FACTOR; if (this.needFade) { this.alpha = Math.max(0, this.alpha - DOT_FADE_BASE * spdFactor); } else { this.alpha = Math.min(1, this.alpha + DOT_ALPHA_SPD * spdFactor); }
// 不让蓄力特效穿过鼠标的判定逻辑 const dx = this.tx - this.x; const dy = this.ty - this.y; const dist = Math.sqrt(dx * dx + dy * dy); const nextStep = this.spd + this.accel;
if (dist <= this.r * 3 || nextStep >= dist) { this.arrived = true; this.alpha = 0; this.track = []; this.x = this.tx; this.y = this.ty; } else { this.spd += this.accel; this.spd = Math.min(this.spd, 8); this.x += Math.cos(this.angle) * this.spd; this.y += Math.sin(this.angle) * this.spd; } }
drawTrail() { if (this.track.length < 2 || this.alpha <= 0 || this.arrived) return; ctx.save(); ctx.beginPath(); ctx.moveTo(this.track[0].x, this.track[0].y); for (let i = 1; i < this.track.length; i++) { ctx.lineTo(this.track[i].x, this.track[i].y); } const lineW = this.r * 0.3; if (lineW <= 0) return; const grad = ctx.createLinearGradient( this.track[0].x, this.track[0].y, this.track[this.track.length-1].x, this.track[this.track.length-1].y ); grad.addColorStop(0, `${this.color}1A`); grad.addColorStop(1, `${this.color}${alphaToHex(Math.min(0.6, this.alpha))}`); ctx.lineWidth = lineW; ctx.lineCap = "butt"; ctx.lineJoin = "miter"; ctx.strokeStyle = grad; ctx.stroke(); ctx.restore(); }
draw() { if (this.alpha <= 0 || this.arrived) return; this.drawTrail(); ctx.save(); ctx.globalAlpha = this.alpha; ctx.fillStyle = this.color; ctx.beginPath(); ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2); ctx.closePath(); ctx.fill(); ctx.restore(); } }
// 三角形类 class Triangle { constructor(x, y, size, spd, alphaSpd) { this.x = x; this.y = y; this.angle = Math.random() * Math.PI * 2; this.spd = spd; this.rotSpd = (Math.random() - 0.5) * 18; this.rot = 0; this.size = size; this.color = blueColors[Math.floor(Math.random() * blueColors.length)]; this.type = triTypes[Math.floor(Math.random() * triTypes.length)]; this.alpha = 1; this.alphaSpd = alphaSpd; this.sizeSpd = randInt(5, 12) / 100; this.track = []; }
update() { this.addTrack(); this.x += Math.cos(this.angle) * this.spd; this.y += Math.sin(this.angle) * this.spd; this.rot += this.rotSpd; this.size = Math.max(1, this.size - this.sizeSpd); this.alpha = Math.max(0, this.alpha - this.alphaSpd); }
addTrack() { this.track.push({ x: this.x, y: this.y, size: this.size, alpha: this.alpha }); if (this.track.length > MAX_TRACK) this.track.shift(); }
// 绘制单个三角形 drawSingle(ctx, x, y, rot, size, alpha) { if (alpha <= 0 || size <= 0) return; ctx.save(); ctx.globalAlpha = alpha; ctx.translate(x, y); ctx.rotate(rot * Math.PI / 180); ctx.fillStyle = this.color; ctx.beginPath(); switch (this.type) { case "acute": ctx.moveTo(0, -size); ctx.lineTo(size * 0.7, size * 0.6); ctx.lineTo(-size * 0.7, size * 0.6); break; case "right": ctx.moveTo(0, -size * 0.8); ctx.lineTo(size * 0.8, size * 0.8); ctx.lineTo(-size * 0.8, size * 0.8); break; case "obtuse": ctx.moveTo(0, -size); ctx.lineTo(size * 1.0, size * 0.4); ctx.lineTo(-size * 1.0, size * 0.4); break; case "isosceles": ctx.moveTo(0, -size); ctx.lineTo(size * 0.6, size * 0.8); ctx.lineTo(-size * 0.6, size * 0.8); break; case "equilateral": const h = size * Math.sqrt(3) / 2; ctx.moveTo(0, -h / 2); ctx.lineTo(size / 2, h / 2); ctx.lineTo(-size / 2, h / 2); break; } ctx.closePath(); ctx.fill(); ctx.restore(); }
// 绘制尾迹 drawTrail(ctx) { if (this.track.length < 2 || this.alpha <= 0) return;
const trackCnt = this.track.length; const startP = this.track[0]; const endP = this.track[trackCnt - 1];
// 计算尾迹方向和长度 const trailAngle = Math.atan2(endP.y - startP.y, endP.x - startP.x); const trailLen = Math.sqrt( Math.pow(endP.x - startP.x, 2) + Math.pow(endP.y - startP.y, 2) ); const endW = endP.size * 0.3; // 宽边(朝向三角形):从0.6→0.3 const startW = endW * 0.05; // 窄边(尾迹末端):从0.1→0.05
ctx.save(); // 构建尾迹路径 const endLX = endP.x + Math.cos(trailAngle + Math.PI / 2) * endW; const endLY = endP.y + Math.sin(trailAngle + Math.PI / 2) * endW; const endRX = endP.x + Math.cos(trailAngle - Math.PI / 2) * endW; const endRY = endP.y + Math.sin(trailAngle - Math.PI / 2) * endW; const startX = startP.x + Math.cos(trailAngle) * startW; const startY = startP.y + Math.sin(trailAngle) * startW;
// 绘制路径 ctx.beginPath(); ctx.moveTo(endLX, endLY); ctx.lineTo(endRX, endRY); ctx.lineTo(startX, startY); ctx.closePath();
// 渐变填充 const grad = ctx.createLinearGradient( endP.x, endP.y, startP.x, startP.y ); grad.addColorStop(0, `${this.color}${alphaToHex(Math.min(0.4, this.alpha))}`); grad.addColorStop(1, `${this.color}10`); ctx.fillStyle = grad; ctx.fill(); ctx.restore(); }
draw() { if (this.alpha <= 0) return; this.drawTrail(ctx); this.drawSingle(ctx, this.x, this.y, this.rot, this.size, this.alpha); } }
// 动画循环 function loop() { ctx.clearRect(0, 0, w, h); if (isPress) { const pressDur = Date.now() - pressStart; if (pressDur >= LONG_PRESS) { const now = Date.now(); if (now - lastDotSpawn >= DOT_INTERVAL) { dots.push(new Dot(px, py)); lastDotSpawn = now; } } } // 圆点更新绘制 dots.forEach(dot => dot.update()); dots.forEach(dot => dot.draw()); dots = dots.filter(dot => dot.alpha > 0 && !dot.arrived); // 三角形更新绘制 tris.forEach(tri => tri.update()); tris.forEach(tri => tri.draw()); tris = tris.filter(tri => tri.alpha > 0);
requestAnimationFrame(loop); } }
// 调用特效 clickTriangleEffect();})();
```:::
:::success[第二个]```// ==UserScript==// @name 鼠标点击特效// @namespace http://tampermonkey.net/// @version 0.1// @description try to take over the world!// @author You// @match *://*/*// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==// @grant none// ==/UserScript==
(function() { 'use strict'; // Your code here...function clickEffect() { let balls = []; let longPressed = false; let longPress; let multiplier = 0; let width, height; let origin; let normal; let ctx; const colours = ["#F73859", "#14FFEC", "#00E0FF", "#FF99FE", "#FAF15D"]; const canvas = document.createElement("canvas"); document.body.appendChild(canvas); canvas.setAttribute("style", "width: 100%; height: 100%; top: 0; left: 0; z-index: 99999; position: fixed; pointer-events: none;"); const pointer = document.createElement("span"); pointer.classList.add("pointer"); document.body.appendChild(pointer);
if (canvas.getContext && window.addEventListener) { ctx = canvas.getContext("2d"); updateSize(); window.addEventListener('resize', updateSize, false); loop(); window.addEventListener("mousedown", function(e) { pushBalls(randBetween(10, 20), e.clientX, e.clientY); document.body.classList.add("is-pressed"); longPress = setTimeout(function(){ document.body.classList.add("is-longpress"); longPressed = true; }, 500); }, false); window.addEventListener("mouseup", function(e) { clearInterval(longPress); if (longPressed == true) { document.body.classList.remove("is-longpress"); pushBalls(randBetween(50 + Math.ceil(multiplier), 100 + Math.ceil(multiplier)), e.clientX, e.clientY); longPressed = false; } document.body.classList.remove("is-pressed"); }, false); window.addEventListener("mousemove", function(e) { let x = e.clientX; let y = e.clientY; pointer.style.top = y + "px"; pointer.style.left = x + "px"; }, false); } else { console.log("canvas or addEventListener is unsupported!"); }
function updateSize() { canvas.width = window.innerWidth * 2; canvas.height = window.innerHeight * 2; canvas.style.width = window.innerWidth + 'px'; canvas.style.height = window.innerHeight + 'px'; ctx.scale(2, 2); width = (canvas.width = window.innerWidth); height = (canvas.height = window.innerHeight); origin = { x: width / 2, y: height / 2 }; normal = { x: width / 2, y: height / 2 }; } class Ball { constructor(x = origin.x, y = origin.y) { this.x = x; this.y = y; this.angle = Math.PI * 2 * Math.random(); if (longPressed == true) { this.multiplier = randBetween(14 + multiplier, 15 + multiplier); } else { this.multiplier = randBetween(6, 12); } this.vx = (this.multiplier + Math.random() * 0.5) * Math.cos(this.angle); this.vy = (this.multiplier + Math.random() * 0.5) * Math.sin(this.angle); this.r = randBetween(8, 12) + 3 * Math.random(); this.color = colours[Math.floor(Math.random() * colours.length)]; } update() { this.x += this.vx - normal.x; this.y += this.vy - normal.y; normal.x = -2 / window.innerWidth * Math.sin(this.angle); normal.y = -2 / window.innerHeight * Math.cos(this.angle); this.r -= 0.3; this.vx *= 0.9; this.vy *= 0.9; } }
function pushBalls(count = 1, x = origin.x, y = origin.y) { for (let i = 0; i < count; i++) { balls.push(new Ball(x, y)); } }
function randBetween(min, max) { return Math.floor(Math.random() * max) + min; }
function loop() { ctx.fillStyle = "rgba(255, 255, 255, 0)"; ctx.clearRect(0, 0, canvas.width, canvas.height); for (let i = 0; i < balls.length; i++) { let b = balls[i]; if (b.r < 0) continue; ctx.fillStyle = b.color; ctx.beginPath(); ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2, false); ctx.fill(); b.update(); } if (longPressed == true) { multiplier += 0.2; } else if (!longPressed && multiplier >= 0) { multiplier -= 0.4; } removeBall(); requestAnimationFrame(loop); }
function removeBall() { for (let i = 0; i < balls.length; i++) { let b = balls[i]; if (b.x + b.r < 0 || b.x - b.r > width || b.y + b.r < 0 || b.y - b.r > height || b.r < 0) { balls.splice(i, 1); } } }}clickEffect();//调用特效函数
})();```:::
## 随机跳题
[原文链接](https://www.luogu.me/article/0v7tv27r)
:::success[代码]```/*MIT License
Copyright (c) 2026 karsl
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.*/// ==UserScript==// @name 洛谷随机跳题// @namespace http://tampermonkey.net/// @version 1.0// @description 筛选题库、难度、标签后随机跳题// @author karsl// @match https://www.luogu.com.cn/// @match https://www.luogu.com.cn// @icon https://www.luogu.com.cn/favicon.ico// @grant GM_xmlhttpRequest// @connect www.luogu.com.cn// ==/UserScript==
(function() { 'use strict';
const DIFFICULTY_MAP = { 0: '暂未评定', 1: '入门', 2: '普及-', 3: '普及', 4: '普及+/提高-', 5: '提高', 6: '提高+/省选-', 7: '省选/NOI-', 8: 'NOI/NOI+/CTS' };
const TYPE_MAP = { '洛谷': 'luogu', '主题库': 'P', '入门与面试': 'B', 'Codeforces': 'CF', 'SPOJ': 'SP', 'AtCoder': 'AT', 'UVa': 'UVA' }; const TYPE_KEYS = Object.keys(TYPE_MAP);
const dimensionMaps = { algorithm: { '语言入门': '-2', '字符串': '2', '后缀自动机 SAM': '101', '字典树 Trie': '300', 'AC 自动机': '301', 'KMP 算法': '302', '后缀数组 SA': '303', '后缀树': '304', '有限状态自动机': '305', '回文自动机 PAM': '325', 'Manacher 算法': '329', '顺序结构': '353', '分支结构': '354', '循环结构': '355', '数组': '356', '字符串(入门)': '357', '结构体': '358', '函数与递归': '359', 'Lyndon 分解': '419', 'Z 函数': '474', '动态规划 DP': '3', '搜索': '4', '广度优先搜索 BFS': '126', '深度优先搜索 DFS': '127', '剪枝': '128', '记忆化搜索': '129', '启发式搜索': '130', '迭代加深搜索': '131', '启发式迭代加深搜索 IDA*': '132', 'Dancing Links': '133', '爬山算法 Local search': '134', '模拟退火': '135', '背包 DP': '139', '数位 DP': '141', '区间 DP': '144', '树形 DP': '152', '轮廓线 DP': '323', '线性 DP': '444', '状压 DP': '464', '后缀平衡树': '496', '数学': '5', '图论': '6', 'Kruskal 重构树': '68', '网络流': '79', '信息论': '122', '随机调整': '136', '遗传算法': '137', '图论建模': '155', '图遍历': '158', '拓扑排序': '159', '最短路': '160', '生成树': '166', '平面图': '172', '最小环': '173', 'A* 算法': '263', '折半搜索 meet in the middle': '380', '梯度下降法': '396', '拉格朗日乘数法': '412', '拉格朗日插值法': '417', '单位根反演': '480', '负权环': '174', '连通块': '175', '2-SAT': '176', '平面图欧拉公式': '177', '强连通分量': '179', 'Tarjan': '180', '双连通分量': '181', '欧拉回路': '182', '差分约束': '185', '仙人掌': '186', '二分图': '187', '一般图的最大匹配': '189', '上下界网络流': '197', '最小割': '198', '费用流': '204', '圆方树': '350', '弦图': '450', 'Floyd 算法': '476', '广义串并联图': '530', 'Hall 定理': '541', '计算几何': '8', '树形数据结构': '11', '线段树': '42', '并查集': '47', '平衡树': '50', '堆': '51', '树状数组': '53', 'cdq 分治': '100', '可并堆': '215', '动态树 LCT': '229', '三维计算几何': '283', '向量': '286', '凸包': '291', '叉积': '292', '线段相交': '293', '半平面交': '295', '旋转卡壳': '299', '极角排序': '449', '平面几何': '482', '闵可夫斯基和 Minkowski sum': '525', '博弈论': '13', '线性数据结构': '44', '单调队列': '56', '颜色段均摊(珂朵莉树 ODT)': '65', '树套树': '232', '可持久化线段树': '233', '可持久化': '234', '前缀和': '254', '栈': '287', '队列': '288', '博弈树': '311', '整体二分': '316', 'K-D Tree': '321', 'Nim 积': '370', '李超线段树': '377', '吉司机线段树 segment tree beats': '378', '线段树合并': '379', 'SG 函数': '445', '二区间合并(猫树分治)': '531', 'KTT / Kinetic Tournament Tree': '539', '原根': '66', '多项式': '69', '数论': '72', '素数判断': '239', '最大公约数 gcd': '241', '扩展欧几里德算法': '242', '不定方程': '243', '进制': '244', '分块': '289', 'ST 表': '290', '快速傅里叶变换 FFT': '313', '快速数论变换 NTT': '324', '快速沃尔什变换 FWT': '326', '快速莫比乌斯变换 FMT': '327', '差分': '330', '链表': '360', '单调栈': '385', 'Berlekamp-Massey(BM) 算法': '391', '集合幂级数,子集卷积': '416', '哈希表': '473', '模拟': '1', '贪心': '7', '基础算法': '110', '中国剩余定理 CRT': '250', '莫比乌斯反演': '251', '逆元': '276', 'Lucas 定理': '322', '类欧几里得算法': '388', '调和级数': '411', '欧拉降幂': '415', 'Stern-Brocot 树': '423', '整除分块': '448', 'Dirichlet 卷积': '451', '大步小步算法 BSGS': '452', '二次剩余': '453', 'Bézout 定理': '455', '杜教筛': '461', '欧拉函数': '462', '线性筛法': '475', '亚线性快速求和算法': '540', '递推': '12', '倍增': '43', '二分': '45', '递归': '54', '枚举': '111', '分治': '112', '排序': '113', '动态规划优化': '146', '优先队列': '148', '矩阵加速': '149', '斜率优化': '150', '状态合并': '151', '凸完全单调性(wqs 二分)': '153', '四边形不等式': '154', 'DP 套 DP': '435', '动态 DP': '443', '决策单调性': '463', 'STL': '504', '整体转移': '507', '斜率维护技巧 slope trick': '508', '点分治': '49', '树上启发式合并': '55', '树的遍历': '208', '最近公共祖先 LCA': '211', '树的直径': '213', '树链剖分': '228', '树论': '230', '群论': '246', '置换': '247', 'Pólya 定理': '248', '虚树': '249', '组合数学': '252', '排列组合': '253', '二项式定理': '255', '康托展开': '256', '基环树': '320', '动态树分治': '382', 'Prüfer 序列': '410', '全局平衡二叉树': '472', '树的重心': '483', 'LGV 引理': '63', '矩阵树定理': '64', '矩阵运算': '71', '鸽笼原理': '258', '容斥原理': '259', 'Fibonacci 数列': '260', 'Catalan 数': '261', 'Stirling 数': '262', '生成函数': '264', '概率论': '266', '期望': '270', '线性代数': '271', '矩阵乘法': '272', '线性递推': '273', '高斯消元': '274', 'Dilworth 定理': '364', '拉格朗日反演': '372', '杨表': '387', '随机游走 Markov Chain': '457', '鞅的停时定理': '458', '暴力数据结构': '9', '高精度': '10', '莫队': '41', '三分': '67', '离散化': '78', '霍夫曼树': '214', '哈希 hashing': '235', '线性基': '277', '微积分': '278', '导数': '280', '积分': '281', '定积分': '282', '级数': '284', '扫描线': '298', '其它技巧': '308', '随机化': '309', '位运算': '314', '构造': '318', '行列式': '454', '特征值': '466', '分数规划': '202', '线性规划': '265', '双指针 two-pointer': '345', 'Ad-hoc': '365', '笛卡尔树': '368', '拟阵': '369', '根号分治': '371', '模拟费用流': '373', '分散层叠': '374', '均摊分析': '375', '分类讨论': '376', '近似算法': '413', '线段树分治': '446', '离线处理': '447', 'bitset': '465', '组合优化': '467', '整数规划': '468', '原始对偶': '470', '启发式合并': '477', '反悔贪心': '524', '最大流最小割定理': '471', '保序回归': '484' }, source: { '各省省选': '48', '集训队互测': '52', '福建省历届夏令营': '70', 'NOI': '77', 'NOIP 普及组': '82', 'NOIP 提高组': '83', 'APIO': '85', 'NOI 导刊': '99', 'CTT(清华集训/北大集训)': '331', '网络流与线性规划 24 题': '332', 'CSP-S 提高级': '342', 'CSP-J 入门级': '343', 'NOI Online': '347', 'Ynoi': '348', 'NOI 系列赛事': '426', '经典套题': '427', '国际知名赛事': '428', 'WC': '459', 'CTSC/CTS': '460', '模板题': '523', 'USACO': '46', 'POI(波兰)': '57', 'IOI': '102', 'CCO(加拿大)': '115', 'CCC(加拿大)': '116', 'CEOI(中欧)': '117', 'eJOI(欧洲)': '118', 'COCI(克罗地亚)': '333', 'BalticOI(波罗的海)': '334', 'JOI(日本)': '336', 'AGM': '346', 'PA(波兰)': '389', 'ROI(俄罗斯)': '393', 'EGOI(欧洲/女生)': '394', 'NOISG(新加坡)': '436', 'NordicOI(北欧)': '437', 'BalkanOI(巴尔干半岛)': '439', 'KOI(韩国)': '440', 'RMI(罗马尼亚)': '441', 'COI(克罗地亚)': '478', '洛谷原创': '81', 'ICPC': '335', '洛谷月赛': '337', '语言月赛': '386', '洛谷比赛': '429', '大学竞赛': '430', 'ROIR(俄罗斯)': '479', 'INOI(伊朗)': '505', 'UOI(乌克兰)': '506', 'JOISC/JOIST(日本)': '512', 'COTS(克罗地亚)': '513', 'Google Code Jam': '514', 'Moscow Olympiad': '515', 'PO(瑞典)': '518', 'PAIO': '519', 'MCC/MCO(马来西亚)': '533', 'KTSC(韩国)': '535', 'IATI(保加利亚/东欧)': '537', 'Google Kick Start': '538', '入门赛': '542', '蓝桥杯国赛': '361', '蓝桥杯省赛': '363', '省赛/邀请赛': '381', '传智杯': '383', 'THUPC': '390', 'GESP': '409', '其他竞赛': '431', 'THUSC': '432', '高校校赛': '434', 'THUWC': '438', 'CSP-X 小学组': '442', 'Code+': '485', '梦熊比赛': '486', '信息与未来': '487', '科创活动': '488', 'BCSP-X': '489', '小学活动': '492', '初中活动': '493', 'CSPro': '516', 'CCPC': '526', '科大国创杯': '494', '蓝桥杯青少年组': '495' }, time: { '1996': '344', '1997': '14', '1998': '15', '1999': '16', '2000': '17', '2001': '18', '2002': '19', '2003': '20', '2004': '21', '2005': '22', '2006': '23', '2007': '24', '2008': '25', '2009': '26', '2010': '27', '2011': '28', '2012': '29', '2013': '30', '2014': '31', '2015': '32', '2016': '33', '2017': '34', '2018': '35', '2019': '36', '2020': '37', '2021': '58', '2022': '59', '2023': '60', '2024': '61', '2025': '62', '2026': '338', '2027': '339', '2028': '340', '2029': '367', '2077': '341', '2078': '362', '2079': '424' }, region: { '重庆': '38', '四川': '39', '河南': '40', '浙江': '88', '上海': '89', '福建': '90', '江苏': '91', '安徽': '92', '湖南': '93', '北京': '94', '河北': '95', '广东': '96', '山东': '97', '吉林': '98', '山西': '114', '江西': '161', '贵州': '162', '广西': '163', '陕西': '164', '国内省市': '497', '辽宁': '167', '云南': '168', '天津': '328', '湖北': '397', '黑龙江': '398', '海南': '399', '甘肃': '400', '青海': '401', '台湾': '402', '内蒙古': '403', '西藏': '404', '宁夏': '405', '新疆': '406', '香港': '407', '澳门': '408', '济南': '420', '南京': '421', '青岛': '422', '国内赛站': '498', 'EC Final': '509', '国际赛区': '499', 'NERC/NEERC': '500', 'SEERC': '501', 'CERC': '502', 'NWRRC': '503', 'WF': '510', 'NAC': '511', '杭州': '520', '昆明': '521', '西安': '522', '哈尔滨': '527', '首尔': '528', '横浜': '529', 'SWERC': '532', '成都': '534', '雅加达': '536' }, special: { '交互题': '103', '提交答案': '104', 'Special Judge': '107', 'O2优化': '108', '通信题': '351' } };
const DIMENSION_NAMES = { algorithm: '算法', source: '来源', time: '时间', region: '区域', special: '特殊题目' }; const DIMENSION_KEYS = ['algorithm', 'source', 'time', 'region', 'special'];
const STORAGE_KEY = 'luogu_random_jump_settings';
let selectedTypes = new Set(); let selectedDifficulties = new Set(); let selectedTags = { algorithm: new Set(), source: new Set(), time: new Set(), region: new Set(), special: new Set() };
let filterAccepted = false; let filterSubmitted = false;
function loadSettings() { try { const raw = localStorage.getItem(STORAGE_KEY); if (!raw) return; const data = JSON.parse(raw); if (data.types) { selectedTypes = new Set(data.types); } if (data.difficulties) { selectedDifficulties = new Set(data.difficulties); } if (data.tags) { DIMENSION_KEYS.forEach(key => { if (data.tags[key] && Array.isArray(data.tags[key])) { selectedTags[key] = new Set(data.tags[key]); } }); } if (typeof data.filterAccepted === 'boolean') { filterAccepted = data.filterAccepted; } if (typeof data.filterSubmitted === 'boolean') { filterSubmitted = data.filterSubmitted; } } catch (e) { console.warn('读取存储失败', e); } }
function saveSettings() { const data = { types: Array.from(selectedTypes), difficulties: Array.from(selectedDifficulties), tags: {}, filterAccepted: filterAccepted, filterSubmitted: filterSubmitted }; DIMENSION_KEYS.forEach(key => { data.tags[key] = Array.from(selectedTags[key]); }); localStorage.setItem(STORAGE_KEY, JSON.stringify(data)); }
loadSettings();
function createFloatingPanel(button) { const panel = document.createElement('div'); panel.style.cssText = ` position: absolute; bottom: calc(100% + 10px); right: 0; background: #fff; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.08); padding: 16px 18px; width: 300px; max-height: 480px; overflow-y: auto; border: 1px solid #eee; z-index: 10000; display: none; font-size: 13px; line-height: 1.5; color: #333; `;
const typeTitle = document.createElement('div'); typeTitle.textContent = '题库'; typeTitle.style.cssText = 'font-weight:600; font-size:14px; margin-bottom:8px; color:#111;'; panel.appendChild(typeTitle);
const typeContainer = document.createElement('div'); typeContainer.style.cssText = 'display:grid; grid-template-columns:1fr 1fr; gap:4px 10px; margin-bottom:16px;'; TYPE_KEYS.forEach(displayName => { const typeValue = TYPE_MAP[displayName]; const labelEl = document.createElement('label'); labelEl.style.cssText = 'display:flex; align-items:center; padding:3px 6px; cursor:pointer; border-radius:6px; transition:background 0.15s;'; labelEl.onmouseenter = () => { labelEl.style.background = '#f5f7fa'; }; labelEl.onmouseleave = () => { labelEl.style.background = 'transparent'; };
const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.value = typeValue; checkbox.style.cssText = 'margin-right:6px; width:15px; height:15px; accent-color:#4f8ef7; cursor:pointer;'; checkbox.checked = selectedTypes.has(typeValue); checkbox.addEventListener('change', function() { const val = this.value; if (this.checked) selectedTypes.add(val); else selectedTypes.delete(val); saveSettings(); });
const span = document.createElement('span'); span.textContent = displayName; span.style.fontSize = '12px';
labelEl.appendChild(checkbox); labelEl.appendChild(span); typeContainer.appendChild(labelEl); }); panel.appendChild(typeContainer);
const diffTitle = document.createElement('div'); diffTitle.textContent = '难度'; diffTitle.style.cssText = 'font-weight:600; font-size:14px; margin-bottom:8px; color:#111;'; panel.appendChild(diffTitle);
const diffContainer = document.createElement('div'); diffContainer.style.cssText = 'display:grid; grid-template-columns:1fr 1fr; gap:4px 10px; margin-bottom:16px;'; Object.entries(DIFFICULTY_MAP).forEach(([value, label]) => { const labelEl = document.createElement('label'); labelEl.style.cssText = 'display:flex; align-items:center; padding:3px 6px; cursor:pointer; border-radius:6px; transition:background 0.15s;'; labelEl.onmouseenter = () => { labelEl.style.background = '#f5f7fa'; }; labelEl.onmouseleave = () => { labelEl.style.background = 'transparent'; };
const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.value = value; checkbox.style.cssText = 'margin-right:6px; width:15px; height:15px; accent-color:#4f8ef7; cursor:pointer;'; checkbox.checked = selectedDifficulties.has(parseInt(value)); checkbox.addEventListener('change', function() { const val = parseInt(this.value); if (this.checked) selectedDifficulties.add(val); else selectedDifficulties.delete(val); saveSettings(); });
const span = document.createElement('span'); span.textContent = label; span.style.fontSize = '12px';
labelEl.appendChild(checkbox); labelEl.appendChild(span); diffContainer.appendChild(labelEl); }); panel.appendChild(diffContainer);
const filterTitle = document.createElement('div'); filterTitle.textContent = '筛选'; filterTitle.style.cssText = 'font-weight:600; font-size:14px; margin-bottom:8px; color:#111;'; panel.appendChild(filterTitle);
const filterContainer = document.createElement('div'); filterContainer.style.cssText = 'display:flex; flex-direction:column; gap:6px; margin-bottom:16px;';
const createFilterCheckbox = (text, getter, setter) => { const label = document.createElement('label'); label.style.cssText = 'display:flex; align-items:center; padding:3px 6px; cursor:pointer; border-radius:6px; transition:background 0.15s;'; label.onmouseenter = () => { label.style.background = '#f5f7fa'; }; label.onmouseleave = () => { label.style.background = 'transparent'; };
const checkbox = document.createElement('input'); checkbox.type = 'checkbox'; checkbox.style.cssText = 'margin-right:6px; width:15px; height:15px; accent-color:#4f8ef7; cursor:pointer;'; checkbox.checked = getter; checkbox.addEventListener('change', function() { setter(this.checked); saveSettings(); });
const span = document.createElement('span'); span.textContent = text; span.style.fontSize = '12px';
label.appendChild(checkbox); label.appendChild(span); return label; };
filterContainer.appendChild(createFilterCheckbox('仅显示未 AC', filterAccepted, val => { filterAccepted = val; })); filterContainer.appendChild(createFilterCheckbox('仅显示未尝试', filterSubmitted, val => { filterSubmitted = val; })); panel.appendChild(filterContainer);
DIMENSION_KEYS.forEach(dimKey => { const dimName = DIMENSION_NAMES[dimKey] || dimKey; const map = dimensionMaps[dimKey] || {}; const tagSet = selectedTags[dimKey];
const section = document.createElement('div'); section.style.cssText = 'margin-bottom:14px;';
const header = document.createElement('div'); header.textContent = dimName; header.style.cssText = 'font-weight:600; font-size:13px; color:#222; margin-bottom:4px;'; section.appendChild(header);
const selectedContainer = document.createElement('div'); selectedContainer.style.cssText = 'display:flex; flex-wrap:wrap; gap:4px; margin-bottom:4px;'; section.appendChild(selectedContainer);
function updateSelectedDisplay() { selectedContainer.innerHTML = ''; if (tagSet.size === 0) { selectedContainer.style.display = 'none'; return; } selectedContainer.style.display = 'flex'; tagSet.forEach(tagId => { let name = null; for (const [n, id] of Object.entries(map)) { if (id === tagId) { name = n; break; } } const displayName = name || `ID:${tagId}`; const tagEl = document.createElement('span'); tagEl.style.cssText = ` display:inline-flex; align-items:center; background:#eef3ff; color:#2b5cd9; padding:2px 10px; border-radius:14px; font-size:11px; gap:4px; `; const nameSpan = document.createElement('span'); nameSpan.textContent = displayName; const removeBtn = document.createElement('span'); removeBtn.textContent = '×'; removeBtn.style.cssText = 'cursor:pointer; font-weight:700; color:#7a8bb0; font-size:14px;'; removeBtn.onclick = (e) => { e.stopPropagation(); tagSet.delete(tagId); updateSelectedDisplay(); saveSettings(); }; tagEl.appendChild(nameSpan); tagEl.appendChild(removeBtn); selectedContainer.appendChild(tagEl); }); } updateSelectedDisplay();
const wrapper = document.createElement('div'); wrapper.style.cssText = 'position:relative;';
const input = document.createElement('input'); input.type = 'text'; input.placeholder = `搜索 ${dimName}`; input.style.cssText = ` width:100%; padding:4px 10px; border:1px solid #ddd; border-radius:6px; font-size:12px; outline:none; transition:border 0.15s; box-sizing:border-box; `; input.onfocus = () => { input.style.borderColor = '#4f8ef7'; }; input.onblur = () => { input.style.borderColor = '#ddd'; }; wrapper.appendChild(input);
const suggestionBox = document.createElement('div'); suggestionBox.style.cssText = ` position:absolute; top:100%; left:0; right:0; background:#fff; border:1px solid #ddd; border-top:none; border-radius:0 0 6px 6px; max-height:120px; overflow-y:auto; display:none; z-index:10001; box-shadow:0 4px 12px rgba(0,0,0,0.05); `; wrapper.appendChild(suggestionBox);
input.addEventListener('input', function() { const query = this.value.trim().toLowerCase(); if (!query) { suggestionBox.style.display = 'none'; return; } const matches = []; for (const [name, id] of Object.entries(map)) { if (name.toLowerCase().includes(query)) { if (!matches.some(m => m.id === id)) { matches.push({ id, name }); } } } if (matches.length === 0) { suggestionBox.style.display = 'none'; return; } suggestionBox.innerHTML = ''; matches.slice(0, 10).forEach(({ id, name }) => { const item = document.createElement('div'); item.style.cssText = ` padding:3px 10px; cursor:pointer; font-size:12px; border-bottom:1px solid #f5f5f5; display:flex; justify-content:space-between; transition:background 0.1s; `; item.onmouseenter = () => { item.style.background = '#f5f7fa'; }; item.onmouseleave = () => { item.style.background = 'transparent'; }; item.onclick = () => { if (!tagSet.has(id)) { tagSet.add(id); updateSelectedDisplay(); saveSettings(); } input.value = ''; suggestionBox.style.display = 'none'; }; const nameSpan = document.createElement('span'); nameSpan.textContent = name; const idSpan = document.createElement('span'); idSpan.textContent = `ID:${id}`; idSpan.style.cssText = 'color:#aaa; font-size:10px;'; item.appendChild(nameSpan); item.appendChild(idSpan); suggestionBox.appendChild(item); }); suggestionBox.style.display = 'block'; });
input.addEventListener('blur', function() { setTimeout(() => { suggestionBox.style.display = 'none'; }, 200); });
section.appendChild(wrapper);
const clearBtn = document.createElement('button'); clearBtn.textContent = '清空'; clearBtn.style.cssText = ` font-size:11px; color:#e55c5c; background:none; border:none; cursor:pointer; padding:2px 6px; margin-top:4px; border-radius:4px; transition:background 0.15s; `; clearBtn.onmouseenter = () => { clearBtn.style.background = '#fef0f0'; }; clearBtn.onmouseleave = () => { clearBtn.style.background = 'transparent'; }; clearBtn.onclick = () => { tagSet.clear(); updateSelectedDisplay(); saveSettings(); }; section.appendChild(clearBtn);
panel.appendChild(section); });
let hoverTimeout = null; button.addEventListener('mouseenter', function() { clearTimeout(hoverTimeout); panel.style.display = 'block'; requestAnimationFrame(() => { const rect = button.getBoundingClientRect(); const panelRect = panel.getBoundingClientRect(); if (rect.top - panelRect.height < 10) { panel.style.bottom = 'auto'; panel.style.top = 'calc(100% + 10px)'; } else { panel.style.bottom = 'calc(100% + 10px)'; panel.style.top = 'auto'; } }); });
button.addEventListener('mouseleave', function(e) { hoverTimeout = setTimeout(() => { const related = e.relatedTarget; if (related && (panel.contains(related) || button.contains(related))) { return; } panel.style.display = 'none'; }, 200); });
panel.addEventListener('mouseenter', function() { clearTimeout(hoverTimeout); panel.style.display = 'block'; });
panel.addEventListener('mouseleave', function(e) { const related = e.relatedTarget; if (related && (panel.contains(related) || button.contains(related))) { return; } panel.style.display = 'none'; });
const parent = button.parentNode; parent.style.position = 'relative'; parent.appendChild(panel);
return panel; }
function startRandomJump() { let diffArray; if (selectedDifficulties.size === 0) { diffArray = Object.keys(DIFFICULTY_MAP).map(Number); } else { diffArray = Array.from(selectedDifficulties); } let typeValue; if (selectedTypes.size === 0) { typeValue = 'luogu'; } else { const typeArray = Array.from(selectedTypes); typeValue = typeArray[Math.floor(Math.random() * typeArray.length)]; } const randomDiff = diffArray[Math.floor(Math.random() * diffArray.length)];
const dimOrder = ['algorithm', 'source', 'time', 'region', 'special']; const tagParts = []; dimOrder.forEach(key => { const ids = Array.from(selectedTags[key]); if (ids.length > 0) { tagParts.push(ids.join(',')); } }); let tagParam = ''; if (tagParts.length > 0) { tagParam = '&tag=' + tagParts.join('|'); }
const baseUrl = `https://www.luogu.com.cn/problem/list?type=${typeValue}&difficulty=${randomDiff}${tagParam}`; const firstPageUrl = baseUrl + '&page=1';
GM_xmlhttpRequest({ method: 'GET', url: firstPageUrl, onload: function(response) { const html = response.responseText; const pageInfo = extractPageInfoFromJson(html); if (!pageInfo || !pageInfo.totalPages || pageInfo.totalPages <= 0) { alert('获取总页数失败,请重试'); return; } const totalPages = pageInfo.totalPages;
if (filterAccepted || filterSubmitted) { const pages = []; for (let i = 1; i <= totalPages; i++) { pages.push(i); } for (let i = pages.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [pages[i], pages[j]] = [pages[j], pages[i]]; }
function tryNextPage(index) { if (index >= pages.length) { alert('该类型题你已全部做过'); return; } const pageUrl = baseUrl + '&page=' + pages[index]; GM_xmlhttpRequest({ method: 'GET', url: pageUrl, onload: function(pageResponse) { const results = extractProblemResultsFromJson(pageResponse.responseText); if (!results || results.length === 0) { tryNextPage(index + 1); return; } const filtered = results.filter(item => { if (filterAccepted && item.accepted !== false) return false; if (filterSubmitted && item.submitted !== false) return false; return true; }); if (filtered.length === 0) { tryNextPage(index + 1); return; } const randomItem = filtered[Math.floor(Math.random() * filtered.length)]; window.open(`https://www.luogu.com.cn/problem/${randomItem.pid}`, '_blank'); }, onerror: function() { tryNextPage(index + 1); } }); } tryNextPage(0); } else { const randomPage = Math.floor(Math.random() * totalPages) + 1; const pageUrl = baseUrl + '&page=' + randomPage; GM_xmlhttpRequest({ method: 'GET', url: pageUrl, onload: function(pageResponse) { const pageHtml = pageResponse.responseText; const problemIds = extractProblemIdsFromJson(pageHtml); if (!problemIds || problemIds.length === 0) { alert('该页没有找到题目,请重试'); return; } const randomId = problemIds[Math.floor(Math.random() * problemIds.length)]; window.open(`https://www.luogu.com.cn/problem/${randomId}`, '_blank'); }, onerror: function() { alert('请求随机页面失败'); } }); } }, onerror: function() { alert('请求题目列表失败'); } }); }
function extractPageInfoFromJson(html) { try { const jsonStr = html.match(/<script id="lentille-context"[^>]*>([\s\S]*?)<\/script>/); if (!jsonStr) return null; const data = JSON.parse(jsonStr[1]); if (data && data.data && data.data.problems) { const perPage = data.data.problems.perPage || 50; const count = data.data.problems.count || 0; const totalPages = Math.max(1, Math.ceil(count / perPage)); return { totalPages, perPage, count }; } } catch (e) {} return null; }
function extractProblemIdsFromJson(html) { try { const jsonStr = html.match(/<script id="lentille-context"[^>]*>([\s\S]*?)<\/script>/); if (!jsonStr) return []; const data = JSON.parse(jsonStr[1]); if (data && data.data && data.data.problems && Array.isArray(data.data.problems.result)) { return data.data.problems.result.map(item => item.pid); } } catch (e) {} return []; }
function extractProblemResultsFromJson(html) { try { const jsonStr = html.match(/<script id="lentille-context"[^>]*>([\s\S]*?)<\/script>/); if (!jsonStr) return []; const data = JSON.parse(jsonStr[1]); if (data && data.data && data.data.problems && Array.isArray(data.data.problems.result)) { return data.data.problems.result; } } catch (e) {} return []; }
function init() { const btn = document.querySelector('[name="gotorandom"]'); if (!btn) { console.warn('未找到随机跳题按钮'); return; }
const parent = btn.parentNode; const newBtn = document.createElement('button'); newBtn.className = btn.className; newBtn.textContent = btn.textContent; newBtn.style.cssText = btn.style.cssText; for (const attr of btn.attributes) { if (attr.name !== 'name') { newBtn.setAttribute(attr.name, attr.value); } } newBtn.setAttribute('name', 'gotorandom-custom');
parent.replaceChild(newBtn, btn); createFloatingPanel(newBtn);
newBtn.addEventListener('click', function(e) { e.preventDefault(); startRandomJump(); });
console.log('洛谷随机跳题脚本 v1.0 已加载'); }
if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); }})();```:::