把这个加了一点小东西,删了一点个人觉得没啥用的东西…准备加一个私信实时接收但不会写qwq
本人是xxs,不喜勿喷
// ==UserScript==
// @name 洛谷插件N合1
// @namespace http://tampermonkey.net/
// @version 3.2
// @description 洛谷插件N合1
// @author xlaser
// @match *://www.luogu.com.cn/*
// @grant none
// @run-at document-end
// ==/UserScript==
var background = new Array();
function payload(){
var back = background[Math.floor(Math.random() * background.length)];
document.querySelector('body').style="background: url(" + back + ") fixed center;background-size: cover;";
if(document.querySelector('div[class="mdui-panel mdui-panel-gapless"]') != null)
document.querySelector('div[class="mdui-panel mdui-panel-gapless"]').style="opacity: 0.8;";
if(document.querySelector('div[class="mp-editor-container"]') != null)
document.querySelector('div[class="mp-editor-container"]').style="opacity: 0.8;";
}
const featureDict = new Map([
['luoguRemoveAd', '屏蔽广告'],
['luoguRemoveback', '网页出错不返回'],
['luoguRemoveCover', '移除主页遮盖'],
['luoguAddProblemsColor', '显示题目颜色'],
['luogulgplqss', '讨论区显示具体时间'],
['luogusbdd', '鼠标点击特效'],
['luogufsfs', '按难度随机跳题'],
['luoguyjjb', '云剪贴板/博客自动跳转']
]);
const problemDifficultyToColor = [[191,191,191],[254,76,97],[243,156,17],[255,193,22],[82,196,26],[52,152,219],[157,61,207],[14,29,105]];
function addSettingButton(){//增加插件设置
const navElement = document.querySelector('nav.lfe-body');
if(!navElement){
console.log("未找到侧边导航栏");
console.log(document);
return;
}
const settingElement = document.createElement('a');//外壳,链接功能
settingElement.setAttribute('data-v-0640126c', '');
settingElement.setAttribute('data-v-639bc19b', '');
settingElement.setAttribute('data-v-33633d7e', '');
settingElement.className = 'color-none';
settingElement.style.color = 'inherit';
const settingText = document.createElement('span');
settingText.setAttribute('data-v-639bc19b', '');
settingText.className = 'text';
settingText.textContent = '插件功能';
settingElement.appendChild(settingText);
navElement.appendChild(settingElement);
settingElement.addEventListener('click', () => {//点击后进入临时页面
function initializeSettings(){
for(let i of featureDict.keys()){
if(localStorage.getItem(i) === null){
localStorage.setItem(i, 'true');
}
}
}
initializeSettings();
const pageContent = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>洛谷插件功能设置</title>
<style>
body { font-family: Arial, sans-serif; }
#featureBox {
position: fixed;
top: 20%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
border: 1px solid #ccc;
padding: 20px;
z-index: 10001;
}
</style>
</head>
<body>
<div id="featureBox">
<h3>选择插件功能</h3>
${Array.from(featureDict).map(([key, description]) => `
<div>
<label><input type="checkbox" id="${key}">${description}</label>
</div>
`).join('')}
<button id="selectAll">全选</button>
<button id="selectnnAll">全不选</button>
<button id="saveFeatures">保存</button>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {//加载设置
${Array.from(featureDict.keys()).map(key => `
const ${key} = localStorage.getItem('${key}') === 'true';
document.getElementById('${key}').checked = ${key};
`).join('')}
});
document.getElementById('saveFeatures').addEventListener('click', () => {//保存设置
${Array.from(featureDict.keys()).map(key => `
const ${key} = document.getElementById('${key}').checked;
localStorage.setItem('${key}', String(${key}));
`).join('')}
alert('功能已保存');
});
document.getElementById('selectAll').addEventListener('click', () => {//全选
${Array.from(featureDict.keys()).map(key => `
document.getElementById('${key}').checked = true;
`).join('')}
});
document.getElementById('selectnnAll').addEventListener('click', () => {//全不选
${Array.from(featureDict.keys()).map(key => `
document.getElementById('${key}').checked = false;
`).join('')}
});
</script>
</body>
</html>
`;
const newWindow = window.open();
newWindow.document.write(pageContent);
newWindow.document.close();
});
}
function removeAd(){//屏蔽广告
const adElement = document.querySelector('div[data-v-0a593618][data-v-1143714b]');
if(adElement) {
adElement.remove();
}
}
function removeBack(){//移除网页跳转
function disableRedirect(){
window.history.go = function() {// 根据实际测试,洛谷使用的是 history.go
};
}
function checkError(){
if(document.title === '错误 - 洛谷 | 计算机科学教育新生态'){
disableRedirect();
return true;
}
return false;
}
const observer = new MutationObserver((mutations, obs) => {
checkError();
});
const config = {
childList: true,
subtree: true,
};
observer.observe(document, config);// 监视 title 变化
if(document.readyState === 'complete' || document.readyState === 'interactive'){
checkError();
}
}
function removeCover(){
let profile = document.querySelector(".introduction.marked");
if(profile && profile.style.display === "none"){
profile.style.display = "block";
for(let i=0;i<profile.parentElement.children.length;++i){
if(profile.parentElement.children[i].innerText === "系统维护,该内容暂不可见。"){
profile.parentElement.children[i].remove();
}
}
}
}
function alwaysRemoveCover(){
const observer = new MutationObserver(() => removeCover());
observer.observe(document,{
childList: true,
subtree: true
});
removeCover();
}
const problemToColorMap = new Map();
class FetchRateLimiter{
constructor(limit) { // limit 以毫秒为单位,表示相邻两次 fetch 操作间的最小间隔
this.limit = limit;
this.queue = [];
this.queuePrior = [];
this.active = false;
this.requestCache = new Map();
}
process() {
this.active = 1;
let resolve, reject, url;
if(this.queuePrior.length > 0){
({resolve, reject, url} = this.queuePrior.shift());
}
else if(this.queue.length > 0){
({resolve, reject, url} = this.queue.shift());
}
else{
this.active = 0;
return;
}
console.log(url);
fetch(url)
.then(resolve)
.catch(reject);
setTimeout(this.process.bind(this), this.limit);
}
push(url, prior) {
if(this.requestCache.has(url)) return this.requestCache.get(url);
const request = new Promise((resolve, reject) => {
if(prior) this.queuePrior.push({url, resolve, reject});
else this.queue.push({url, resolve, reject});
if(!this.active) this.process();
})
.then((response) => {
return response.text();
});
this.requestCache.set(url,request);
return request;
}
}
const limiter = new FetchRateLimiter(300);
async function getProblemColor(problemid, prior=false){
if(window.location.href.startsWith('https://www.luogu.com.cn/record')){
const resultList = _feInstance.currentData.records.result;
if(!resultList.luoguVisited){
for(const item of resultList){
problemToColorMap.set(item.problem.pid,`rgb(${problemDifficultyToColor[item.problem.difficulty].join(',')})`);
}
resultList.luoguVisited = true;
}
}
if(/^https:\/\/www\.luogu\.com\.cn\/user\/\d+#practice$/.test(window.location.href)) {
let problemList = _feInstance.currentData.submittedProblems;
if(!problemList.luoguVisited){
for(const item of problemList){
problemToColorMap.set(item.pid,`rgb(${problemDifficultyToColor[item.difficulty].join(',')})`);
}
problemList.luoguVisited = true;
}
problemList = _feInstance.currentData.passedProblems;
if(!problemList.luoguVisited){
for(const item of problemList){
problemToColorMap.set(item.pid,`rgb(${problemDifficultyToColor[item.difficulty].join(',')})`);
}
problemList.luoguVisited = true;
}
}
if(problemToColorMap.has(problemid)) return problemToColorMap.get(problemid);
const url = '/problem/'+problemid;
let data;
try{
data = await limiter.push(url, prior);
} catch (error) {
debugger;
console.error('Error fetching user data:', error);
console.log(problemid);
return;
}
const parser = new DOMParser();
const doc = parser.parseFromString(data, 'text/html');
let scriptText = doc.querySelector("script").textContent;
scriptText = scriptText.match(/window\._feInjection = JSON\.parse\(decodeURIComponent\("(.+)"\)\);/);
if(!scriptText) return;
scriptText = scriptText[1];
const _feInjection = JSON.parse(decodeURIComponent(scriptText));
const problemDifficulty = _feInjection.currentData.problem.difficulty;
problemToColorMap.set(problemid,`rgb(${problemDifficultyToColor[problemDifficulty].join(',')})`);
return problemToColorMap.get(problemid);
}
function isProblemId(problemid){
if(problemid.startsWith('AT_')) return true;
if(!/[a-zA-Z]/.test(problemid)) return false;
if(!/[0-9]/.test(problemid)) return false;
return true;
}
async function addProblemColor(item){
let problemid = item.href.split('/').pop();
let prior = false;
if(problemid.includes('?forum=')){
debugger;
problemid = problemid.split('=').pop();
prior = true;
}
problemid = problemid.split('?')[0];
problemid = problemid.split('=').pop();
if(!isProblemId(problemid)) return;
if(item.innerText.startsWith(problemid)){
const spanItem = item.children[0];
if(spanItem && spanItem.matches('span.pid') && spanItem.innerText === problemid){
const color = await getProblemColor(problemid, prior);
spanItem.style.color = color;
spanItem.style.fontWeight = 'bold';
}
else{
const color = await getProblemColor(problemid, prior);
const content = item.innerHTML;
item.innerHTML = content.replace(problemid,`<b style="color: ${color};">${problemid}</b>`);
}
}
}
async function addProblemsColor(){
const observer = new MutationObserver(async (mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
for (const addedNode of mutation.addedNodes) {
if (addedNode.nodeType === Node.ELEMENT_NODE) {
const newItems = addedNode.querySelectorAll('a[href]');
if(addedNode.matches('a[href]')) addProblemColor(addedNode);
for (const newItem of newItems) {
addProblemColor(newItem);
}
}
}
}
else if(mutation.type === 'characterData') {
if(mutation.target.parentElement.matches('span.pid')){
mutation.target.parentElement.style.color = await getProblemColor(mutation.target.textContent);
mutation.target.parentElement.style.fontWeight = 'bold';
}
}
}
});
observer.observe(document, {
childList: true,
subtree: true,
characterData: true,
});
const nodelist = document.querySelectorAll('a[href]');
for(const i of nodelist){
addProblemColor(i);
}
}
function formatTime(isoDatetime) {
const date = new Date(isoDatetime);
const year = date.getFullYear();
const month = (date.getMonth() + 1).toString().padStart(2, '0');
const day = date.getDate().toString().padStart(2, '0');
const hours = date.getHours().toString().padStart(2, '0');
const minutes = date.getMinutes().toString().padStart(2, '0');
const seconds = date.getSeconds().toString().padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
}
function changeTimeText() {
let timeElements = document.querySelectorAll('time[data-v-f9624136][datetime]');
timeElements.forEach((timeElement) => {
const datetime = timeElement.getAttribute('datetime');
const formattedTime = formatTime(datetime);
timeElement.textContent = formattedTime;
});
timeElements = document.querySelectorAll('time[data-v-65a77fa1][datetime]');
timeElements.forEach((timeElement) => {
const datetime = timeElement.getAttribute('datetime');
const formattedTime = formatTime(datetime);
timeElement.textContent = formattedTime;
});
timeElements = document.querySelectorAll('time[data-v-85ede732][datetime]');
timeElements.forEach((timeElement) => {
const datetime = timeElement.getAttribute('datetime');
const formattedTime = formatTime(datetime);
timeElement.textContent = formattedTime;
});
timeElements = document.querySelectorAll('time[data-v-6784177c][datetime]');
timeElements.forEach((timeElement) => {
const datetime = timeElement.getAttribute('datetime');
const formattedTime = formatTime(datetime);
timeElement.textContent = formattedTime;
});
}
function updateLastReplyText() {
const elements = document.querySelectorAll('div[data-v-b0d342de][data-v-f9624136].row.row-space-between.bottom');
elements.forEach((element) => {
const linkElement = element.querySelector('a.row.content-left.title.link.color-default');
const linkElement1 = linkElement.querySelector('div.time');
const timeText = linkElement1.title;
if (timeText) {
const titleText = `最后回复于 ${timeText}`;
if (linkElement1) {
linkElement1.textContent = titleText;
}
}
});
elements.forEach((element) => {
const linkElement = element.querySelector('div.row.content-left');
const linkElement1 = linkElement.querySelector('div.time');
const timeText = linkElement1.title;
if (timeText) {
const titleText = `发表于 ${timeText}`;
if (linkElement1) {
linkElement1.textContent = titleText;
}
}
});
}
function benben(){
// 找到所有 class 为 span.lfe-caption 的元素
var elements = document.querySelectorAll('span.lfe-caption');
// 遍历每个元素并进行操作
elements.forEach(function(element) {
var temp = element.textContent;
// 提取 title 属性中的数字
var title = element.getAttribute('title');
if(title){
var numbers = title.match(/\d+/g);
if (numbers && numbers.length >= 5) {
// 提取第三个数字和第四个数字
var thirdNumber = parseInt(numbers[2]);
var fourthNumber = parseInt(numbers[3]);
// 处理日凌晨的情况
if (title.includes("日凌晨")) {
if (fourthNumber === 12) {
fourthNumber = "0";
} else {
//fourthNumber = fourthNumber < 10 ? "0" + fourthNumber : fourthNumber.toString();
}
}
// 处理日早上、日上午、日下午、日晚上的情况
if (title.includes("日早上") || title.includes("日上午")) {
//fourthNumber = fourthNumber < 10 ? "0" + fourthNumber : fourthNumber.toString();
} else if (title.includes("日下午") || title.includes("日晚上")) {
fourthNumber += 12;
}
// 补全第二个数和第三个数并更新 text
var secondNumber = parseInt(numbers[1]);
var secondNumberStr = secondNumber < 10 ? "0" + secondNumber : secondNumber.toString();
var thirdNumberStr = thirdNumber < 10 ? "0" + thirdNumber : thirdNumber.toString();
var fourthNumberStr = parseInt(fourthNumber) < 10 ? "0" + fourthNumber : fourthNumber.toString();
if(fourthNumberStr=="24")fourthNumberStr="12";
var newText = `${numbers[0]}-${secondNumberStr}-${thirdNumberStr} ${fourthNumberStr}:${numbers[4]}`;
// 更新元素的 text
element.textContent = newText;
element.setAttribute('title',temp);
}
}
});
}
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);
}
}
}
}
//type:success, error, info
//time:ms
function displayAlert(type, data, time){
var lunbo=document.createElement("div");
if(type == "success") {
lunbo.style.backgroundColor = "#009900";
} else if(type == "error") {
lunbo.style.backgroundColor = "#990000";
} else if(type == "info") {
lunbo.style.backgroundColor = "#e6b800";
} else {
console.log("入参type错误");
return;
}
lunbo.id="lunbo";
lunbo.style.position = "absolute";
lunbo.style.width = "290px";
lunbo.style.height = "120px";
lunbo.style.marginLeft = "-100px";
lunbo.style.marginTop = "-30px";
lunbo.style.left = "90%";
lunbo.style.top = "15%";
lunbo.style.color = "white";
lunbo.style.fontSize = "25px";
lunbo.style.borderRadius = "20px";
lunbo.style.textAlign="center";
lunbo.style.lineHeight="60px";
if(document.getElementById("lunbo")==null){
document.body.appendChild(lunbo);
lunbo.innerHTML=data;
setTimeout(function(){
document.body.removeChild(lunbo);
} ,time);
}
}
function yjjb(){
if(window.location.pathname.substr(0,6)==="/paste")
{
location.assign("https://www.luogu.com"+window.location.pathname);
}
else if(window.location.pathname.substr(0,8)==="/article")
{
location.assign("https://www.luogu.com"+window.location.pathname);
}
}
function fnf(){
payload();
if(window.location.pathname == "/"){
setTimeout(function () {
document.querySelector('div[class="am-u-md-3"]').innerHTML = `
<div class="lg-article" id="rand-problem-form">
<h2>随机跳题</h2>
<select class="am-form-field" style="background-color:#DDD;" name="rand-problem-rating" autocomplete="off" placeholder="选择难度">
<option value="0">暂无评定</option>
<option value="1">入门</option>
<option value="2">普及-</option>
<option value="3">普及/提高-</option>
<option value="4">普及+/提高</option>
<option selected value="5">提高+/省选-</option>
<option value="6">省选/NOI-</option>
<option value="7">NOI/NOI+/CTSC</option>
</select>
<select class="am-form-field" style="background-color:#DDD;margin-top:16px;" name="rand-problem-source" autocomplete="off" placeholder="选择来源">
<option selected value="P">洛谷题库</option>
<option value="CF">CodeForces</option>
<option value="SP">SPOJ</option>
<option value="AT">AtCoder</option>
<option value="UVA">UVa</option>
</select>
<button class="am-btn am-btn-sm am-btn-primary" style="margin-top:16px;visibility:hidden">跳转</button>
<button class="am-btn am-btn-sm am-btn-primary lg-right" id="rand-problem-button" style="margin-top:16px;">跳转</button>
</div>`;
$('#rand-problem-button').click(function() {
$('#rand-problem-button').addClass('am-disabled');
$.get("https://www.luogu.com.cn/problem/list?difficulty=" + $('[name=rand-problem-rating]')[0].value + "&type=" + $('[name=rand-problem-source]')[0].value + "&page=1&_contentOnly=1",
function (data) {
var arr = data;
if (arr['code'] != 200) {
$('#rand-problem-button').removeClass('am-disabled');
show_alert("好像哪里有点问题", arr["message"]);
}
else {
var problem_count = arr['currentData']['problems']['count'];
var page_count = Math.ceil(problem_count / 50);
var rand_page = Math.floor(Math.random()*page_count) + 1;
$.get("https://www.luogu.com.cn/problem/list?difficulty=" + $('[name=rand-problem-rating]')[0].value + "&type=" + $('[name=rand-problem-source]')[0].value + "&page=" + rand_page + "&_contentOnly=1",
function(data) {
var list = data['currentData']['problems']['result'];
var rand_idx = Math.floor(Math.random()*list.length);
var pid = list[rand_idx]['pid'];
location.href = "https://www.luogu.com.cn/problem/" + pid;
}
);
}
}
);
});
},499);
}
}
setTimeout(addSettingButton, 500);
if(localStorage.getItem('luoguRemoveAd') === 'true'){
setTimeout(removeAd, 500);
}
if(localStorage.getItem('luoguRemoveback') === 'true'){
removeBack();
}
if(localStorage.getItem('luoguRemoveCover') === 'true'){
setTimeout(alwaysRemoveCover, 500);
}
if(localStorage.getItem('luoguAddProblemsColor') === 'true'){
setTimeout(addProblemsColor, 500);
}
if(localStorage.getItem('luogulgplqss') === 'true'){
setInterval(changeTimeText, 500);
setInterval(updateLastReplyText, 500);
setInterval(benben, 500);
}
if(localStorage.getItem('luogusbdd') === 'true'){
clickEffect();
}
if(localStorage.getItem('luogufsfs') === 'true'){
fnf();
}
if(localStorage.getItem('luoguyjjb') === 'true'){
yjjb();
}