HacgGodTurn

Tools for OLD DRIVER to adult gentleman sites (Just a joke, you won't want to read forward) as glazed shrine, reimu imperial, pure love plan, gentleman two dimension, dimension and dimension trajectory, adorable heart ACG survey team, the magic day in the field, light agency, two dimensional, adorable Angel Sakura diffuse homes, Shengguang, love nest, Campanula dimension barrage, fantasy element, our opportunities, some adorable

// ==UserScript==
// @name        琉神转-改
// @name:en     HacgGodTurn
// @name:zh-TW  琉神轉-改
// @name:ja     琉璃神社工具セット
// @namespace   wangyan-life
// @description         老司机工具箱,支持琉璃神社、灵梦御所、纯爱计划、绅士二次元、萌心次元、次元轨迹、ACG调查小队、幻天领域、天使二次元、樱花漫舍、风铃窝、次元の圣光、爱弹幕、幻想次元、司机会所、里番萌、最ACG、绅士仓库、绅士图书馆、ACG和谐区/里世界、寂月神社、萌幻之乡、绅士之庭、萌口组、九妖萌、CE家族社、喵窝、次元老司机、绅士ACG社等,神秘代码转换成下载链接,网盘自动填写提取密码,F8、Shift+F8站点切换,Alt+F8列表浏览,左右方向键文章跳转,Ctrl+左右快捷翻页,Ctrl+上下跳入跳出,下载链接嗅探,绕过重定向跳转,各种和谐补丁
// @description:en      Tools for OLD DRIVER to adult gentleman sites (Just a joke, you won't want to read forward) as glazed shrine, reimu imperial, pure love plan, gentleman two dimension, dimension and dimension trajectory, adorable heart ACG survey team, the magic day in the field, light agency, two dimensional, adorable Angel Sakura diffuse homes, Shengguang, love nest, Campanula dimension barrage, fantasy element, our opportunities, some adorable
// @description:zh-TW   老司機工具箱,支持琉璃神社、靈夢禦所、純愛計劃、紳士二次元、萌心次元、次元軌跡、ACG調查小隊、幻天領域、天使二次元、櫻花漫舍、風鈴窩、次元の聖光、愛彈幕、幻想次元、司機會所、裏番萌、最ACG、紳士倉庫、紳士圖書館、ACG和諧區/裏世界、寂月神社、萌幻之鄕、紳士の庭、萌口組、九妖萌、CE家族社、喵窩、次元老司機、紳士ACG社等,神秘代碼轉換成下載鏈接,網盤自動填寫提取密碼,F8、Shift+F8站點切換,Alt+F8列表瀏覽,左右方向鍵文章跳轉,Ctrl+左右快捷翻頁,Ctrl+上下跳入跳出,下載鏈接嗅探,繞過重定向跳轉,各種和諧補丁
// @description:ja      琉璃神社工具セット、秋の名山老運転手専用
// @author      wangyan-life
// @icon        https://www.hacg.me/favicon.ico
// @include     http*://www.hacg.*/wordpress/*
// @include     http*://hacg.*/wordpress/*
// @include     http*://www.hacg.lol/*
// @include     http*://hacg.lol/*
// @include     http*://hacg.riwee.com/*
// @include     http*://9iacg.*
// @include     http*://okloli.*
// @include     http*://www.okloli.*
// @include     http*://www.h2024.me/*
// @include     http*://hacg.me/*
// @include     http*://hacg.in/*
// @include     http*://hacg.be/*
// @include     http*://hacg.club/*
// @include     http*://hacg.li/*
// @include     http*://hacg.fi/*
// @include     http*://hacg.red/*
// @include     http*://hacg.la/*
// @include     http*://hacg.tw/*
// @include     http*://hacg.at/*
// @include     http*://hacg.ch/*
// @include     http*://llss.*/wp/*
// @include     http*://*.llss.*/wp/*
// @include     http*://liuli.*/wp/*
// @include     http*://*.liuli.*/wp/*
// @include     http*://hacg.*/wp/*
// @include     http*://*.hacg.*/wp/*
// @include     http*://www.acgpy.*
// @include     http*://blog.reimu.net/*
// @include     http*://pan.baidu.com/share/*
// @include     http*://pan.baidu.com/s/*
// @include     http*://www.moxacg.com/*
// @include     http*://moxacg.*
// @include     http*://*.acggj.com/*
// @include     http*://www.tianshit.com/*
// @include     http*://www.tianshif.com/*
// @include     http*://www.tianshie.com/*
// @include     http*://www.oomoe.*
// @include     http*://www.kaze5.com/*
// @include     http*://lifanmoe.*
// @include     http*://www.yhacg.*
// @include     http*://www.idanmu.*
// @include     http*://idanmu.*
// @include     http*://*.sijihuisuo.club/*
// @include     http*://sijihuisuo.club/*
// @include     http*://acg18.*
// @include     http*://*.acg18.*
// @include     http*://hxcy.*
// @include     http*://zuiacg.*
// @include     http*://www.zuiacg.*
// @include     http*://www.galacg.me/*
// @include     http*://cangku.*
// @include     http*://acgzone.org/*
// @include     http*://www.acgzone.org/*
// @include     http*://acgmoon.*
// @include     http*://www.jiyue.*
// @include     http*://jiyue.*
// @include     http*://www.moe-acg.*/*
// @include     http*://huan.moe*
// @include     http*://*.hmoe*
// @include     http*://*.hentaiclub.net*
// @include     http*://*.sshs.cc/*
// @include     http*://www.mygalgame.com/*
// @include     http*://www.mmgal.com/*
// @include     http*://htai.*
// @include     http*://gmgard.com/*
// @include     http*://*.gmgard.com/*
// @include     http*://hggard.com/*
// @include     http*://*.hggard.com/*
// @include     http*://www.kou.moe/*
// @include     http*://cefamilie.com/*
// @include     http*://www.xiu.moe/*
// @include     http*://www.cld1.net/*
// @include     http*://sjhs*.*
// @include     http*://*comicat.*
// @include     http*://*kisssub.*
// @include     http*://*miobt.*
// @include     http*://www.dakashangche.*
// @include     http*://www.dakaba.*
// @include     http*://xiuxiqu.*
// @include     https://www.reddit.com/*
// @include     http*://sleazyfork.org/*/scripts/*
// @include     http*://greasyfork.org/*/scripts/*
// @include     http*://sleazyfork.org/*/forum/*discussion*
// @include     http*://greasyfork.org/*/forum/*discussion*
// @version     3.22.72
// @grant       GM_xmlhttpRequest
// @grant       GM_setClipboard
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       unsafeWindow
// @run-at      document-end
// @require     https://update.greasyfork.org/scripts/512762/1465452/od.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/core-min.js
// @require     https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js
// @license     MIT License
// @connect     tts.baidu.com
// @compatible        chrome
// @compatible        firefox
// @compatible        opera 未测试
// @compatible        safari 未测试
// ==/UserScript==
/*
通用快捷键:
    F8或者shift+F8向前或向后循环宅站列表
    ← →快速定位到上一篇或下一篇文章
    Ctrl+← →快速翻页
    Ctrl+↑ ↓进入文章内容页或返回
    Alt+F8打开绅士站点列表
    Ctrl+F8打开火箭嗅探窗口
    Ctrl+Z开启或关闭NSFW模式

最ACG快捷键:
    点击图片去除和谐力量
    按住Ctrl点击图集或文章页面的下载按钮直接跳转至百度盘

火箭功能,嗅探并显示所有下载链接,点击序号定位至页面中资源所在位置

老司机输入框输入链接:https://pan.baidu.com/s/xxxxxxxx 密码:yyyy或者xxxxxxxx yyyy等可跳转至:https://pan.baidu.com/s/xxxxxxxx#yyyy
*/
(function(){
    'use strict';
    var config={
        sites:[
            {
                name:"琉璃神社",
                url:"https://www.hacg.icu/wp/",
                regex:/hacg\.|llss\.|liuli\./,
                commArea:"comments-area",
                run:function(){
                    var feiZao,feiZaos=document.querySelectorAll("p1"),i;
                    for(i=0;i<feiZaos.length;i++){
                        feiZao=feiZaos[i];
                        if(feiZao.parentNode)feiZao.parentNode.removeChild(feiZao);
                    }
                    var has8=false;
                    var comm,comms=document.querySelectorAll("span.fn"),commId;
                    for(i=0;i<comms.length;i++){
                        comm=comms[i];
                        if(comm.innerText == "\u5c0f\u0038\u9171"){
                            has8=true;
                            commId=comm.parentNode.parentNode.parentNode.id;
                            break;
                        }
                    }
                    if(has8){
                        var header=document.querySelector("div.entry-meta");
                        if(header){
                            header.innerHTML+="</br> <a href=\"#"+commId+"\">\u2605\u0020\u76f4\u8fbe\u8865\u6863\u59ec\u0020\u2605<\/a>";
                        }
                    }
                    if(isHttps){
                        changeUrl(true,[["iframe"],[['http:','https:']]]);
                        changeUrl(true,[["embed"],[['http:','https:']]]);
                        changeUrl(true,[["object"],[['http:','https:']]]);
                        changeUrl(true,[["a"],[['http:(.*(hacg|llss))','https:$1']]]);
                    }
                    if(document.querySelector(".metaslider-flex")){
                        document.title = document.title.replace(/\u7409\u7483\u795e\u793e/,"\u7409\u7483 ♂ \u795e\u793e");
                        [].forEach.call(document.querySelectorAll("a"), function(item, index, arr) {
                            item.innerHTML=item.innerHTML.replace(/\u7409\u7483\u795e\u793e/,"\u7409\u7483 ♂ \u795e\u793e");
                            item.title="\u630a\u591a\u4f1a\u5bfc\u81f4\u89c6\u7ebf\u6a21\u7cca\uff0c\u8fd9\u662f\u5047\u7ad9\uff01";
                        });
                    }
                    var tags=document.querySelectorAll("article>footer>a");
                    for(i=0;i<tags.length;i++){
                        var tag=tags[i];
                        if(tag.innerHTML == "\u4f2a\u5a18" || tag.innerHTML == "\u53ef\u7231\u7684\u7537\u5b69\u5b50" || tag.innerHTML == "\u5973\u88c5" || tag.innerHTML == "\u7537\u306e\u5a18"){
                            var articleTitle=document.querySelector(".entry-title");
                            if(articleTitle){
                                articleTitle.innerHTML="<font color='red' title='!\u53cd\u9e21\u590d\u5976!'>\u2642\u8def\u897f\u6cd5\u2642</font> "+articleTitle.innerHTML;
                                originTitile = document.title = document.title.replace(/\u7409\u7483\u795e\u793e/,"\u5927\u5c4c\u795e\u793e");
                            }
                            break;
                        }
                    }
                    var embeds=document.querySelectorAll(".wp-embedded-content");
                    for(i=0;i<embeds.length;i++){
                        let embed=embeds[i];
                        embed.onload=function(){
                            setTimeout(function(){
                                embed.removeAttribute("data-secret");
                            },1);
                        };
                    }
                    if(unsafeWindow.quote){
                        var msg = "…" + unsafeWindow.quote + "…",pos = 0;
                        function scrollMsg() {
                            document.title = msg.substring(pos, msg.length) + msg.substring(0, pos);
                            pos++;
                            if (pos >  msg.length) {
                                pos = 0;
                                document.title = originTitile;
                            }else{
                                setTimeout(scrollMsg,250);
                            }
                        }
                        scrollMsg();
                    }
                }
            },
            {
                name:"灵梦御所",
                url:"https://blog.reimu.net/",
                regex:/blog\.reimu\./,
                run:function(){
                    var titleTime;
                    document.addEventListener('visibilitychange', function() {
                        if (document.hidden) {
                            document.title = '\u6765\u556a\u0038\u5566~(*´∇`*) ' + originTitile;
                            clearTimeout(titleTime);
                        }
                        else {
                            document.title = '\u624d\u4e0d\u7ed9\u556a(╯‵□′)╯︵┻━┻ ' + originTitile;
                            titleTime = setTimeout(function() {
                                document.title = originTitile;
                            }, 2000);
                        }
                    });
                    function createBlockBtn(){
                        var pre = document.querySelector("pre");
                        var author = document.querySelector(".author-info,.entry-footer");
                        if (author && !document.querySelector("#blockBtn")) {
                            var blockBtn=document.createElement("button");
                            blockBtn.id="blockBtn";
                            blockBtn.type="button";
                            blockBtn.textContent="\u597d\u5b69\u5b50\u770b\u4e0d\u5230";
                            blockBtn.style.cssText="padding:4px 0;position: relative;width:120px;";
                            if(pre){
                                pre.parentNode.insertBefore(blockBtn,pre);
                            }else{
                                blockBtn.style.cssText="display:none;";
                                author.appendChild(blockBtn);
                            }
                            blockBtn.addEventListener("click", function(){
                                if(this.nextSibling.style.display == 'block'){
                                    this.nextSibling.style.display = '';
                                }else{
                                    this.nextSibling.style.display = 'block';
                                }
                            });
                        }
                    }
                    document.querySelector("#main").addEventListener('DOMNodeInserted', function(e) {
                        var author = document.querySelector(".author-info");
                        if (author && !document.querySelector("#blockBtn")) {
                            createBlockBtn();
                            process();
                            var $=unsafeWindow.jQuery;
                            var toggle=$(".toggle")[0];
                            if(toggle){
                                var evts=$._data(toggle, "events");
                                if(!evts || !evts["click"]){
                                    $(".toggle-box").hide();
                                    $(".toggle").toggle(function(){
                                        $(this).addClass("toggle-active");
                                    }, function () {
                                        $(this).removeClass("toggle-active");
                                    });
                                    $(".toggle").click(function(){
                                        $(this).next(".toggle-box").slideToggle();
                                    });
                                }
                            }
                        }
                    });
                    createBlockBtn();
                }
            },
            {
                name:"天使二次元",
                url:"https://www.tianshie.com/",
                regex:/tianshi.\./,
                contentArea:'.article-content'
            },
            {
                name:"爱弹幕",
                url:"http://www.idanmu.co/",
                regex:/idanmu\./,
                downloadUrl:/idanmu\..*\/download/,
                offset:55,
                articleSel:"section.card",
                run:function(){
                    var resets = document.querySelectorAll('body>style');
                    for(var i=0;i<resets.length;i++){
                        var reset=resets[i];
                        if(/\.card-bg\simg|\.content-reset\simg/.test(reset.innerHTML)){
                            reset.parentNode.removeChild(reset);
                        }
                    }
                    var r10=document.querySelector('#menu-header>li');
                    if(r10){
                        var r18=r10.cloneNode(true);
                        r18.innerHTML = r18.innerHTML.replace("资讯", 'R18').replace(/category\/v01/g, 'category/v09/v13');
                        r10.after(r18);
                    }
                }
            },
            {
                name:"幻想次元",
                url:"https://hxcy.moe/",
                regex:/acg18\.|hxcy\./,
                offset:55,
                run:function(){
                    changeUrl(true,[["a"],[['https?:\\\/\\\/[^\\\.]*(\\\.)?(acg18|hxcy)\\\.[a-z]+\\\/go\\\/\\\?url=','']]]);
                }
            },
            {
                name:"最ACG网",
                url:"http://zuiacg.com/",
                regex:/zuiacg\./,
                hideOd:true,
                offset:75,
                run:function(){
                    let shield=document.querySelector('#shieldclass');
                    if(shield){
                        shield.parentNode.removeChild(shield);
                        let imgs=document.querySelectorAll('p>img');
                        for(let i=0;i<imgs.length;i++){
                            let img=imgs[i];
                            img.onclick=function(){this.className="";};
                        }
                    }
                    var downloadBtn=document.querySelector('a[data-action=download]');
                    if(downloadBtn){
                        if(/\/download\//.test(location.href)){
                            let cd=document.querySelector('div.single-content>p>input');
                            if(cd){
                                downloadBtn.href+="#"+cd.value;
                            }
                        }else{
                            downloadBtn.onclick=function(e){
                                if(e.ctrlKey){
                                    let newWin=window.open('');
                                    GM_xmlhttpRequest({
                                        method: 'GET',
                                        url: downloadBtn.href.replace(/\/news\//,"/download/"),
                                        onload: function(d) {
                                            let html=document.implementation.createHTMLDocument('');
                                            html.documentElement.innerHTML = d.responseText;
                                            let dl=html.querySelector('#adddownload>a');
                                            if(dl){
                                                let url=dl.href;
                                                let cd=html.querySelector('div.single-content>p>input');
                                                if(cd){
                                                    url+="#"+cd.value;
                                                }
                                                newWin.location.href=url;
                                            }else{
                                                newWin.close();
                                            }
                                        },
                                        onerror: function(e) {
                                            newWin.close();
                                        }
                                    });
                                    return false;
                                }
                            };
                        }
                    }
                }
            },
            {
                name:"绅士仓库",
                url:"https://cangku.io/",
                regex:/galacg\.|cangku\./,
                hideOd:true,
                articleSel:".post-card-wrap",
                run:function(){
                    window.setTimeout(function(){
                        process();
                        [].forEach.call(document.querySelectorAll(".r18-mask"),function(item){
                            item.onclick=function(e){
                                e.currentTarget.classList.remove("r18-mask");
                            }
                        });
                    },500);
                }
            },
            {
                name:"萌幻之乡",
                url:"https://hmoe.top/",
                regex:/moe-acg\.|huan\.moe|hmoe\.moe|hmoe\d+\./,
                offset:55,
                hideOd:true,
                downloadUrl:/\/download/,
                articleSel:"section.card,article.is-type-post"
            },
            {
                name:"紳士の庭",
                url:"https://hggard.com/",
                regex:/(gmgard|hggard)\.com/,
                articleSel:"div.post",
                noScale:true,
                run:function(){
                    if(isHttps)addInsertHandler([["img"],[['p(:\\\/\\\/static\.hggard\.com)','ps$1']]]);
                    curSite.preRocket=function(){unsafeWindow.$('#dllist a').mouseenter();};
                }
            },
            {
                name:"MyGalgame - 忧郁的弟弟",
                url:"https://okloli.com/",
                regex:/(mmgal|mygalgame|okloli)\.com/,
                articleSel:".article",
                commArea:'commentlist',
                run:function(){
                    String.prototype.pmatch = function(reg){
                        if(!(reg instanceof RegExp))return 0;
                        if(!reg.global){
                            var a = this.match(reg);
                            return a? [a.slice(1,a.length)] : 0;
                        }
                        a=[];var b;
                        while(b=reg.exec(this)){
                            b.shift();
                            a.push(b);
                        }
                        return a.length>0?a:0;
                    }
                    var downBtn=document.querySelector("a.hint--right");
                    if(downBtn){
                        var innBtn=downBtn.querySelector(".btn-danger");
                        if(innBtn){
                            var onclickStr=innBtn.getAttribute("onclick");
                            if(/\.com\/go\.php\?url\=/.test(onclickStr)){
                                innBtn.setAttribute("onclick", "");
                                var href=onclickStr.replace(/.*\.com\/go\.php\?url\=([^']+)'.*/,"$1");
                                downBtn.setAttribute("href", href);
                                downBtn.setAttribute("target", "_blank")
                            }
                        }
                    }
                    var bgLi=document.createElement("li");
                    bgLi.innerHTML="<a><i class='fa fa-star'></i>\u5f53\u524d\u80cc\u666f\u56fe\u7247</a>";
                    var bgs=document.querySelectorAll(".cb-slideshow>li>span");
                    bgLi.onclick=function(){
                        for(var i=0;i<bgs.length;i++){
                            var bg=bgs[i];
                            if(getComputedStyle(bg).opacity>.5){
                                var url=getComputedStyle(bg).backgroundImage.replace(/url\("?([^"]+)"?\)/,"$1");
                                window.open(url);
                            }
                        }
                    }
                    bgLi.onmouseover=function(){
                        bgLi.classList.add("open");
                    }
                    bgLi.onmouseout=function(){
                        bgLi.classList.remove("open");
                    }
                    var bgUrls,sum=0,maxCss=5;
                    var batchBg=document.createElement("ul");
                    batchBg.classList.add("dropdown-menu");
                    batchBg.innerHTML="<li><a href=\"javascript:void(0)\">复制当组背景图链接</a></li>";
                    batchBg.onclick=function(e){
                        e.stopPropagation();
                        if(bgUrls==undefined){
                            bgUrls="";
                            var style=document.querySelectorAll("style");
                            for(let j=0;j<=style.length;j++){
                                if(style[j].innerHTML.indexOf(".cb-slideshow")!=-1){
                                    style=style[j];
                                    break;
                                }
                            }
                            var curRegs=style.innerHTML.pmatch(/background\-image:\s*url\('?([^\')]+)'?\)/gi);
                            bgUrls=curRegs.join("\n\r")+"\n\r";
                            var rmBg=document.querySelector("div.large");
                            if(rmBg)bgUrls+=getComputedStyle(rmBg).backgroundImage.replace(/url\("?([^"]+)"?\)/,"$1");
                            GM_setClipboard(bgUrls);
                            console.info(bgUrls);
                            alert("背景图片链接复制完毕");
                        }else{
                            if(bgUrls!=""){
                                GM_setClipboard(bgUrls);
                                alert("背景图片链接复制完毕");
                            }
                        }
                    }
                    bgLi.appendChild(batchBg);
                    document.querySelector("ul.navbar-nav").appendChild(bgLi);
                    var comments=document.querySelector("#comments"),processing=false;
                    if(comments)comments.addEventListener('DOMNodeInserted', function(e) {
                        if(processing)return;
                        processing=true;
                        setTimeout(function(){
                            seriousReplace(commArea);
                            processing=false;
                        },500);
                    });
                    var picTitle=document.querySelector("h1>a[href='"+location.origin+"/gengxinrizhi.html']");
                    if(picTitle){
                        var imgUrl=picTitle.parentNode.parentNode.parentNode.querySelector("div.img>img").src;
                        var picBtn=document.createElement("a");
                        picBtn.href=imgUrl;
                        picBtn.target="_blank";
                        picBtn.innerHTML="<span class='animated_h1'>封面图</span>";
                        picTitle.parentNode.appendChild(picBtn);
                    }
                }
            },
            {
                name:"萌口组",
                url:"http://www.kou.moe/",
                regex:/kou\.moe/,
                offset:35,
                articleSel:"article",
                contentArea:'.entry-content'
            },
            {
                name:"CE家族社",
                url:"https://cefamilie.com/",
                regex:/cefamilie\.com/,
                articleSel:"li.post>div.thumbnail",
                contentArea:'#post_content',
                commArea:"commentlist"
            },
            {
                name:"绅士会所",
                url:"https://www.hentaiclub.net/",
                regex:/hentaiclub\.net/,
                articleSel:"article",
                offset:20,
                run:function(){
                    var dlBox=document.querySelector("#dl-box");
                    if(dlBox)document.querySelector("#dl-box").style.display="block";
                }
            },
            {
                name:"爱恋动漫",
                url:"http://kisssub.org/",
                regex:/kisssub\./,
                run:function(){
                    var acgscript_config = { "miobt": { "4": { "api_url": "http://v2.uploadbt.com" } } };
                    (function($) {
                        if (acgscript_config['miobt']['4']['loaded']) { return false; }
                        acgscript_config['miobt']['4']['loaded'] = true;
                        var log_name = 'bt_download';
                        console.log([log_name, { 'loaded': acgscript_config['miobt']['4']['loaded'], 'api_url': acgscript_config['miobt']['4']['api_url'], 'mika_mode': Config['mika_mode']['enabled'], 'in_script': Config['in_script'], 'platform': Config['user_script']['platform'] }]);
                        if (!Config['mika_mode']['enabled']) { return false; }
                        if (Config['in_script'] !== 'show') { return false; }
                        if (!$('#box_download')) { return false; }
                        var api_url = acgscript_config['miobt']['4']['api_url'];
                        var torrent_url = { "lite": api_url + '/?r=down&hash=' + Config['hash_id'], 'full': api_url + '/?r=down&hash=' + Config['hash_id'] + '&name=' + Config['down_torrent_format'].replace('%s', Config['bt_data_title']) };
                        var magnet_url = { 'lite': 'magnet:?xt=urn:btih:' + Config['hash_id'], 'full': 'magnet:?xt=urn:btih:' + Config['hash_id'] + '&tr=' + Config['announce'] };
                        if (Config['user_script']['platform'] == 'desktop') { $('#box_download h2.title').text('下载地址');
                            $('#magnet').attr('href', magnet_url.full).text('磁链下载');
                            $('#download').attr('href', torrent_url.full).text('种子下载');
                            $('#qrcode_magnet').removeAttr('href').text('磁链扫码');
                            $('#qrcode_download').removeAttr('href').text('种子扫码');
                            $('#qrcode_magnet_enlarged').attr('qr_content', magnet_url.full);
                            $('#qrcode_download_enlarged').attr('qr_content', torrent_url.lite); var register_qrcode_event = function(sel, sel_enlarged) { $(sel).click(function() { $('.qrcode_enlarged').html('').hide();
                                    $(sel_enlarged).qrcode({ render: "canvas", size: 256, fill: '#0480BE', background: '#FFF', quiet: 1, mode: 2, minVersion: 10, label: $(sel_enlarged).attr('qr_label'), fontname: '"Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif', fontcolor: 'darkorange', text: $(sel_enlarged).attr('qr_content') });
                                    $(sel_enlarged).fadeIn(200); });
                                $(sel_enlarged).click(function() { $(this).hide(); }); };
                            $(document).ready(function() { register_qrcode_event('#qrcode_magnet', '#qrcode_magnet_enlarged');
                                register_qrcode_event('#qrcode_download', '#qrcode_download_enlarged'); }); } else if (Config['user_script']['platform'] == 'mobile') { $('#torrent_url').attr('href', torrent_url.full).text('种子下载').click(function() { return (prompt('确认下载该种子', torrent_url.full) ? true : false); });
                            $('#magnet_url').attr('href', magnet_url.full).text('磁力下载').click(function() { return (prompt('确认下载磁链', magnet_url.full) ? true : false); }); } else { return false; }
                    })(unsafeWindow.jQuery);
                }
            },
            {
                name:"MioBT",
                url:"http://miobt.com/",
                regex:/miobt\./,
                run:function(){
                    var acgscript_config = { "miobt": { "4": { "api_url": "http://v2.uploadbt.com" } } };
                    (function($) {
                        if (acgscript_config['miobt']['4']['loaded']) { return false; }
                        acgscript_config['miobt']['4']['loaded'] = true;
                        var log_name = 'bt_download';
                        console.log([log_name, { 'loaded': acgscript_config['miobt']['4']['loaded'], 'api_url': acgscript_config['miobt']['4']['api_url'], 'mika_mode': Config['mika_mode']['enabled'], 'in_script': Config['in_script'], 'platform': Config['user_script']['platform'] }]);
                        if (!Config['mika_mode']['enabled']) { return false; }
                        if (Config['in_script'] !== 'show') { return false; }
                        if (!$('#box_download')) { return false; }
                        var api_url = acgscript_config['miobt']['4']['api_url'];
                        var torrent_url = { "lite": api_url + '/?r=down&hash=' + Config['hash_id'], 'full': api_url + '/?r=down&hash=' + Config['hash_id'] + '&name=' + Config['down_torrent_format'].replace('%s', Config['bt_data_title']) };
                        var magnet_url = { 'lite': 'magnet:?xt=urn:btih:' + Config['hash_id'], 'full': 'magnet:?xt=urn:btih:' + Config['hash_id'] + '&tr=' + Config['announce'] };
                        if (Config['user_script']['platform'] == 'desktop') { $('#box_download h2.title').text('下载地址');
                            $('#magnet').attr('href', magnet_url.full).text('磁链下载');
                            $('#download').attr('href', torrent_url.full).text('种子下载');
                            $('#qrcode_magnet').removeAttr('href').text('磁链扫码');
                            $('#qrcode_download').removeAttr('href').text('种子扫码');
                            $('#qrcode_magnet_enlarged').attr('qr_content', magnet_url.full);
                            $('#qrcode_download_enlarged').attr('qr_content', torrent_url.lite); var register_qrcode_event = function(sel, sel_enlarged) { $(sel).click(function() { $('.qrcode_enlarged').html('').hide();
                                    $(sel_enlarged).qrcode({ render: "canvas", size: 256, fill: '#0480BE', background: '#FFF', quiet: 1, mode: 2, minVersion: 10, label: $(sel_enlarged).attr('qr_label'), fontname: '"Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif', fontcolor: 'darkorange', text: $(sel_enlarged).attr('qr_content') });
                                    $(sel_enlarged).fadeIn(200); });
                                $(sel_enlarged).click(function() { $(this).hide(); }); };
                            $(document).ready(function() { register_qrcode_event('#qrcode_magnet', '#qrcode_magnet_enlarged');
                                register_qrcode_event('#qrcode_download', '#qrcode_download_enlarged'); }); } else if (Config['user_script']['platform'] == 'mobile') { $('#torrent_url').attr('href', torrent_url.full).text('种子下载').click(function() { return (prompt('确认下载该种子', torrent_url.full) ? true : false); });
                            $('#magnet_url').attr('href', magnet_url.full).text('磁力下载').click(function() { return (prompt('确认下载磁链', magnet_url.full) ? true : false); }); } else { return false; }
                    })(unsafeWindow.jQuery);
                }
            },
            {
                name:"漫猫",
                url:"http://comicat.org/",
                regex:/comicat\./,
                run:function(){
                    (function($) {
                        var acgscript_config = {
                            "miobt": {
                                "4": {
                                    "api_url": "http://v2.uploadbt.com",
                                    "source": "cdn.acgscript.com"
                                }
                            }
                        };
                        if (acgscript_config['miobt']['4']['loaded']) {
                            return false;
                        }
                        acgscript_config['miobt']['4']['loaded'] = true;
                        var log_name = 'acgscript/miobt/bt_download';
                        console.log([log_name, {
                            'source': acgscript_config['miobt']['4']['source'],
                            'loaded': acgscript_config['miobt']['4']['loaded'],
                            'api_url': acgscript_config['miobt']['4']['api_url'],
                            'mika_mode': Config['mika_mode']['enabled'],
                            'in_script': Config['in_script'],
                            'platform': Config['user_script']['platform']
                        }]);
                        if (!Config['mika_mode']['enabled']) {
                            return false;
                        }
                        if (Config['in_script'] !== 'show') {
                            return false;
                        }
                        if (!$('#box_download')) {
                            return false;
                        }
                        var api_url = acgscript_config['miobt']['4']['api_url'];
                        var torrent_url = {
                            "lite": api_url + '/?r=down&hash=' + Config['hash_id'],
                            'full': api_url + '/?r=down&hash=' + Config['hash_id'] + '&name=' + Config['down_torrent_format'].replace('%s', Config['bt_data_title'])
                        };
                        var magnet_url = {
                            'lite': 'magnet:?xt=urn:btih:' + Config['hash_id'],
                            'full': 'magnet:?xt=urn:btih:' + Config['hash_id'] + '&tr=' + Config['announce']
                        };
                        if (Config['user_script']['platform'] == 'desktop') {
                            $('#box_download h2.title').text('下载地址');
                            $('#magnet').attr('href', magnet_url.full).text('磁链下载');
                            $('#download').attr('href', torrent_url.full).text('种子下载');
                            $('#qrcode_magnet').removeAttr('href').text('磁链扫码');
                            $('#qrcode_download').removeAttr('href').text('种子扫码');
                            $('#qrcode_magnet_enlarged').attr('qr_content', magnet_url.full);
                            $('#qrcode_download_enlarged').attr('qr_content', torrent_url.lite);
                            var register_qrcode_event = function(sel, sel_enlarged) {
                                $(sel).click(function() {
                                    $('.qrcode_enlarged').html('').hide();
                                    $(sel_enlarged).qrcode({
                                        render: "canvas",
                                        size: 256,
                                        fill: '#0480BE',
                                        background: '#FFF',
                                        quiet: 1,
                                        mode: 2,
                                        minVersion: 10,
                                        label: $(sel_enlarged).attr('qr_label'),
                                        fontname: '"Helvetica Neue", Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Heiti SC", "Microsoft YaHei", "WenQuanYi Micro Hei", sans-serif',
                                        fontcolor: 'darkorange',
                                        text: $(sel_enlarged).attr('qr_content')
                                    });
                                    $(sel_enlarged).fadeIn(200);
                                });
                                $(sel_enlarged).click(function() {
                                    $(this).hide();
                                });
                            };
                            $(document).ready(function() {
                                register_qrcode_event('#qrcode_magnet', '#qrcode_magnet_enlarged');
                                register_qrcode_event('#qrcode_download', '#qrcode_download_enlarged');
                            });
                        } else if (Config['user_script']['platform'] == 'mobile') {
                            $('#torrent_url').attr('href', torrent_url.full).text('种子下载').click(function() {
                                return (prompt('确认下载该种子', torrent_url.full) ? true : false);
                            });
                            $('#magnet_url').attr('href', magnet_url.full).text('磁力下载').click(function() {
                                return (prompt('确认下载磁链', magnet_url.full) ? true : false);
                            });
                        } else {
                            return false;
                        }
                    })(unsafeWindow.jQuery);
                }
            }
        ],
        rocketReg:/magnet:\?xt|pan\.baidu\.com\/s|yunpan\.cn|howfile\.com\/file|mega\.|ed2k:\/\/\|file|bt\.cosxcos\.com\/view|du\.acgget\.com\/go\/|\.mediafire\.com\/download\/|\.torrent$/,
        disableSites:/hacg.*about\.html/,
        imgRegs:[[/^(?:https:)?(\/\/img\.2dfan|www\.moxtu\.cc|(?:pic|tc)\.(?:ffsky|rpgsky)|\/\/i\.tianshi\.info)/,'http:$1'],[/http(:\/\/(?:[^\.]*\.)?loli\.io)/,'https$1'],[/^https:\/\/galacg.me/,'https://www.galacg.me/'],[/^http:\/\/www\.moepicx\.cc/,'https://www.moepicx.cc']]
    };
    /*if (!Array.prototype.findSite) {
        Array.prototype.findSite = function (siteName) {
            var arr = this;
            for (var i = 0, length = arr.length; i < length; i++) {
                if (arr[i].name == siteName) {
                    return arr[i];
                }
            }
        };
    }*/

    var t, curSite, curArticle, siteListHtml;
    var originTitile = document.title;
    var isHttps=location.protocol=="https:";
    var head=document.getElementsByTagName("head")[0];
    if(isHttps){
        /*var refMeta = document.createElement('meta');
        refMeta.name = 'referrer';
        refMeta.content = 'always';
        head.appendChild(refMeta);*/
    }else{
        if(document.title=="Service Unavailable - Connection Error"){
            location.href=location.href.replace(/^http:/,"https:");
        }
    }
    for(var site of config.sites){
        if(site.regex.test(location.hostname)){
            curSite=site;
            break;
        }
    }
    var contentArea=curSite&&curSite.contentArea?curSite.contentArea:'.entry-content',commArea=curSite&&curSite.commArea?curSite.commArea:"comment-content",articleSel=curSite&&curSite.articleSel?curSite.articleSel:"article";

    if(/(sleaz|greas)yfork\.org/.test(location.hostname)){
        if(/scripts\/23316/.test(location.href)){
            let pos=elementPosition(document.querySelector("#additional-info>div.script-author-description>h2")).y;
            scrollTo(0,pos);
        }else if(/discussion/.test(location.href)){
            var goodBtn=document.querySelector("#Form_Rating3");
            var okBtn=document.querySelector("#Form_Rating2");
            var badBtn=document.querySelector("#Form_Rating1");
            if(goodBtn){
                var scriptID=document.querySelector("input[name=ScriptID]");
                var about=document.querySelector("#Content>div.MessageList.Discussion>span>a");
                if((scriptID && scriptID.value=="23316") || (about && about.getAttribute("href")=="/scripts/23316")){
                    var actionBtn=document.querySelector("input.Primary")||document.querySelector("#Form_Save");
                    actionBtn.onclick=function(){
                        var discussTitle=document.querySelector("#Form_Name");
                        var discussBody=document.querySelector("#Form_Body");
                        if(goodBtn.checked==false && ((discussTitle && /声音|语音/.test(discussTitle.value)) || (discussBody && /声音|语音/.test(discussBody.value)))){
                            if(window.confirm("\u8f93\u5165\u0068\u0061\u007a\u0075\u006b\u0061\u0073\u0068\u0069\u0069\u5c31\u80fd\u5207\u6362\u8bed\u97f3\uff0c\u8be6\u89c1\u8bf4\u660e\u9875\uff0c\u662f\u5426\u7ed9\u4e2a\u597d\u8bc4\uff1f")){
                                goodBtn.checked=true;
                            }
                        }
                    };
                }
            }
        }else{
            if(document.body.innerHTML.indexOf("\u7409\u7483\u795e\u793e")!=-1){
                var installLink=document.querySelector("a.install-link");
                if(installLink){
                    installLink.onclick=function(){
                        if(window.confirm('\u8be5\u811a\u672c\u53ef\u80fd\u4e0e\u0020\u2605\u7409\u795e\u8f6c\u2605\u0020\u4e0d\u517c\u5bb9\u54e6\uff0c\u662f\u5426\u53d6\u6d88\u5b89\u88c5\uff1f')){
                            return false;
                        }else{
                            return true;
                        }
                    };
                }
            }
        }
        return;
    }else if(location.hostname=="pan.baidu.com"){
        var submitBtn=document.querySelector('.g-button,#submitBtn');
        if(location.hash.slice(1) && submitBtn){
            document.querySelector(".pickpw input,#accessCode").value=decodeURI(location.hash.slice(1).split("?")[0]);
            submitBtn.click();
        }
        return;
    }else if(config.disableSites.test(location.href)){
        return;
    }else if(curSite){
        if(curSite.run)curSite.run();
    }

    if(curSite && curSite.downloadUrl && curSite.downloadUrl.test(location.href)){
        if(!curSite.getDownPass){
            curSite.getDownPass=function(target){
                var pass=target.parentNode.parentNode.parentNode.querySelector('input.form-control');
                if(pass)target.href=target.href.split("#")[0]+'#'+pass.value;
            };
        }
        t=window.setInterval(function(){
            if(document.querySelector('.btn-success')){
                clearInterval(t);
                process();
            }
        },1000);
    }else{
        process();
    }

    var hideNode=document.createElement("style");
    hideNode.id="hideNode";
    hideNode.innerHTML="img{display:none!important}";
    if(GM_getValue("hacgGodeTurnHideImg")){
        head.appendChild(hideNode);
    }
    document.addEventListener("keydown", function(e) {
        if(curArticle && e.code !== 'ControlLeft' && e.code !== 'ControlRight') curArticle.classList.remove("oD_sel");
        if(e.code === 'F8') {
            if(e.altKey){
                rocketContent.style.display="block";
                var rocketLinks=document.querySelector("div#rocketLinks");
                if(!siteListHtml){
                    siteListHtml="";
                    for(var i=0;i<config.sites.length;i++){
                        var site=config.sites[i];
                        siteListHtml+="<span style='font-weight:bold;color:red;'>"+(i+1)+":\t</span>"+"<a href="+site.url+">"+site.name+"</a><br/>";
                    }
                }
                rocketLinks.innerHTML=siteListHtml;
            }else if(e.ctrlKey){
                launchRocket();
            }else{
                var i=0;
                if(curSite)i=config.sites.indexOf(curSite);
                if(e.shiftKey) i=i===0?(config.sites.length-1):(i-1);
                else i=i==(config.sites.length-1)?0:(i+1);
                location.href = config.sites[i].url;
            }
            return false;
        }else{
            if((e.code === 'ArrowUp' || e.code === 'ArrowDown' || e.code === 'ArrowLeft' || e.code === 'ArrowRight') && !e.shiftKey && !e.altKey){
                if(/INPUT|TEXTAREA/.test(document.activeElement.tagName))return;
                var article, isFind, index, articles=document.querySelectorAll(articleSel);
                var scrollTop = window.scrollY || document.documentElement.scrollTop  || document.body.scrollTop  || 0;
                if(e.code === 'ArrowRight'){
                    if(e.ctrlKey){
                        var next=getPage().next;
                        if(next)next.click();
                    }else{
                        isFind = false;
                        if(curArticle){
                            index=Array.prototype.indexOf.call(articles, curArticle)+1;
                            if(index<articles.length){
                                scrollArticle(articles[index]);
                                isFind = true;
                            }
                        }else{
                            for(let i=0,j=articles.length;i<j;i++){
                                article=articles[i];
                                if(elementPosition(article).y>scrollTop+50){
                                    scrollArticle(article);
                                    isFind = true;
                                    break;
                                }
                            }
                        }
                        if(!isFind){
                            curArticle=null;
                            scrollTo(0,document.body.scrollHeight);
                        }
                    }
                }else if(e.code === 'ArrowLeft'){
                    if(e.ctrlKey){
                        var pre=getPage().pre;
                        if(pre)pre.click();
                    }else{
                        isFind = false;
                        if(curArticle){
                            index=Array.prototype.indexOf.call(articles, curArticle)-1;
                            if(index>=0){
                                scrollArticle(articles[index]);
                                isFind = true;
                            }
                        }else{
                            for(let i=0,j=articles.length;i<j;i++){
                                article=articles[j-i-1];
                                if(elementPosition(article).y<scrollTop-50){
                                    scrollArticle(article);
                                    isFind = true;
                                    break;
                                }
                            }
                        }
                        if(!isFind){
                            curArticle=null;
                            scrollTo(0,0);
                        }
                    }
                }else if(e.ctrlKey && e.code === 'ArrowUp'){
                    history.go(-1);
                    return false;
                }else if(e.ctrlKey && e.code === 'ArrowDown'){
                    if(curArticle){
                        let aLink=curArticle.querySelector("a:not(.label)");
                        if(aLink){
                            aLink.click();
                            return false;
                        }else if(curArticle.parentNode && curArticle.parentNode.tagName=="A"){
                            curArticle.parentNode.click();
                            return false;
                        }
                    }else{
                        let dis;
                        for(let i=0,j=articles.length;i<j;i++){
                            article=articles[i];
                            dis=elementPosition(article).y - scrollTop;
                            if(dis > -50 && dis < 50){
                                let aLink=article.querySelector("a:not(.label)");
                                if(aLink){
                                    aLink.click();
                                    return false;
                                }else if(article.parentNode && article.parentNode.tagName=="A"){
                                    article.parentNode.click();
                                    return false;
                                }
                                break;
                            }
                        }
                    }
                }
            }else if(e.code !== 'ControlLeft' && e.code !== 'ControlRight'){
                if(e.ctrlKey && e.code === 'KeyZ'){
                    if(hideNode.parentNode){
                        head.removeChild(hideNode);
                        GM_setValue("hacgGodeTurnHideImg",false);
                    }else{
                        head.appendChild(hideNode);
                        GM_setValue("hacgGodeTurnHideImg",true);
                    }
                }
                curArticle=null;
            }
        }
    });
    var mousewheelEvent=navigator.userAgent.toLowerCase().indexOf('firefox')==-1?"mousewheel":"DOMMouseScroll";
    document.addEventListener(mousewheelEvent,function(e){
        if(curArticle)curArticle.classList.remove("oD_sel");
    });
    document.addEventListener("copy", function(e) {
        var copyData=document.getSelection().toString();
        if(copyData && oD_text){
            oD_text.value=copyData;
        }
    });

    head.appendChild(nod);
    var rocketContent=document.createElement("div");
    document.body.appendChild(rocketContent);
    rocketContent.outerHTML=rocketStr;
    rocketContent=document.querySelector("#rocketContent");
    document.querySelector("#rocketQuit").onclick=function (){
        rocketContent.style.display="none";
    };
    document.querySelector("#rocketContent>div").onclick=function (){
        rocketContent.style.display="none";
    };
    document.addEventListener("keydown", function(e) {
        if(e.code === 'Escape') {
            rocketContent.style.display="none";
        }
    });
    setTimeout(function(){
        if(document.querySelectorAll("#oD_box").length > 1){
            alert("\u68c0\u6d4b\u5230\u0049\u0044\u51b2\u7a81\uff0c\u7409\u795e\u8f6c\u811a\u672c\u5c06\u65e0\u6cd5\u6b63\u5e38\u5de5\u4f5c\uff01\u8bf7\u68c0\u67e5\u662f\u5426\u5b58\u5728\u91cd\u590d\u6216\u540c\u7c7b\u811a\u672c");
        }
    },500);
    var oD_box,oD_text,oD_button;
    if((!curSite || !curSite.hideOd) && !frameElement){
        oD_box=document.createElement("div");
        oD_box.id="oD_box";
        oD_box.className = "oD_box";
        oD_box.onmouseover = function(e) {
            oD_link.style.visibility = "visible";
            oD_link2.style.visibility = "visible";
            rocketBtn.style.visibility = "visible";
        };
        oD_box.onmouseout = function(e) {
            oD_link.style.visibility = "hidden";
            oD_link2.style.visibility = "hidden";
            rocketBtn.style.visibility = "hidden";
        };
        oD_text=document.createElement("input");
        oD_text.type="text";
        oD_text.style.cssText="width:248px;height:33px;position:relative;margin-top:0px;padding:0px;box-sizing:border-box;z-index:0";
        oD_text.placeholder="输入hash值、网盘地址或Base64密文";
        oD_text.title='将自动添加"magnet:?xt=urn:btih:"并去除非法字符';
        oD_button=document.createElement("button");
        oD_button.type="button";
        oD_button.textContent="开车";
        oD_button.style.cssText="padding:4px 0;position: absolute;top:-1px;right:0px;width:40px;height:35px";
        oD_button.onclick=function (){
            oD_link.textContent=oD_link2.textContent=oD_link3.textContent="";
            var oD_hash=oD_text.value,url;
            if(oD_hash===""){
                alert("请输入hash值、网盘或Base64密文");
            }else if(/\b1[0-9a-z]{6,7}(\b|$)/i.test(oD_hash)){
                var panMatch=oD_hash.match(/\b1[0-9a-z]{6,7}/i);
                var ecode=oD_hash.trim();
                url="https://pan.baidu.com/s/"+panMatch;
                var shortMatch=/\b1[0-9a-z]{6,7}\s*([0-9a-z!]{4}|[^\s,,::]{2,4})(\b|$)/i.exec(ecode);
                if(shortMatch){
                    url+="#"+shortMatch[1];
                }else{
                    ecode=simpleRule.test(ecode)?ecode.match(simpleRule)[1]:codeRule.test(ecode)?ecode.match(codeRule)[1]:"";
                    if(ecode)url+="#"+ecode;
                }
                window.open(url);
            }else if(/^\s*(https|ftp)?:\/\//.test(oD_hash)){
                url=oD_hash.replace(/[^a-z0-9:\/%\?&\._\-\+\*]/gi,"");
                window.open(url);
            }else if(/^\d{8}$/.test(oD_hash)){
                url="https://www.pixiv.net/member_illust.php?mode=medium&illust_id="+oD_hash;
                window.open(url);
            }else{
                oD_hash=oD_hash.replace(/(\[.*\])|[\W_]/g,"");
                if(!regObj.btih.test(oD_hash)){
                    if(/^[\da-z\/\+\=]+$/i.test(oD_hash)){
                        try{
                            GM_setClipboard(CryptoJS.enc.Base64.parse(oD_hash).toString(CryptoJS.enc.Utf8));
                            alert("Base64解密结果已复制");
                        }catch(e){
                            alert(e+" 格式错误");
                        }
                    }else
                        alert("hash值格式错误");
                }else{
                    oD_link.href="magnet:?xt=urn:btih:"+oD_hash;
                    oD_link.textContent="磁链";
                    oD_link2.href="https://itorrents.org/torrent/"+oD_hash+".torrent";
                    oD_link2.textContent="种子";
                    oD_link2.style.cssText="margin-left:20px";
                    oD_link3.href="https://btsow.motorcycles/magnet/detail/hash/"+oD_hash;
                    oD_link3.textContent="详情";
                    oD_link3.style.cssText="margin-left:20px";
                }
            }
        };
        var oD_link=document.createElement("a");
        var oD_link2=document.createElement("a");
        var oD_link3=document.createElement("a");
        oD_link2.target=oD_link3.target="_blank";
        oD_box.appendChild(oD_text);
        oD_box.appendChild(oD_button);
        oD_box.appendChild(document.createElement('br'));
        oD_box.appendChild(oD_link);
        oD_box.appendChild(oD_link2);
        oD_box.appendChild(oD_link3);
        var rocketBtn=document.createElement("button");
        rocketBtn.id="rocketBtn";
        rocketBtn.type="button";
        rocketBtn.textContent="\u706b\u7bad";
        rocketBtn.style.cssText="padding:4px 0;position:absolute;top:-36px;right:0px;width:40px;height:35px;visibility:hidden";
        var preImgData="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAMAAAAMCGV4AAAAgVBMVEUAAADDKkPPN1HLM02+Iz3PPFbUQFrDK0XcR2LTOlXUO1bJL0rGLkjHN1DXSmPRRl/DLUfHM0zOOVPaSGPCK0TIMUrdRmHIMEm/JT/DK0bHLki7ITvdRWHHLUe+IzzYPVm+JD7OR17KQVnRTGTJO1TXVGvRSmLKPlfFNE3LP1fHNk/FsIf5AAAAIXRSTlMAdQwGysW4l35hRDss/vj45uXe2MCzoZ6TjIBLSkQxKxaE9dxlAAAAZ0lEQVQI152LVw6AIBAFAXvvvSPY7n9AcTUGf52PncxLFv2k/RTJTTmHhMtt+ZzrNnnK1pZZsAS6pYh04ulFuwaS7ZTSla3iFvCBPcYMt6sjdrgwOOGGhRRjqxAwphhcquihvwUt0Zy1HgdDH4CNEQAAAABJRU5ErkJggg==";
        rocketBtn.onclick=function (){
            launchRocket();
        };
        oD_box.appendChild(rocketBtn);
        document.body.appendChild(oD_box);
    }

    function launchRocket(){
        if(!rocketBtn)return;
        if(curSite.preRocket){
            curSite.preRocket();
        }
        rocketContent.style.display="block";
        var links=document.querySelectorAll("a");
        var rocketLinks=document.querySelector("div#rocketLinks");
        rocketLinks.innerHTML="";
        var i=0;
        for(let j=0;j<links.length;j++){
            let link=links[j];
            if(config.rocketReg.test(link.href)&&link.className.indexOf("whx-a")==-1){
                if(rocketLinks.innerHTML.indexOf(link.outerHTML)!=-1 || window.getComputedStyle(link).display=="none" || (link.firstElementChild&&window.getComputedStyle(link.firstElementChild).display=="none"))continue;
                rocketLinks.innerHTML+="<a id='rocketBack' style='font-weight:bold;color:red;' href='javascript:void(0)'>"+(++i)+"<img src='"+preImgData+"'></a>: ";
                rocketLinks.appendChild(link.cloneNode(true));
                rocketLinks.innerHTML+="<br/>";
            }
        }
        var backs=document.querySelectorAll("div#rocketLinks>#rocketBack");
        for(i=0;i<backs.length;i++){
            let back=backs[i];
            back.onclick=function(){
                let target=document.querySelector("[href='"+back.nextSibling.nextSibling.getAttribute("href")+"']");
                let pos=elementPosition(target).y;
                if(curSite && curSite.offset)pos-=curSite.offset;
                scrollToControl(pos);
                rocketContent.style.display="none";
            };
        }
        if(rocketLinks.innerHTML===""){
            rocketLinks.innerHTML="No links found!";
        }
    }

    function process(){
        var downloadBtn;
        if(isHttps && (downloadBtn=document.querySelector("div#post-toolbar-download-count-container"))){
            var t=function(){
                if(downloadBtn.innerHTML=="<!-- react-empty: 1 -->"){
                    var downloadContent=document.createElement("a");
                    downloadContent.href=window.location.protocol+"//"+window.location.host+"/download?id="+window.location.pathname.split("/").pop();
                    downloadContent.innerHTML+='<div class="tx"><span><i class="fa fa-cloud-download"></i></span>\u4e0b\u8f7d</div>';
                    downloadBtn.appendChild(downloadContent);
                }else if(downloadBtn.innerHTML===""){
                    setTimeout(t,100);
                }
            };
            setTimeout(t,100);
        }
        var content=document.querySelector(contentArea);
        if(content){
            processObj(content);
        }
        var link, imgs, i, k;
        setTimeout(function(){
            if (document.querySelectorAll) {
                link = document.querySelectorAll('a');
                imgs = document.querySelectorAll('img');
            } else {
                link = document.getElementsByTagName('a');
                imgs = document.getElementsByTagName('img');
            }
            for (i = 0, k = link.length; i < k; i++) {
                let target=link[i];
                target.addEventListener("mousedown", function(){
                    if(/baidu.com/i.test(target.href)&&!/(?:eyun|tieba)\.baidu\.com/i.test(target.href)&&!/#/i.test(target.href)){
                        if(/\/storage-download/.test(location.href)){
                            var pass=target.parentNode.parentNode.querySelector('input.pwd');
                            if(pass&&pass.id.indexOf("download-pwd")!=-1)target.href=target.href.split("#")[0]+'#'+pass.value;
                        } else if(curSite.downloadUrl && curSite.downloadUrl.test(location.href) && curSite.getDownPass){
                            curSite.getDownPass(target);
                        } else if(codeRule.test(target.textContent)){
                            target.href+='#'+extCode(target);
                        } else if(/^\s*[a-z\d]{4}\s*$/i.test(target.textContent)){
                            target.href+='#'+target.textContent.trim();
                        } else if(target.nextSibling&&codeRule.test(target.nextSibling.textContent)){
                            target.href+=/#/i.test(target.href)?extCode(target.nextSibling):('#'+extCode(target.nextSibling));
                        } else if(target.nextSibling&&/^\s*[a-z\d]{4}\s*$/.test(target.nextSibling.textContent)){
                            target.href+='#'+target.nextSibling.textContent.trim();
                        } else if(codeRule.test(target.parentNode.textContent)){
                            if(!/#\S+/i.test(target.href)) target.href+=/#/i.test(target.href)?extCode(target.parentNode):('#'+extCode(target.parentNode));
                        } else {
                            var j = 0,
                                maxParent = 5,
                                parent = target;
                            while(j<maxParent) {
                                j++;
                                parent = parent.parentNode;
                                if(parent.tagName=="TR") {
                                    if(codeRule.test(parent.nextElementSibling.textContent)) {
                                        parent=parent.nextElementSibling;
                                        target.href+='#'+extCode(parent);
                                        break;
                                    }
                                } else if(codeRule.test(parent.textContent)) {
                                    target.href+='#'+extCode(parent);
                                    break;
                                }
                                if(parent==document.body) break;
                            }
                        }
                    }
                });
            }
            for (i = 0, k = imgs.length; i < k; i++) {
                let src;
                for(let imgReg of config.imgRegs){
                    src = imgs[i].src.replace(imgReg[0], imgReg[1]);
                    if(src != imgs[i].src)imgs[i].src = src;
                    if(imgs[i].dataset.src){
                        src=imgs[i].dataset.src.replace(imgReg[0], imgReg[1]);
                        if(src != imgs[i].dataset.src)imgs[i].dataset.src = src;
                    }
                }
            }
            seriousReplace(commArea);
        },2);
    }

    function processObj(obj){
        if(obj){
            if(obj.nodeType==1 && obj.tagName != "A"){
                for(var i=0;i<obj.childNodes.length;i++){
                    processObj(obj.childNodes[i]);
                }
            }else if(obj.nodeType==3){
                var curData=obj.data;
                if(obj.nextSibling && obj.nextSibling.outerHTML=="<b>hacg</b>"){
                    curData+="hacg";
                    if(obj.nextSibling.nextSibling && obj.nextSibling.nextSibling.nodeType==3){
                        curData+=obj.nextSibling.nextSibling.data;
                        obj.nextSibling.nextSibling.data="";
                    }
                    obj.parentNode.removeChild(obj.nextSibling);
                }
                let data=processTxt(curData);
                if(curData != data){
                    let curObj=obj;
                    setTimeout(function(){
                        var newData = document.createElement("p");
                        curObj.parentNode.replaceChild(newData, curObj);
                        newData.outerHTML=data;
                    },1);
                }else if(/B|STRONG/.test(obj.parentNode.tagName)){
                    let allStrongs=[];
                    var next=obj.parentNode.nextSibling;
                    while(next){
                        if(/B|STRONG/.test(next.tagName)){
                            allStrongs.push(next);
                            curData+=next.innerHTML;
                            next=next.nextSibling;
                        }else{
                            break;
                        }
                    }
                    data=processTxt(curData);
                    if(curData != data){
                        let curObj=obj;
                        setTimeout(function(){
                            allStrongs.forEach(function(item){
                                item.style.display="none";
                            });
                            var newData = document.createElement("p");
                            curObj.parentNode.replaceChild(newData, curObj);
                            newData.outerHTML=data;
                        },1);
                    }
                }
            }
        }
    }

    function getPage(){
        let pre=document.querySelector("a.prev");
        let next=document.querySelector("a.next");
        if(!pre)pre=document.querySelector(".prev>a");
        if(!next)next=document.querySelector(".next>a");
        if(!pre && !next){
            let aTags=document.querySelectorAll("a,button>span");
            if(!pre){
                let pref,pres,pret;
                for(var i=0;i<aTags.length;i++){
                    let aTag=aTags[i];
                    if(pref && pres && pret)break;
                    if(!pref){
                        if(/上一页/.test(aTag.innerHTML)){
                            pref=aTag;
                        }
                    }
                    if(!pres){
                        if(aTag.innerHTML=="&lt;"){
                            pres=aTag;
                        }
                    }
                    if(!pret){
                        if(aTag.innerHTML=="«"){
                            pret=aTag;
                        }
                    }
                }
                pre=pref||pres||pret;
            }
            if(!next){
                let nextf,nexts,nextt;
                for(i=0;i<aTags.length;i++){
                    let aTag=aTags[i];
                    if(nextf && nexts && nextt)break;
                    if(!nextf){
                        if(/下一页/.test(aTag.innerHTML)){
                            nextf=aTag;
                        }
                    }
                    if(!nexts){
                        if(aTag.innerHTML=="&gt;"){
                            nexts=aTag;
                        }
                    }
                    if(!nextt){
                        if(aTag.innerHTML=="»"){
                            nextt=aTag;
                        }
                    }
                }
                next=nextf||nexts||nextt;
            }
        }
        if(!pre && !next){
            let pageDiv=document.querySelector("div.wp-pagenavi");
            if(pageDiv){
                var cur=pageDiv.querySelector("span.current");
                pre=cur.previousSibling;
                next=cur.nextSibling;
            }
        }
        return {pre:pre,next:next};
    }

    function scrollArticle(a){
        curArticle=a;
        if(!curSite.noScale)curArticle.classList.add("oD_sel");
        let pos=elementPosition(curArticle).y;
        if(curSite && curSite.offset)pos-=curSite.offset;
        scrollToControl(pos);
    }

    var hasViewed=false;
    if(document.referrer){
        for(site of config.sites){
            if(site.regex.test(document.referrer)){
                hasViewed=true;
                break;
            }
        }
    }
    if(!hasViewed){
        var audioContext = new AudioContext();
        function playSound(buffer) {
            var source = audioContext.createBufferSource();
            source.buffer = buffer;
            source.connect(audioContext.destination);
            source.start(0);
        }
        var ttss=["有家,有爱,有欧派","未被穿过的胖次是没有价值的","巨乳只有下垂的未来","男人变态有什么错","为什么你会这么熟练啊","德国的科学技术是世界第一","在虚构的故事当中寻求真实感的人脑袋一定有问题"," 胸部什么的,明明只是装饰","勇士喜欢巨乳有什么错","哥哥让开!这样我杀不了那家伙","我们的宇宙充满了质子,中子,电子,还有奶子","有个能干的妹妹真好","只要可爱就算是男孩子也没关系","道歉時露出胸部是常識","我就是叫紫妈怎么了 有本事突然从我背后出现 把我的脸按在键盘上aqswdectfrvtghunijopioijohnuygbyfvtcdesxwedrfvtbguyhiumjiuyvftrssexrybtgnyuhm","反基复萌,反屌复奶","哼!都怪你,也不哄哄人家,人家超想哭的,捶你胸口,老公!大坏蛋!咩QAQ 捶你胸口,你好讨厌!要抱抱嘤嘤嘤,哼,人家拿小拳拳捶你胸口!大坏蛋,打死你"];
        var ttsRand=Math.floor(Math.random()*ttss.length);
        var tts=ttss[ttsRand];
        var sUrl = "http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=5&text="+tts;//`http://tts.baidu.com/text2audio?lan=zh&ie=UTF-8&spd=5&text=${tts}`;
        var p = new Promise(function(resolve, reject) {
            var ret = GM_xmlhttpRequest({method: "GET",url: sUrl,responseType: 'arraybuffer',
                onload: function(res) {
                    try {
                        audioContext.decodeAudioData(res.response, function(buffer) {resolve(buffer);});
                    } catch(e) {
                        reject(e);
                    }
                }
            });
        });
        var command=[72,65,90,85,75,65,83,72,73,73],index=0;//"hazukashii"
        document.addEventListener("keydown", function(e) {
            if(e.code == command[index]) {
                if(index == command.length - 1) {
                    index = 0;
                    var nowValue = GM_getValue("hazukashii");
                    GM_setValue("hazukashii", !nowValue);
                    if(nowValue) {
                        p.then(playSound, function(e) {
                            console.log(e);
                        });
                    }
                } else {
                    index++;
                }
            }else{
                index=0;
            }
        });

        //refer to "My Mouse Gestures"-ver.0.0.7 of Peer Zeng at [http://userscripts-mirror.org/scripts/show/463904], thanks to him
        const minLength=256,tg=0.5;
        var lastX, lastY, signs, lastSign;
        function tracer(e) {
            let curX=e.changedTouches[0].clientX,curY=e.changedTouches[0].clientY;
            let distanceX=curX-lastX,distanceY=curY-lastY;
            let distance=distanceX*distanceX+distanceY*distanceY;
            if (distance>minLength) {
                lastX=curX;
                lastY=curY;
                let direction="";
                let slope=Math.abs(distanceY/distanceX);
                if(slope>tg){
                    if(distanceY>0) {
                        direction="↓";
                    }else{
                        direction="↑";
                    }
                }else if(slope<=1/tg) {
                    if(distanceX>0) {
                        direction="→";
                    }else{
                        direction="←";
                    }
                }
                if(lastSign!=direction) {
                    signs+=direction;
                    lastSign=direction;
                }
            }
        }
        document.addEventListener("touchstart", function(e) {
            lastX=e.changedTouches[0].clientX;
            lastY=e.changedTouches[0].clientY;
            lastSign=signs="";
            document.addEventListener("touchmove", tracer, false);
        }, false);
        document.addEventListener("touchend", function(e) {
            document.removeEventListener("touchmove", tracer, false);
            if(signs=="↓→↑←"){
                e.stopPropagation();
                e.preventDefault();
                if(window.confirm("\u662f\u5426\u7981\u7528\u7f9e\u803b\u0070\u006c\u0061\u0079\u8bed\u97f3\uff1f")){
                    GM_setValue("hazukashii", true);
                }else{
                    GM_setValue("hazukashii", false);
                }
            }
        }, false);
    }
})();