JavaScript// ==UserScript==
// @name 颓啥颓 写题去
// @namespace http://tampermonkey.net/
// @version 1.1
// @description You are not allowed to view the requested page.
// @author _buzhidao_
// @match *://*/*
// @grant none
// @run-at document-start
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// ==================== 外部网站列表 ====================
const EXTERNAL_SITES = [
'bilibili',
'florr',
'oitrainer',
'benben',
'2048'
];
// ==================== 洛谷特定页面 ====================
const LUOGU_SPECIFIC_PAGES = [
'www.luogu.com.cn/chat',
'www.luogu.com.cn/user/notification',
'www.luogu.com.cn/ticket',
'activity',
'following'
];
// ==================== 网站检查 ====================
// 检查是否是外部网站
const isExternalSite = () => {
const currentUrl = window.location.href.toLowerCase();
const currentHostname = window.location.hostname.toLowerCase();
for (const site of EXTERNAL_SITES) {
if (currentHostname.includes(site) || currentUrl.includes(site)) {
return true;
}
}
return false;
};
// 检查是否是洛谷特定页面
const isLuoguSpecificPage = () => {
const currentUrl = window.location.href.toLowerCase();
for (const page of LUOGU_SPECIFIC_PAGES) {
if (currentUrl.includes(page)) {
return true;
}
}
return false;
};
// 检查是否是洛谷网站
const isLuoguSite = () => {
const currentHostname = window.location.hostname.toLowerCase();
return currentHostname.includes('luogu.com.cn') || currentHostname.includes('luogu.com');
};
// ==================== 元素隐藏功能 ====================
// 隐藏消息红点
const hideRedDots = () => {
// 立即检查一次
setTimeout(() => {
const supElements = document.querySelectorAll('sup');
supElements.forEach(element => {
const style = element.style;
const computedStyle = window.getComputedStyle(element);
const bgColor = style.backgroundColor || computedStyle.backgroundColor;
if (bgColor === 'rgb(231, 76, 60)' ||
bgColor === '#e74c3c' ||
element.getAttribute('style')?.includes('rgb(231, 76, 60)') ||
element.getAttribute('style')?.includes('#e74c3c')) {
const text = element.textContent.trim();
if (/^\d+$/.test(text)) {
element.remove();
}
}
});
}, 0); // 立即执行
// 延迟再检查一次,处理异步加载
setTimeout(() => {
const supElements = document.querySelectorAll('sup');
supElements.forEach(element => {
const style = element.style;
const computedStyle = window.getComputedStyle(element);
const bgColor = style.backgroundColor || computedStyle.backgroundColor;
if (bgColor === 'rgb(231, 76, 60)' ||
bgColor === '#e74c3c' ||
element.getAttribute('style')?.includes('rgb(231, 76, 60)') ||
element.getAttribute('style')?.includes('#e74c3c')) {
const text = element.textContent.trim();
if (/^\d+$/.test(text)) {
element.remove();
}
}
});
}, 200); // 200ms后再检查一次
};
// 隐藏讨论区
const hideDiscussion = () => {
const contestPanels = document.querySelectorAll('.am-panel.lg-index-contest.am-panel-primary');
contestPanels.forEach(panel => panel.remove());
};
// 隐藏犇犇
const hideBenben = () => {
const commentLists = document.querySelectorAll('.am-comments-list.am-comments-list-flip');
commentLists.forEach(list => list.remove());
};
// 隐藏底部导航栏
const hideNavbar = () => {
const infoDivs = document.querySelectorAll('div[data-v-95701c92].info');
infoDivs.forEach(div => {
const walker = document.createTreeWalker(
div,
NodeFilter.SHOW_TEXT,
null,
false
);
let node;
while ((node = walker.nextNode())) {
if (node.nodeValue && node.nodeValue.trim().length > 0) {
node.nodeValue = ' ';
}
}
});
};
// 新增功能1: 移除包含特定 data-v 属性的元素
const removeElementsWithDataV = () => {
// 查找并移除包含 data-v-fdcd5a58 的元素
const elements1 = document.querySelectorAll('[data-v-fdcd5a58]');
elements1.forEach(el => el.remove());
// 查找并移除包含 data-v-0a593618 的元素
const elements2 = document.querySelectorAll('[data-v-0a593618]');
elements2.forEach(el => el.remove());
// 设置观察器监听新添加的元素
if (window.dataVObserver) {
window.dataVObserver.disconnect();
}
const observer = new MutationObserver(() => {
setTimeout(() => {
// 移除新出现的包含这些属性的元素
document.querySelectorAll('[data-v-fdcd5a58]').forEach(el => el.remove());
document.querySelectorAll('[data-v-0a593618]').forEach(el => el.remove());
}, 100);
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['data-v-fdcd5a58', 'data-v-0a593618']
});
window.dataVObserver = observer;
};
// 新增功能2: 移除 href="/article" 的元素
const removeElementsWithHrefArticle = () => {
// 查找并移除所有 href="/article" 的元素
const elements = document.querySelectorAll('[href="/article"]');
elements.forEach(el => el.remove());
// 设置观察器监听新添加的元素
if (window.hrefArticleObserver) {
window.hrefArticleObserver.disconnect();
}
const observer = new MutationObserver(() => {
setTimeout(() => {
// 移除新出现的 href="/article" 的元素
document.querySelectorAll('[href="/article"]').forEach(el => el.remove());
}, 100);
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['href']
});
window.hrefArticleObserver = observer;
};
// 处理所有洛谷元素
const processLuoguElements = () => {
hideRedDots();
hideDiscussion();
hideBenben();
hideNavbar();
// 检查URL是否包含 www.luogu.com.cn
const currentUrl = window.location.href;
if (currentUrl.includes('www.luogu.com.cn')) {
removeElementsWithDataV();
}
// 检查当前域名是否是 www.luogu.com.cn
if (window.location.hostname === 'www.luogu.com.cn') {
removeElementsWithHrefArticle();
}
};
// ==================== 观察器设置 ====================
// 设置洛谷元素观察器
const setupLuoguObserver = () => {
if (window.luoguObserver) {
window.luoguObserver.disconnect();
}
const observer = new MutationObserver(() => {
setTimeout(processLuoguElements, 100);
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true,
characterData: true,
attributeFilter: ['style', 'class', 'data-v-95701c92']
});
window.luoguObserver = observer;
};
// ==================== 主逻辑 ====================
// 主检测函数
const mainDetection = () => {
// 检查并处理外部网站
if (isExternalSite()) {
// 直接跳转到空白页
if (window.stop) {
window.stop();
}
document.documentElement.innerHTML = '';
window.location.replace('//www.luogu.com.cn');
return;
}
// 检查并处理洛谷特定页面
if (isLuoguSpecificPage()) {
// 直接跳转到空白页
if (window.stop) {
window.stop();
}
document.documentElement.innerHTML = '';
window.location.replace('//www.luogu.com.cn');
return;
}
// 如果是洛谷网站,处理元素隐藏
if (isLuoguSite()) {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
processLuoguElements();
setupLuoguObserver();
// 额外的检查以确保完全覆盖
setTimeout(processLuoguElements, 300);
setTimeout(processLuoguElements, 1000);
});
} else {
processLuoguElements();
setupLuoguObserver();
// 额外的检查以确保完全覆盖
setTimeout(processLuoguElements, 300);
setTimeout(processLuoguElements, 1000);
}
}
};
// 立即执行检测
mainDetection();
// 监听URL变化
let lastUrl = location.href;
const urlObserver = new MutationObserver(() => {
const url = location.href;
if (url !== lastUrl) {
lastUrl = url;
mainDetection();
}
});
urlObserver.observe(document, { subtree: true, childList: true });
// 监听导航事件
window.addEventListener('hashchange', mainDetection);
window.addEventListener('popstate', mainDetection);
})();