Greasy Fork

来自缓存

Greasy Fork is available in English.

蓝奏云连接转换

从蓝奏云连接转换成pan.lanzou.com解决一部分蓝奏云用户无法打开蓝奏云网站的问题!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         蓝奏云连接转换
// @namespace    http://greasyfork.icu/zh-CN/scripts/408717-%E8%93%9D%E5%A5%8F%E4%BA%91%E8%BF%9E%E6%8E%A5%E8%BD%AC%E6%8D%A2
// @version      0.5
// @description  从蓝奏云连接转换成pan.lanzou.com解决一部分蓝奏云用户无法打开蓝奏云网站的问题!
// @AuThor       KongKe
// @include       *
// @exclude    *://*.lanzou*/*
// @exclude    *://pc.woozooo.com/*
// @grant        none
// ==/UserScript==

(function() {
    function replaceLanZou(str){
        if(str!= undefined && str.indexOf("lanzou")>=0){
            console.log(str);
            console.log("发现蓝奏云链接,已进行替换!");
            return str.replace(/(https?:\/\/)?([a-zA-Z0-9\.]+)?lanzou[a-z]{1}/g,"https://pan.lanzou");
        }
        return str;
    }

    document.addEventListener('copy', function(e) {
        if(e.path[0].id != 'copy_input'){
            var content = window.getSelection().toString();
            var netContent = replaceLanZou(content);
            if(content != netContent){
                var input = document.createElement("input");
                input.setAttribute("id", "copy_input");
                input.setAttribute("value", netContent);
                document.body.appendChild(input);
                input.select();
                document.execCommand("copy");
                document.body.removeChild(input);
            }
        }
    });


    function replaceTextNode(node) {
        var children = node.childNodes;
        for (var i = 0; i < children.length; i++) {
            replaceTextNode(children[i])
        }
        if (node.nodeType === 3) {
            var data = replaceLanZou(node.data);
            if(node.data != data){
                node.data = data;
            }
        }
    }


    setTimeout(function(){
        var arr = document.getElementsByTagName("a");
        for(var i = 0;i<arr.length;i++){
            var a = arr[i];
            var href = a.getAttribute("href");
            var newHref = replaceLanZou(href);
            if(href != newHref){
                a.setAttribute("href", newHref);
            }
        }
        replaceTextNode(document);
    },1500);


})();