// ==UserScript==
// @name 网页屏蔽器
// @version 1.0.0
// @description 屏蔽列表内的网站
// @namespace chemcat
// @license MIT
// @author chemcat
// @include *
// @noframes false
// @grant GM_setValue
// @grant GM_getValue
// @run-at document-start
// @supportURL chem_cat@qq.com
// ==/UserScript==
// 屏蔽网站列表
const blockedSites = {
"https://www.msn.cn/zh-cn": true
};
// 检查当前网站是否在屏蔽列表中
const currentSite = window.location.origin + window.location.pathname;
if (blockedSites[currentSite] || blockedSites[window.location.origin]) {
// 屏蔽整个页面
document.addEventListener('DOMContentLoaded', function() {
document.body.innerHTML = `
此网站已被屏蔽
网页屏蔽器已阻止访问该网站
祝你天天好心情
`;
// 移除所有脚本防止执行
const scripts = document.querySelectorAll('script');
scripts.forEach(script => script.remove());
// 阻止任何新脚本的执行
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
mutation.addedNodes.forEach(function(node) {
if (node.tagName === 'SCRIPT') {
node.remove();
}
});
});
});
observer.observe(document.documentElement, {
childList: true,
subtree: true
});
});
// 在页面加载前就阻止内容显示
if (document.readyState === 'loading') {
document.documentElement.innerHTML = `
此网站已被屏蔽
此网站已被屏蔽
网页屏蔽器已阻止访问该网站
祝你天天好心情
`;
// 停止所有网络请求
window.stop();
}
}
// 标记被屏蔽的链接
document.addEventListener('DOMContentLoaded', function() {
setInterval(() => {
const links = document.querySelectorAll('a[href]');
links.forEach(link => {
try {
const url = new URL(link.href);
if (blockedSites[url.origin] || blockedSites[url.origin + url.pathname]) {
link.style.opacity = '0.5';
link.style.pointerEvents = 'none';
link.title = '此网站已被网页屏蔽器阻止';
}
} catch (e) {
// 忽略无效URL
}
});
}, 1000);
});