Greasy Fork

Greasy Fork is available in English.

蓝奏云域名替换

替换www为pan

目前为 2020-07-15 提交的版本。查看 最新版本

// ==UserScript==
// @name         蓝奏云域名替换
// @namespace    http://greasyfork.icu/zh-CN/users/6065-hatn
// @version      0.2
// @description  替换www为pan
// @icon         http://www.gravatar.com/avatar/10670da5cbd7779dcb70c28594abbe56?r=PG&s=92&default=identicon
// @author       hatn
// @copyright	 2020, hatn
// @include      *
// @run-at     	 document-start
// @grant        unsafeWindow
// ==/UserScript==
let lzyObj = {
    cat: /https:\/\/www.lanzous.com\/\S+/gi,
    targetStr: "https://pan.",
    originStr: "https://www.",
	init () {
        let i = 0, s = this;
        let urlStr = location.href;
        if (s.cat.test(urlStr)) {
            let toUrl = urlStr.replace(s.originStr, s.targetStr);
            location.href = toUrl;
        }
        let maxTimes = 100;
        let timer = setInterval(() => {
            if (i >= maxTimes) return clearInterval(timer);
            ++i;
            if (typeof jQuery == 'undefined') return;
            s.replace();
            //console.log(i, 'times');
            return clearInterval(timer);
        }, 100);
    },
    
    replace() {
        let s = this;
        let $check = $('a[href^="https://www.lanzous.com/"]');
        if ($check.length < 1) return console.log('Log: There is no match !');
        $check.each(function() {
            $s = $(this);
            let originUrl = $s.attr('href');
            if (!s.cat.test(originUrl)) return true; // 只处理分享链接
            let innerHTML = this.innerHTML;
            // console.log(originUrl, innerHTML);
            let newUrl = originUrl.replace(s.originStr, s.targetStr);
            let newHTML = innerHTML.replace(s.originStr, s.targetStr);
            // console.log(newUrl, newHTML);
            $s.attr('href', newUrl);
            this.innerHTML = newHTML;
        });
    }
};

lzyObj.init();