// ==UserScript== // @name CNB.Cool 图片显示问题 // @version 1.0 // @description 通过 base64 编码绕过 CSP // @author IIIStudio // @match https://cnb.cool/* // @grant GM_xmlhttpRequest // @connect linux.do // @connect * // ==/UserScript== (function() { 'use strict'; // 可配置的白名单域名数组 const ALLOWED_DOMAINS = [ 'cnb.cool', 'githubusercontent.com', 'shields.io', 'qlogo.cn', 'cdn-go.cn', 'weixin.qq.com', 'github.com', 'storage.deepin.org', 'deepwiki.com', 'commit.cool', // 在此处添加新的域名 ]; // 构建正则表达式 const ALLOWED_REGEX = new RegExp( `(${ALLOWED_DOMAINS.map(domain => domain.replace('.', '\\.')).join('|')})` ); // 处理图片 function processImage(img) { if (img.dataset.processed || img.src.startsWith('data:') || ALLOWED_REGEX.test(img.src)) { return; } console.log('处理图片:', img.src); img.dataset.processed = 'true'; // 使用 GM_xmlhttpRequest 跨域请求 GM_xmlhttpRequest({ method: 'GET', url: img.src, responseType: 'blob', onload: function(response) { const reader = new FileReader(); reader.onloadend = function() { img.src = reader.result; }; reader.readAsDataURL(response.response); }, onerror: function(error) { console.error('图片加载失败:', img.src, error); } }); } // 初始处理 document.querySelectorAll('img').forEach(processImage); // 监听新图片 new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { mutation.addedNodes.forEach(function(node) { if (node.tagName === 'IMG') { processImage(node); } if (node.querySelectorAll) { node.querySelectorAll('img').forEach(processImage); } }); }); }).observe(document.body, { childList: true, subtree: true }); })();