版本比较
WZOI 辅助工具
标题
增加 1 行删除 1 行
11wzoi helperWZOI 辅助工具正文
增加 67 行删除 73 行
12345676891011121314151617161718181920212122232425222324262526272847 行未改动76777879808182838485866 行未改动9394959697989910010110210310410510697989910010110210310410510710610710810911011311111211311411711811511611711820 行未改动13914014114214714814914314414514614714814915015715115215315415518 行未改动174175176177184185178179180181182183136 行未改动全部展开32032132232333032432532633332732832933010 行未改动34134234334435234534634734834935035135235335436135535635735835936036136236336436536636737137236836937037137237320 行未改动39439539639740139839940340040140240340447 行未改动452453454455459460461462463464465466467468469470471472473474475476477456457458459460461462463464465466467468469470471472473474479480481482483484485486487488489490491492493475476477478479480481482483484485486487488489490491497本工具由 @[chenbs](https://www.luogu.com.cn/user/766573) 和我共同编写。
```js// ==UserScript==// @name WZOI 辅助工具// @namespace http://tampermonkey.net/// @description 在 WZOI 中,给样例输入输出、表格等添加复制按钮。并可以一键吸氧、增加搜索、查看自己以前的 AC 代码。// @version 2025-08-11// @version 2026-02-09// @author chenbs,wanganze// @match *://*/*// @grant none// @license MIT// ==/UserScript==
(function () { 'use strict'; //判断 { if(document.getElementsByClassName('mt-auto')[0].innerHTML.search("wzoj") == -1)return; } if(document.getElementsByClassName('mt-auto').length == 0 || document.getElementsByClassName('mt-auto')[0].innerHTML == null || document.getElementsByClassName('mt-auto')[0].innerHTML.search("wzoj") == -1)return; //跳转 if(window.location.pathname=="/tags-chart") { if(window.location.pathname=="/tags-chart") { let s = window.origin + "/search?name=&search_item=problems&tags%5B%5D=" + window.location.hash.substr(5); console.log(s); window.location.replace(s); let s = window.origin + "/search?name=&search_item=problems&tags%5B%5D=" + window.location.hash.substr(5); console.log(s); window.location.replace(s); } } // 复制字符串函数 function copy(text) { let input = document.createElement('textarea');47 行未改动 }
let tmp = Array.from(document.getElementsByClassName("text-muted")); for (let i = 0; i < tmp.length; i++) { if (tmp[i].innerText == "(双击复制)") tmp[i].remove(); } } // 个人简介 let fa = document.getElementsByClassName("card-header"); for (let i = 0; i < fa.length; i++) {6 行未改动 cp.onclick = function () { let s = this.parentNode.parentNode.children[1].innerText; copy(s); }; fa[i].appendChild(cp); } // 题解 { fa = document.getElementsByClassName("language-cpp"); for(let i=0; i<fa.length; i++){ if(fa[i].tagName != "PRE") continue; if(fa[i].className.includes("line-numbers") || window.location.hostname == "wzoi.cn") continue; let cp = document.createElement("button"); cp.className = "new-button"; cp.innerText = "复制"; cp.onclick = function(){let s=this.parentNode.innerText;copy(s.substr(3,s.length));}; fa[i].insertBefore(cp, fa[i].firstChild); fa = document.getElementsByClassName("language-cpp"); for(let i=0; i<fa.length; i++){ if(fa[i].tagName != "PRE") continue; if(fa[i].className.includes("line-numbers") || window.location.hostname == "wzoi.cn") continue; let cp = document.createElement("button"); cp.className = "new-button"; cp.innerText = "复制"; cp.onclick = function(){let s=this.parentNode.innerText;copy(s.substr(3,s.length));}; fa[i].insertBefore(cp, fa[i].firstChild); } } // 表格 fa = document.getElementsByTagName("table"); for (let i = 0; i < fa.length; i++) { if (fa[i].children[0].tagName != "THEAD") continue; fa[i].style.cssText += "margin-top: 25px !important"; fa[i].style.cssText += "margin-top: 5px !important"; let cp = document.createElement("button"); cp.className = "new-button"; cp.innerText = "复制表格 Markdown"; cp.style.position = "absolute"; cp.style.transform = "translate(0px,-82px)"; cp.onclick = function () { function calc(s) { // 转义字符 let s2 = ""; for (let i = 0; i < s.length; i++) {20 行未改动 // 显示打勾图标 if (body[j].children[k].innerHTML.includes("class=\"fa fa-check\"")) s += "✅|"; // 显示完整用户名 else if (body[j].children[k].innerHTML.includes("user-badge badge badge-light")) { if (body[j].children[k].children[0].children[0].dataset.nickname == "") s += body[j].children[k].children[0].children
[0].dataset.uname + "|"; if (body[j].children[k].children[0].children[0].dataset.nickname == "") {s += body[j].children[k].children[0].children[0].dataset.uname + "|";} else s += body[j].children[k].children[0].children[0].dataset.nickname + "|"; // 有真名就显示真名 } else s += calc(body[j].children[k].innerText) + "|"; } } copy(s); }; fa[i].insertBefore(cp, fa[i].firstChild); fa[i].parentElement.insertBefore(cp, fa[i].parentElement.firstChild);
} // 样式 let tmp = document.createElement("style");18 行未改动 // 一键吸氧 { let fa = document.getElementById("sol-form"); if (fa != null) { const o3 = "#pragma GCC optimize(3,\"Ofast\",\"inline\")\n#pragma G++ optimize(3,\"Ofast\",\"inline\")"; const o2 = "#pragma GCC optimize(2)\n#pragma G++ optimize(2)"; const o3 = "#pragma GCC optimize(3,\"Ofast\",\"inline\")"; const o2 = "#pragma GCC optimize(2)"; const TEXTnode = fa.children[5].children[0]; let tmp = document.createElement("button"); let tmp1 = document.createElement("button"); tmp.className = "btn btn-primary";136 行未改动全部展开 let pre = document.createElement("pre"); document.body.appendChild(cb); cb.appendChild(cb_top); cb.appendChild(pre);
function updatecode(c1,c2){code = c1;code2 = c2} let regexp = new RegExp(location.origin+"/s/\\d*/\\d*"); console.log(regexp);
setInterval(async function () { // 添加查看按钮 let body = document.getElementsByTagName("tbody")[0]; if (!body) return;10 行未改动 for (let j = purl.length - 1; purl[j] != "/" && j >= 0; j--) pid = purl[j] + pid; if (isNaN(Number(pid))) continue;
e.children[0].dataset.vis = 1; e.children[0].addEventListener("click", () => { e.children[0].addEventListener("click",function (){ pre.innerHTML = `<p style="text-align:center; height:100px; width:100px; line-height:100px;">查询中,请稍等</p>`; cb.style.display = "block";
fetch(`/solutions?problemset_id=&user_name=${username}&problem_id=${pid}&score_min=100&score_max=&language=&status=4`) .then((r) => r.text()) .then((data) => { let k = data.indexOf("a href=\"/solution"); if (k == -1) { updatecode(`<p style="text-align:center; height:120px; line-height:120px;">未找到</p>`,`<p style="text-align:center; height:120px; line-height:120px;">未找到</p>`); code = code2 = `<p style="text-align:center; height:120px; line-height:120px;">未找到</p>`; //code = code2 = `<p style="text-align:center; height:120px; line-height:120px;">未找到</p>`; update(); } else { k += 19; let sid = ""; while (data[k] != "\"") sid += data[k++]; console.log(sid); fetch(`/solutions/${sid}`) .then((response) => response.text()) .then((data) => { updatecode(data.substring(data.indexOf("<code class=\"language-cpp\">") + 27, data.indexOf("</code>")), "#### " + e.children[1].innerText + "." + e.children[2].innerText + "\n```cpp\n" + data.substring(data.indexOf("<code class=\"language-cpp\">") + 27, data.indexOf("</code>")) + "\n```");
code = data.substring(data.indexOf("<code class=\"language-cpp\">") + 27, data.indexOf("</code>")); code2 = "#### " + e.children[1].innerText + "." + e.children[2].innerText + "\n```cpp\n" + code + "\n```"; //code = data.substring(data.indexOf("<code class=\"language-cpp\">") + 27, data.indexOf("</code>")); //code2 = "#### " + e.children[1].innerText + "." + e.children[2].innerText + "\n```cpp\n" + code + "\n```"; update(); }); } });20 行未改动 fetch(`/solutions?problemset_id=&user_name=${username}&problem_id=${pid}&score_min=100&score_max=&language=&status=4`) .then((r) => r.text()) .then((data) => { if (data.indexOf("a href=\"/solution") != -1) { if (e.children[0].dataset.in_search != 1) e.children[0].innerHTML = `<span class="fa fa-check" style="color: if (e.children[0].dataset.in_search != 1) {e.children[0].innerHTML = `<span class="fa fa-check" style="color:
#00800066;"></span>`;#00800066;"></span>`;} else e.children[0].innerHTML = `<span class="fa fa-check" style="color: green"></span>`;
// 写入缓存 localStorage.setItem(username + "_" + location.href + "_" + i, "1");47 行未改动 } i++; }, 200); } { if (window.location.href.includes("/users/")) { // 显示排名 let flag = (!document.getElementsByClassName("card-title")[0]); // 未手机验证的用户 let id = window.location.href.substring(window.location.href.indexOf("users") + 6); for (let page = 1; page <= 20; page++) { setTimeout(() => { fetch(`/ranklist?page=${page}`) .then((r) => r.text()) .then((data) => { let p = data.indexOf(`data-uid="${id}"`); if (p != -1) { while (p > 0 && data.substring(p, p + 5) != "</td>") p--; if (data.substring(p, p + 5) != "</td>") return; let p2 = p; while (p2 > 0 && data[p2] != ">") p2--; if (data[p2] != ">") return; let rank = data.substring(p2 + 1, p); console.log("rank", rank); if (window.location.href.includes("/users/")) { // 显示排名 let flag = (!document.getElementsByClassName("card-title")[0]); // 未手机验证的用户 let id = window.location.href.substring(window.location.href.indexOf("users") + 6); for (let page = 1; page <= 20; page++) { setTimeout(() => { fetch(`/ranklist?page=${page}`) .then((r) => r.text()) .then((data) => { let p = data.indexOf(`data-uid="${id}"`); if (p != -1) { while (p > 0 && data.substring(p, p + 5) != "</td>") p--; if (data.substring(p, p + 5) != "</td>") return; let p2 = p; while (p2 > 0 && data[p2] != ">") p2--; if (data[p2] != ">") return; let rank = data.substring(p2 + 1, p); console.log("rank", rank);
let tmp = document.getElementsByClassName(flag ? "container h-100" : "card-title")[0]; let node = document.createElement("span"); node.className="new_div"; node.innerText = "#" + rank; node.style.marginLeft = "20px"; node.style.fontFamily = "Exo, Consolas"; node.style.fontSize = "12px"; node.style.border = "1px solid #000"; node.style.background = "rgb(255, 245, 245)"; node.style.padding = "5px"; tmp.appendChild(node); } }); }, (page - 1) * 200); } let tmp = document.getElementsByClassName(flag ? "container h-100" : "card-title")[0]; let node = document.createElement("span"); node.className="new_div"; node.innerText = "#" + rank; node.style.marginLeft = "20px"; node.style.fontFamily = "Exo, Consolas"; node.style.fontSize = "12px"; node.style.border = "1px solid #000"; node.style.background = "rgb(255, 245, 245)"; node.style.padding = "5px"; tmp.appendChild(node); } }); }, (page - 1) * 200); } }})();```