老司机传说开发版

准备撸一个新的老司机传说,功能慢慢加,欢迎提供建议。尽量不弃坑。

Versión del día 25/07/2020. Echa un vistazo a la versión más reciente.

// ==UserScript==
// @name        老司机传说开发版
// @namespace   http://www.ocrosoft.com/
// @version     0.106
// @description 准备撸一个新的老司机传说,功能慢慢加,欢迎提供建议。尽量不弃坑。
// @author      ocrosoft
// @match       *://www.liuli.se/*
// @match       *://www.liuli.pl/*
// @match       *://blog.reimu.net/*
// @match       *://pan.baidu.com/s/*
// @match       *://pan.baidu.com/disk/home*
// @match       *://pan.baidu.com/share/init?surl=*
// @icon        https://www.liuli.pl/favicon.ico
// @grant       unsafeWindow
// ==/UserScript==
//var $ = '';

let prefix = '[老司机传说] ';
function INFO(msg) {
    console.info(prefix + msg);
}
function WARN(msg) {
    console.warn(prefix + msg);
}
function ERROR(msg) {
    console.error(prefix + msg);
}
function ELEM(element) {
    console.log(element);
}

// jQuery
let jquery_cdns = [
    'http://code.jquery.com/jquery-2.1.4.min.js',
    'http://libs.baidu.com/jquery/2.1.4/jquery.min.js',
    'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.4.min.js'
];
function CheckJQuery() {
    function InsertJQuery(url) {
        let script = document.createElement('script');
        script.src = url;
        document.head.appendChild(script);
        return script;
    }
    function ConverProtocolIfNeeded(url) {
        let is_https = location.href.indexOf('https://') != -1;
        let url_is_https = url.indexOf('https://') != -1;

        if (is_https && !url_is_https) {
            return url.replace('http://', 'https://');
        } else if (!is_https && url_is_https) {
            return url.replace('https://', 'http://');
        }
    }
    function WaitAndCheckJQuery(cdn_index, resolve) {
        if (cdn_index >= jquery_cdns.length) {
            ERROR('无法加载 JQuery,正在退出。');
            resolve(false);
            return;
        }
        let url = ConverProtocolIfNeeded(jquery_cdns[cdn_index]);
        INFO('尝试第 ' + (cdn_index + 1) + ' 个 JQuery CDN:' + url + '。');
        let script = InsertJQuery(url);
        setTimeout(function() {
            try {
                $();
                INFO('已加载 JQuery。');
                resolve(true);
            } catch (exception) {
                WARN('无法访问。');
                script.remove();
                WaitAndCheckJQuery(cdn_index + 1, resolve);
            }
        }, 100);
    }
    return new Promise(function(resolve) {
        try {
            $();
            INFO('已加载 jQuery。');
            resolve(true);
        } catch (exception) {
            INFO('未发现 JQuery,尝试加载。');
            WaitAndCheckJQuery(0, resolve);
        }
    });
}

// 窗口大小发生改变的调用方法
let resize_functions = {};
// 查找字符串所在的元素
function FindElementByText(root, text) {
    let result = [];
    let found_in_children = false;
    $.each(root.children(), function(i, child) {
        let _this = $(child);
        if (_this.text().indexOf(text) != -1) {
            let e = FindElementByText(_this, text);
            if (e.length > 0) {
                found_in_children = true;
                result = result.concat(e);
            }
        }
    });
    if (!found_in_children) {
        result.push(root);
    }
    return result;
}
// 分析提取码
function FindCodes(content, keys) {
    let codes = [];
    $.each(keys, function(i, key) {
        let split = content.split(key);
        if (split.length < 2) {
            WARN('找不到对应的提取码:' + key);
            codes.push('');
            return;
        }
        let content_to_match = split[1];
        let match = content_to_match.match(/[^a-zA-Z0-9]([a-zA-Z0-9]{4})([^a-zA-Z0-9]|$)/);
        if (match) {
            codes.push(match[1]);
        } else {
            WARN('找不到对应的提取码:' + key);
        }
    });
    let match = [];
    return codes;
}

let sites = [{
    name: '琉璃神社',
    pattern: /https:\/\/www\.liuli\.(se|pl)\/wp\/\d+\.html/,
    process: function() {
        // 处理磁力链(仅正文)
        function ProcessMagnetInContent() {
            // 提取 HASH
            function GetHashFromMagnet(magnet) {
                return magnet.toLowerCase().replace('magnet:?xt=urn:btih:', '').toUpperCase();
            }
            // 增加一个跳转下载链接的气泡
            function AddBubble(hash_match) {
                // 元素
                let comment_bubble_wrapper = $('#wpd-bubble-wrapper');
                let link_bubble_wrapper = comment_bubble_wrapper.clone();
                link_bubble_wrapper.find('#wpd-bubble-all-comments-count').text(hash_match.length).addClass('od_link_count');
                let link_bubble = link_bubble_wrapper.find('#wpd-bubble-count');
                let svg = $('<svg height="512pt" viewBox="0 -61 512 512" width="512pt" xmlns="http://www.w3.org/2000/svg"><path d="m377 0h-121l-30 37.5 30 37.5h121c33.085938 0 60 26.914062 60 60s-26.914062 60-60 60h-121l-30 37.5 30 37.5h121c74.4375 0 135-60.5625 135-135s-60.5625-135-135-135zm0 0" fill="#18e0ff"></path><path d="m256 120-30 37.5 30 37.5c33.085938 0 60 26.914062 60 60s-26.914062 60-60 60l-30 37.5 30 37.5c74.4375 0 135-60.5625 135-135s-60.5625-135-135-135zm0 0" fill="#13bdf7"></path><path d="m135 195h121v-75h-121c-74.4375 0-135 60.5625-135 135s60.5625 135 135 135h121v-75h-121c-33.085938 0-60-26.914062-60-60s26.914062-60 60-60zm0 0" fill="#18e0ff"></path><path d="m256 75v-75c-74.4375 0-135 60.5625-135 135s60.5625 135 135 135v-75c-33.085938 0-60-26.914062-60-60s26.914062-60 60-60zm0 0" fill="#13bdf7"></path></svg>');
                link_bubble.children('svg').remove();
                link_bubble.append(svg);
                link_bubble_wrapper.css({
                    'left': comment_bubble_wrapper.css('left'),
                    'bottom': parseInt(comment_bubble_wrapper.css('bottom')) + 100 + 'px',
                });
                resize_functions.liuli_resize_bubble_position = function() {
                    link_bubble_wrapper.css('left', comment_bubble_wrapper.css('left'));
                };
                // 链接
                let bubble_message = link_bubble_wrapper.find('#wpd-bubble-add-message').addClass('od_link_message');
                bubble_message.empty().css({'display': 'block', 'text-align': 'left', 'width': 'max-content', 'height': 'auto'});
                $.each(hash_match, function(index, hash) {
                    if (index > 0) {
                        bubble_message.append('<br>');
                    }
                    let link_jump = $('<a style="color:#fff;">定位到链接</a>');
                    let hash_only = GetHashFromMagnet(hash);
                    let link_download = $('<a href="magnet:?xt=urn:btih:' + hash_only + '" style="color:#fff; margin-left: 10px;">' + hash_only + '</a>');
                    link_jump.click(function() {
                        let selector = '#od_link_' + hash_only;
                        // 目标在 toggle 里面
                        if ($('.toggle-box').find(selector).length > 0) {
                            let parent = $(selector).parent();
                            while (parent.length > 0) {
                                if (parent.hasClass('toggle-box')) {
                                    if (parent.css('display') == 'none') {
                                        parent.prev().click();
                                    }
                                    break;
                                }
                                parent = parent.parent();
                            }
                        }
                        $('body, html').animate({scrollTop: $(selector).offset().top}, 500);
                    });
                    let span = $('<span></span>');
                    span.append(link_jump).append(link_download);
                    bubble_message.append(span);
                });
                // 事件
                link_bubble_wrapper.find('#wpd-bubble-count').click(function(event) {
                    let wrapper = $(this).parent();
                    wrapper.addClass('wpd-bubble-hover');
                });
                link_bubble_wrapper.find('#wpd-bubble').find('svg').css('-webkit-transform', 'rotate(45deg)');
                // 关闭只点 SVG,点弹出的链接就不会关闭了
                link_bubble_wrapper.find('#wpd-bubble').find('svg').click(function(event) {
                    let wrapper = $(this).parent().parent();
                    wrapper.removeClass('wpd-bubble-hover');
                });
                comment_bubble_wrapper.after(link_bubble_wrapper);
                // 找到了链接,主动打开一下
                if (hash_match.length > 0) {
                    link_bubble_wrapper.find('#wpd-bubble-count').click();
                }
            }
            // 过滤无效的HASH
            function FilterHash(content, hash_match_raw) {
                let hash_match = [];
                let hash_set = {};

                function IsFound(content, regex) {
                    let match = content.match(regex);
                    if (match && match.length > 0) {
                        return true;
                    }
                    return false;
                }
                $.each(hash_match_raw, function(index, hash) {
                    // 包含前缀,不检查
                    if (IsFound(content, 'magnet:\\?xt=urn:btih:' + hash)) {
                        if (hash_match.indexOf('magnet:?xt=urn:btih:' + hash) == -1) {
                            hash_match.push('magnet:?xt=urn:btih:' + hash);
                        }
                        return;
                    }
                    let regexs = [
                        '\/' + hash, // 前面跟了一个斜杠,可能是目录名
                        hash + '\/', // 后面跟了一个斜杠,可能是目录名
                        hash + '\.', // 后面一个点,可能是文件名
                    ];
                    let is_valid = true;
                    $.each(regexs, function(index_, regex) {
                        if (IsFound(content, regex)) {
                            is_valid = false;
                            return false;
                        }
                    });
                    if (is_valid && hash_match.indexOf(hash) == -1) {
                        hash_match.push(hash);
                    }
                });

                return hash_match;
            }

            let e_content = $('.entry-content');
            let content = e_content.text();
            let hash_match_raw = content.match(/([a-zA-Z0-9]{40})|([a-zA-Z0-9]{32})/g);
            ELEM(hash_match_raw);
            if (!hash_match_raw) {
                INFO('找不到任何磁力链接。');
                return;
            }
            let hash_match = FilterHash(content, hash_match_raw);
            ELEM(hash_match);
            if (!hash_match) {
                INFO('找不到有效的磁力链接。');
                return;
            }

            // HASH 替换成老司机链接
            $.each(hash_match, function(index, hash) {
                let replace_text = '';
                let hash_only = GetHashFromMagnet(hash);
                replace_text = '<br><a id="od_link_' + hash_only + '" href="magnet:?xt=urn:btih:' + hash + '">老司机链接</a>(' + hash_only + ')<br>';
                // 不能修改整个 content,会导致 toggle 展不开
                let elements = FindElementByText(e_content, hash);
                $.each(elements, function(i, element) {
                    element.get(0).innerHTML = element.get(0).innerHTML.replace(hash, replace_text);
                });
            });

            AddBubble(hash_match);
        }
        // 处理百度链接(仅评论区,新版链接)
        function ProcessBaiduNetdiskInComment() {
            // 从链接取出提取链接
            function GetKeyFromBaiduNetdiskLink(link) {
                if (link.indexOf('/s/') != -1) return link.replace('/s/', '');
                if (link.indexOf('s/') != -1) return link.replace('s/', '');
                return link;
            }
            // 过滤无效的提取链接
            function FilterCommentsKey(e_comments_raw) {
                let e_comments = [];

                $.each(e_comments_raw, function(i, comments) {
                    let e = comments.e;
                    let text = e.text();
                    let match = comments.key_match;
                    let keys = [];
                    $.each(match, function(i, key) {
                        // 前后有数字或字母
                        if (text.match('[0-9a-zA-Z]' + key) ||
                            text.match(key + '[0-9a-zA-Z]')) {
                            return;
                        }
                        // /s/***
                        if (text.match('\/s\/' + key)) {
                            keys.push('/s/' + key);
                            return;
                        }
                        // s/***
                        if (text.match('s\/' + key)) {
                            keys.push('s\/' + key);
                            return;
                        }
                        if (key.length == 22) {
                            key = '1' + key;
                        }
                        // 其他的不管
                        keys.push(key);
                    });
                    let codes = FindCodes(text, keys);
                    e_comments.push({
                        e: e,
                        keys: keys,
                        codes: codes,
                    });
                });

                return e_comments;
            }
            // 追加到气泡
            function AppendToBubble(e_comments) {
                let e_link_count = $('.od_link_count');
                let e_link_message = $('.od_link_message');
                let link_count_now = parseInt(e_link_count.text());
                $.each(e_comments, function(i, comment) {
                    let e = comment.e;
                    let keys = comment.keys;
                    let codes = comment.codes;

                    for (let key_id = 0; key_id < keys.length; ++key_id) {
                        if (link_count_now > 0) {
                            e_link_message.append('<br>');
                        }
                        let key = keys[key_id];
                        let span = $('<span></span>');
                        let link_jump = $('<a style="color:#fff;">定位到评论</a>');
                        let key_only = GetKeyFromBaiduNetdiskLink(key);
                        let code_text = (codes.length == 0 ? '(无提取码)' : '(' + codes[key_id] + ')');
                        let code_in_href = (codes.length == 0 ? '' : '#tq=' + codes[key_id]);
                        let link_download = $('<a target="_blank" href="https://pan.baidu.com/s/' + key_only + code_in_href + '" style="color:#fff; margin-left: 10px;">' + key_only + code_text + '</a>');
                        link_jump.click(function() {
                            $('body, html').animate({scrollTop: e.offset().top}, 500);
                        });
                        span.append(link_jump).append(link_download);
                        e_link_message.append(span);
                        link_count_now += 1;
                    }
                    e_link_count.text(link_count_now);
                });
            }

            let comment_count = parseInt($('#wpd-threads').find('.wpd-thread-info ').find('.wpdtc').text());
            if (comment_count == 0) {
                return;
            }
            let itv = setInterval(function() {
                let e_comment_text = $('.wpd_comment_level-1');
                let e_comments_raw = [];
                if (e_comment_text.length == 0) return;
                clearInterval(itv);
                $.each(e_comment_text, function(i, e_comment) {
                    let e_content = $(e_comment).find('.wpd-comment-text:first');
                    // 貌似 22 长度的是 surl= 版本的,前面加个 1 就能用 /s/
                    let key_match = e_content.text().match(/[a-zA-Z0-9-_]{22,23}/g);
                    if (key_match && key_match.length > 0) {
                        e_comments_raw.push({e: e_content, key_match: key_match});
                    }
                });
                ELEM(e_comments_raw);
                let e_comments = FilterCommentsKey(e_comments_raw);
                ELEM(e_comments);

                $.each(e_comments, function(i, comment) {
                    let e_comment = comment.e;
                    let keys = comment.keys;
                    let codes = comment.codes;

                    for (let key_id = 0; key_id < keys.length; ++key_id) {
                        let e = e_comment.get(0);
                        let key = keys[key_id];
                        let code = codes[i];
                        let code_in_href = (code == null ? '' : '#tq=' + code);
                        let key_only = GetKeyFromBaiduNetdiskLink(key);
                        let replace_html = '<a target="_blank" style="padding-left: 5px;" href="https://pan.baidu.com/s/' + key_only + code_in_href + '">前往百度网盘</a>'
                        e.innerHTML = e.innerHTML.replace(key, key + replace_html);
                    }
                });

                AppendToBubble(e_comments);
            }, 100);
        }

        ProcessMagnetInContent();
        ProcessBaiduNetdiskInComment();
    },
}, {
    name: '灵梦御所',
    pattern: /https:\/\/blog.reimu.net/,
    process: function() {
        // 从链接取出提取链接
        function GetKeyFromBaiduNetdiskLink(url) {
            //
        }
        // 展开隐藏内容
        function ExpandHideContent() {
            function ResetBtnPosition() {
                let btn = $('#od_link_btn');
                let margin_right = parseInt($('#main').children('article').css('margin-right'));
                let left = $('#main').offset().left + parseInt($('#main').css('width')) - margin_right;
                if (margin_right == 0) {
                    left -= parseInt($('#main').children('article').children('header').css('padding-right'));
                }
                let top = parseInt($('#main').css('padding-top'));
                if ($('.secondary-toggle').css('display') == 'block') {
                    top += parseInt($('.sidebar').css('height'));
                }
                btn.css({
                    'left': left + 'px',
                    'top': top + 'px',
                });
            }

            let btn = $('<button id="od_link_btn" style="position: fixed; top: 0px; left: 0px; display: none;">前往并展开隐藏内容</button>');
            btn.click(function() {
                let e_hide_content = $('.entry-content').find('pre');
                e_hide_content.css('display', 'block');
                $('body, html').animate({scrollTop: $(e_hide_content).offset().top}, 500);
            });
            $('body').append(btn);
            ResetBtnPosition();

            resize_functions.reimu_resize_btn_position = ResetBtnPosition;
        }
        // 磁力链接
        function ProcessMagnetInContent() {
            // TODO
        }
        // 秒传链接
        function ProcessFastLinkInContent() {
            let e_content = $('.entry-content').find('pre');
            let content = e_content.text();
            let link_match = content.match(/[0-9A-F]{32}#[0-9A-F]{32}#\d+#.*\n/g);
            ELEM(link_match);
            if (!link_match) {
                INFO('没有秒传链接');
                return;
            }

            $.each(link_match, function(i, link) {
                let e = e_content.get(0);
                let encoded = encodeURIComponent(link);
                let replace_html = '<a target="_blank" style="color: #55c3dc;" href="https://pan.baidu.com/disk/home#/all?path=%2F&vmode=list&mc=' + encoded + '">前往百度网盘</a>' + link + '<br>';
                e.innerHTML = e.innerHTML.replace(link, replace_html);
            });
        }
        // 百度链接附加提取码
        function ProcessBaiduNetDiskCode() {
            // 御所都是完整的百度网盘链接,不需要找
            let e_content = $('.entry-content').find('pre');
            let e_links = e_content.find('a');

            let found_valid_element = false;
            $.each(e_links, function(i, e_link) {
                let _this = $(e_link);
                let link_href = _this.attr('href');
                let match = link_href.match(/https:\/\/pan\.baidu\.com\/s\/[a-zA-Z0-9-_]{23}/);
                if (match) {
                    let temp_span = $('<span style="display: none;">' + match[0] + '</span>');
                    _this.after(temp_span);
                    let codes = FindCodes(e_content.text(), match);
                    if (codes.length > 0) {
                        _this.attr('href', link_href + '#tq=' + codes[0]);
                    } else {
                        WARN('找不到对应的提取码:' + link_href);
                    }
                    temp_span.remove();
                    found_valid_element = true;
                }
            });
            if (!found_valid_element) {
                INFO('找不到百度网盘链接。');
                return;
            }
        }

        ExpandHideContent();

        let current_href = '';
        let processed = false;
        setInterval(function() {
            let btn_visible = ($('#od_link_btn').css('display') != 'none');
            let has_hide_content = $('.entry-content').find('pre').length > 0;
            if (has_hide_content) {
                if (!btn_visible) {
                    $('#od_link_btn').show();
                }
            } else {
                if (btn_visible) {
                    $('#od_link_btn').hide();
                }
            }
            let processed = $('.entry-content').find('pre').hasClass('od_processed');
            if (has_hide_content && !processed) {
                $('.entry-content').find('pre').addClass('od_processed');
                ProcessMagnetInContent();
                ProcessFastLinkInContent();
                ProcessBaiduNetDiskCode();
            }
        }, 100);
    },
}, {
    name: '百度网盘-主页-秒传',
    pattern: /https:\/\/pan\.baidu\.com\/disk\/home.*&mc=/,
    process: function() {
        // 加载秒传链接
        function LoadFastLink() {
            let detect_count = 0;
            let itv = setInterval(function() {
                let href = location.href;
                let match = href.match(/&mc=([^&#]+)/);
                if (!match) {
                    clearInterval(itv);
                    ERROR('找不到秒传链接!');
                    return;
                }
                let fast_link = decodeURIComponent(match[1]);
                let btn = $('#fast_link_btn');
                if (btn.length == 0) {
                    if (++detect_count >= 50) {
                        ERROR('未安装秒传插件,即将退出。');
                        INFO('需要安装:https://greasyfork.org/zh-CN/scripts/397324');
                        clearInterval(itv);
                        return;
                    }
                    if (detect_count % 10 == 0) {
                        WARN('未安装秒传插件,剩余尝试次数:' + (50 - detect_count));
                    }
                    return;
                }
                clearInterval(itv);
                btn.click();
                setTimeout(function() {
                    $('.swal2-textarea').val(fast_link);
                    //$('.swal2-confirm').click();
                }, 100);
            }, 100);
        }

        LoadFastLink();
    },
}, {
    name: '百度网盘-分享',
    pattern: /https:\/\/pan\.baidu\.com\/s\/.*#tq=|https:\/\/pan\.baidu\.com\/share\/init\?surl=.*#tq=/,
    process: function() {
        let code_match = location.href.match(/#tq=([^&]+)/);
        if (!code_match) {
            ERROR('找不到提取码。');
            return;
        }
        let code = code_match[1];
        let input = [];
        let dt = FindElementByText($('.verify-input'), '请输入提取码');
        if (dt.length == 0) {
            WARN('找不到输入框,尝试其他方式。');
        } else {
            input = dt[0].next().find('input');
            if (input.length == 0) {
                WARN('找不到输入框,尝试其他方式。');
                input = $('input[tabindex="1"]');
            }
        }
        if (input.length == 0) {
            ERROR('找不到输入框,请手动填写。');
            return;
        }
        input.val(code);
        let btn = $('#submitBtn');
        btn.click();
    },
}];

CheckJQuery().then(function(success) {
    if (!success) {
        return;
    }

    let url = location.href;
    $.each(sites, function(index, site) {
        if (!url.match(site.pattern)) {
            return;
        }
        INFO(site.name);
        site.process();

        return false;
    });

    $(window).resize(function() {
        $.each(resize_functions, function(name, func) {
            func();
        });
    });
});

//执行函数
/*function a(){
    'use strict';
    //灵梦御所
    if(host=="blog.reimu.net"){
        var titleTime;
        if(boxON[1])addBox();
        //开启老司机模式
        if(ifshow()){
            var pre = document.getElementsByTagName('pre');
            for(var rmi=0;rmi<pre.length;rmi++){
                if (pre[rmi]) pre[rmi].style.display = 'block';
                var textrei=pre[rmi].innerHTML;
                if(textrei){
                    var cilirei=textrei.match(/magnet:?[^\n"]+/);
                    pre[rmi].innerHTML=textrei.replace(cilirei,'<a href="'+cilirei+'">'+cilirei+'</a>');
                }
            }
        }
        //添加直接跳转到下载链接的按钮
        var oD_box=document.createElement("div");
        oD_box.style.zindex="999999";
        oD_box.id="goToDownload";
        oD_box.style="position:fixed;top:60px;right:0px;width:40px;transition: all 0.2s ease;white-space:nowrap;z-index:99998";
        var oD_button=document.createElement("button");
        oD_button.id="goToDownload_button";
        oD_button.type="button";
        oD_button.innerHTML="前往<br/>下载";
        oD_button.style="padding: 4px 0px; position: absolute; top: -1px; right: 0px; width: 40px; height: auto;";
        oD_button.onclick=function (){
            if(document.getElementsByTagName('pre').length>1)alert("下载链接可能不止一个,将跳转到第一个!");
            document.getElementsByTagName('pre')[0].scrollIntoView();
        };
        oD_box.appendChild(oD_button);
        document.body.appendChild(oD_box);
    }
    //调整跳转链接
    else if(host.indexOf('hacg')!=-1||host.indexOf('llss')!=-1||host.indexOf('liuli')!=-1||host.indexOf('tianshit')!=-1){//琉璃神社\天使二次元
        if((host.indexOf('hacg')!=-1 || host.indexOf('llss')!=-1 || host.indexOf('liuli')!=-1)&&boxON[0])addBox();
        if(host.indexOf('tianshit')!=-1&&boxON[4])addBox();
        var aaa=$(".entry-title a");
        for(var j=0;j<aaa.length;j++){
            var ax=aaa[j];
            var dir=ax.href.indexOf(':');
            ax.href="https"+ax.href.substring(dir);
        }
        //调整神秘代码
        var toogle = document.getElementsByClassName('toggle-box')[0];
        if (toogle) toogle.style.display = 'block';
        var oldDriver = document.getElementsByClassName('entry-content')[0];
        if(host.indexOf('tianshit')!=-1)oldDriver=document.getElementsByClassName('article-content')[0];
        var childDriver = oldDriver.childNodes;
        for (var i = childDriver.length - 1; i >= 0; i--){
            var takeMe = childDriver[i].textContent.match(/(\w{40})|(([A-Za-z0-9]{2,39})( ?)[\u4e00-\u9fa5 ]{2,}( ?)+(\w{2,37})\b)/g);
            if (takeMe){
                for (j = 0; j < takeMe.length; ++j){
                    var has = takeMe[j].toString().replace(/(\s|[\u4e00-\u9fa5])+/g, '').trim();
                    if (has.length >= 40){
                        var fuel = "<a href='magnet:?xt=urn:btih:" + has + "'>老司机链接</a>"+"("+has+")";
                        if(childDriver[i].innerHTML)
                            childDriver[i].innerHTML = childDriver[i].innerHTML.toString().replace(takeMe[j], fuel);
                        else if(childDriver[i].parentElement)
                            if(childDriver[i].parentElement.innerHTML)
                                childDriver[i].parentElement.innerHTML=childDriver[i].parentElement.innerHTML.replace(takeMe[j], fuel);
                    }
                }
            }
            else{
                takeMe=childDriver[i].textContent.match(/(\w{32})|(([A-Za-z0-9]{2,31})( ?)[\u4e00-\u9fa5 ]{2,}( ?)+(\w{2,29})\b)/g);
                if(takeMe){
                    for (j = 0; j < takeMe.length; ++j){
                        var has2 = takeMe[j].toString().replace(/(\s|[\u4e00-\u9fa5])+/g, '').trim();
                        if (has2.length >= 32){
                            var fuel2 = "<a href='magnet:?xt=urn:btih:" + has2 + "'>老司机链接</a>"+"("+has2+")";
                            childDriver[i].innerHTML = childDriver[i].innerHTML.toString().replace(takeMe[j], fuel2);
                        }
                    }
                }
            }
        }
        //小八链接
        var buDang=document.getElementsByClassName('comment-content');
        for (i in buDang){
            if(buDang[i].innerHTML){
                buDang[i].innerHTML=buDang[i].innerHTML.replace(/b?\/?s?\/?\b(\w{8})\b/g,"<a href='http://pan.baidu.com/s/$1'>百度网盘</a>");
            }
        }
    }
    //百度云填写验证码
    else{
        var sCode = hash.slice(1).trim();
        if(sCode==='')return;
        setTimeout (function (){
            codeBox = $('.pickpw').find('input');
            btnOk = $('.pickpw').find('.g-button');
            if(codeBox)
            {
                codeBox.val(sCode);
                btnOk.click();
            } else {
                var codeBox = $(conf.code),btnOk = $(conf.btn);
                codeBox.val(sCode);
                if (conf.preSubmit)
                    if (conf.preSubmit (codeBox, btnOk))
                        return ;
                btnOk.click();
            }
        }, 10);
    }
})();
var hostName = location.host.match(/\w+\.\w+$/)[0].toLowerCase();
var conf = site[hostName];
var HostArr = [];
for(var i in site) HostArr.push(i);
var HostExp = new RegExp(HostArr.join("|"),'i');
if(site.JumpUrl[host]){
    site.JumpUrl[host].each(function(){
        $(this).attr({'href':$(this).text(),'target':'blank'});
    });
}
//跳转(点击链接、前进后退)时开启老司机模式
function lsjmodeON(){
    if(urls.indexOf("archives")!=-1){
        var pret = document.getElementsByTagName('pre')[0];
        if(pret)pret.style.display='inline';//文章页跳转文章页特殊处理
    }
    if(urls==location.href){
        var pret2 = document.getElementsByTagName('pre')[0];
        if(pret2)pret2.style.display='block';//文章页跳转文章页特殊处理
        return;
    }
    $("#attention").remove();
    urls=location.href;
    var re=urls.indexOf("archives");
    if(re!=-1){
        var pre = document.getElementsByTagName('pre')[0];
        var trytime=0;
        var itval=setInterval(function (){
            var pre = document.getElementsByTagName('pre')[0];
            trytime+=1;
            if(trytime==40)clearInterval(itval);
            if(pre){
                if(pre.style.display!='inline'){
                    if(ifshow()){
                        var prex = document.getElementsByTagName('pre');
                        for(var rmi=0;rmi<prex.length;rmi++)
                            if (prex[rmi]) prex[rmi].style.display = 'block';
                        //pre.style.display='block';
                        clearInterval(itval);
                    }
                    else clearInterval(itval);
                }
            }
        },500);
    }
}
//监控点击事件
$('body').on('click', 'a', function (){
    if(host=="blog.reimu.net")lsjmodeON();
    //整合提取码和链接
    if(aiON===0)return;
    var target=this;
    if(this.hash) return;
    if(HostExp.test(this.href)&&!/(?:eyun|tieba)\.baidu\.com/i.test(this.href)){
        if(target.nextSibling&&site['codeRule'].test(target.nextSibling.textContent.trim())){
            if(!/#/i.test(target.href)) target.href+='#'+extCode(target.nextSibling);}
        else{
            var cajhc=target.nextSibling.data;
            if(!cajhc)cajhc=target.nextSibling.text;
            if(cajhc.indexOf(":")!=-1){
                target.href+='#'+cajhc.substring(cajhc.indexOf(":")+1,cajhc.indexOf(":")+3);
            }
            else target.href+='#8酱';
        }
    }
});
//提取码
function extCode(obj){
    text=obj.textContent.trim();
    var rule=new RegExp('(?:提取|访问)[码碼]?\s*[:: ]?\\s*([a-z\\d]{4})','i');
    return rule.test(text)?text.match(rule)[1]:text.match(site['codeRule'])[1];
}
//老司机快捷键,并移除重口味提示
jQuery(document).keypress(function(e){
    if(odON===0)return;//快捷键无效
    if(e.ctrlKey && e.which == 13 || e.which == 10) {
        var pre = document.getElementsByTagName('pre');
        for(var rmi=0;rmi<pre.length;rmi++)
            if (pre[rmi]) pre[rmi].style.display = 'block';
        $("#attention").remove();
    }
});
//支持前进后退
jQuery(document).ready(function ($) {
    if (window.history && window.history.pushState) {
        $(window).on('popstate', function () {
            var hashLocation = location.hash;
            var hashSplit = hashLocation.split("#!/");
            var hashName = hashSplit[1];
            if (hashName !== '') {
                var hash = window.location.hash;
                if (hash === '') lsjmodeON();
            }
        });
    }
});*/