修复微博图片跨域展示

修复微博图片在第三方网站上无法正常显示的问题

目前為 2023-03-30 提交的版本,檢視 最新版本

// ==UserScript==
// @name              修复微博图片跨域展示
// @namespace         https://github.com/itorr/fix-sinaimg.user.js
// @version           0.11
// @description       修复微博图片在第三方网站上无法正常显示的问题
// @author            itorr
// @license           MIT
// @match             *://*/*
// @exclude           *://weibo.com/*
// @exclude           *://*.weibo.com/*
// @exclude           *://t.cn/*
// @icon              https://weibo.com/favicon.ico
// @run-at            document-end
// @grant             GM_xmlhttpRequest
// @supportURL        https://github.com/itorr/fix-sinaimg.user.js/issues
// ==/UserScript==


const isSinaImageRegex = /sinaimg\.cn\//;
const fixSinaImages = ()=>{
    [...document.images].filter(el=>isSinaImageRegex.test(el.src)).forEach(el=>{
        GM_xmlhttpRequest({
            method:'GET',
            url: el.src,
            responseType: 'blob',
            headers: {
                'referer': 'https://weibo.com/mygroups'
            },
            onload(res){
                el.src = URL.createObjectURL(res.response);
            }
        });
        el.removeAttribute('src');
    });
};

if(window.MutationObserver){
    (new MutationObserver(fixSinaImages)).observe(document.body,{
        childList: true,
        subtree: true,
        attributes: true,
    });
}else{
    document.addEventListener('DOMNodeInserted',fixSinaImages);
}

window.addEventListener('load',fixSinaImages);

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址