仓库 HTTPS 图片

把部分白名单域名内的图片更换为 https。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         仓库 HTTPS 图片
// @namespace    moe.jixun.galacg-https-image
// @version      0.1.3
// @description  把部分白名单域名内的图片更换为 https。
// @author       Jixun <https://jixun.moe/>
// @include      https://galacg.me/*
// @include      https://cangku.in/*
// @include      https://cangku.moe/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function(_xhr_send) {
    function filter (src) {
        return src.replace(/(http)(:(\/\/|\\\/\\\/)(ww\d\.sinaimg\.cn|imgsrc\.baidu\.com|(?:\w+\.)?galacg\.me|\w+\.loli\.io|[\w\.]+.127.net|(?:\w+\.)?cangku\.(in|moe))[\\\/])/g, '$1s$2');
    }

    XMLHttpRequest.prototype.send = function () {
        var _onload = this.onload;
        var self = this;
        var ret = _xhr_send.apply(this, arguments);
        this.onload = function () {
            let resp = self.response;
            let respText = self.responseText;

            Object.defineProperty(self, 'response', { value: filter(resp) });
            Object.defineProperty(self, 'responseText', { value: filter(respText) });

            if (_onload)
                return _onload.apply(this, arguments);

            var event = new Event('xhrRequestEvent');
            window.dispatchEvent(event);
        };
        return ret;
    };
})(XMLHttpRequest.prototype.send);