琉神转 | Create Download Links for HACG (https)

琉璃神社与其他绅士站神秘代码转换成下载链接

От 06.10.2016. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name        琉神转 | Create Download Links for HACG (https)
// @namespace   hoothin
// @description 琉璃神社与其他绅士站神秘代码转换成下载链接
// @author      hoothin
// @include     http*://www.hacg.*/wordpress/*
// @include     http*://hacg.*/wordpress/*
// @include     http*://www.hacg.*/wp/*
// @include     http*://hacg.*/wp/*
// @include     http*://blog.reimu.net/*
// @include     http*://pan.baidu.com/share/*
// @include     http*://pan.baidu.com/s/*
// @include     http*://sexacg.com/*
// @include     http*://www.acg.tf/*
// @include     http*://www.shenshi.re/*
// @include     http*://acg.tf/*
// @include     http*://shenshi.re/*
// @include     http*://www.moxacg.com/*
// @include     http*://*.acggj.com/*
// @include     http*://acg12.com/*
// @include     http*://*.acg12.com/*
// @include     http*://www.acgnz.cc/*
// @include     http*://nacg.me/*
// @include     http*://www.tianshit.com/*
// @include     http*://www.oomoe.moe/*
// @include     http*://www.kaze5.com/*
// @include     http*://www.acglover.top/*
// @version     3.19.28
// @grant       none
// @run-at      document-end
// @require     https://greasyfork.org/scripts/23522-olddriver-js/code/oldDriverjs.js?version=150983
// @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
// @require     https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/enc-base64-min.js
// ==/UserScript==
(function(){
    //度盘填充提取码
    if(/baidu/.test(location.href)){
        if(location.hash.slice(1)){
            document.querySelector("#accessCode").value=location.hash.slice(1);
            document.querySelector('#submitBtn').click();
        }
        return;
    }

    var sites=[["https://www.hacg.fi/wp/",".hacg."],
               ["https://blog.reimu.net/","blog.reimu."],
               ["https://sexacg.com/","sexacg"],
               ["https://www.acggj.com/","acggj."],
               ["http://nacg.me/","nacg.me"],
               ["https://www.tianshit.com/","tianshit."],
               ["https://www.oomoe.moe/","oomoe.moe"],
               ["http://www.kaze5.com/","kaze5.com"],
               ["http://www.acglover.top/","acglover.top"],
               ["https://acg12.com/","acg12."],
               ["https://www.acgnz.cc/","acgnz.cc"],
               ["https://www.moxacg.com/","moxacg."],
               ["https://www.acg.tf/",".acg.tf"]];
    document.onkeydown= function(e) {
        if (e.keyCode == 117) {
            var i=0;
            for(var j=sites.length;i<j;i++){
                if(location.href.indexOf(sites[i][1]) !=-1){
                    break;
                }
            }
            if(e.shiftKey) i=i===0?(sites.length-1):(i-1);
            else i=i==(sites.length-1)?0:(i+1);
            location.href = sites[i][0];
            return false;
        }
    };

    if(/hacg.*about\.html/.test(location.href)){
        return;
    }

    if(/acg\.tf/.test(location.href)){
        var content=document.querySelector('.entry-inner');
        if(content){
            var plist = content.querySelectorAll("p");
            var key = "";
            for(var pNode of plist){
                if(/(?<=密匙[::])\S*/i.test(pNode.innerHTML)){
                    var orgStr = pNode.innerHTML.match(/(?<=密匙[::])(\S*)/i)[0];
                    key=CryptoJS.enc.Base64.parse(orgStr).toString(CryptoJS.enc.Utf8);
                    pNode.innerHTML = "";
                    break;
                }
            }
            if(key !==""){
                var blockquotes = content.querySelectorAll("blockquote");
                for(var blockquote of blockquotes){
                    var target = blockquote.querySelector("p");
                    if(!target||target.innerText===""){continue;}
                    var result = target.innerHTML.replace(/<br>/g,"").replace(/\s/g,"");
                    result = CryptoJS.AES.decrypt(result,key).toString(CryptoJS.enc.Utf8);
                    target.innerHTML = result;
                }

            }
        }
    }

    function process(){
        var content=document.querySelector('.entry-content');
        var is2https=false;
        if(/sexacg\./.test(location.href))content=document.querySelector('article');
        else if(/acg\.tf/.test(location.href))content=document.querySelector('.entry-inner');
        else if(/moxacg\./.test(location.href)){
            document.addEventListener('DOMNodeInserted', function(e) {
                if(document.readyState == "complete" && !is2https){
                    is2https=true;
                    var times=0;
                    var t=setInterval(function(){
                        if(times==1){
                            moxacg2https(false);
                        }else if(times==8){
                            is2https=false;
                            clearInterval(t);
                        }
                        times++;
                    },500);
                }
            });
            moxacg2https(true);
        }
        else if(/acggj\./.test(location.href)){
            var tags=["img","a","script","link"];
            for(var tag of tags){
                var acggjLink = document.querySelectorAll(tag);
                for (var i = 0, k = acggjLink.length; i < k; i++) {
                    if (acggjLink[i].parentNode && /p:\/\/(www\.|bbs\.)?acggj/i.test(acggjLink[i].outerHTML)) {
                        acggjLink[i].outerHTML = acggjLink[i].outerHTML.replace(/p:\/\/(www\.|bbs\.)?acggj/gi, 'ps:\/\/$1acggj');
                    }else if (acggjLink[i].parentNode && !/\/\//i.test(acggjLink[i].outerHTML)) {
                        acggjLink[i].outerHTML = acggjLink[i].outerHTML.replace(/src="(?!")/gi, 'src="https://'+document.domain+"/").replace(/href="(?!")/gi, 'href="https://'+document.domain+"/");
                    }
                }
            }
            var benzi=document.querySelector('#menu-item-3786');
            if(benzi){
                var scy=benzi.cloneNode(true);
                scy.innerHTML = scy.innerHTML.replace(/本子/gi, '三次元').replace(/hexie\/book/gi, 'sciyuan').replace(/fa-book/gi, 'fa-instagram');
                benzi.after(scy);
            }
        }else if(/acg12\./.test(location.href)){
            document.addEventListener('DOMNodeInserted', function(e) {
                if(document.readyState == "complete" && !is2https){
                    is2https=true;
                    var times=0;
                    var t=setInterval(function(){
                        if(times==1){
                            acg122https(false);
                        }else if(times==8){
                            is2https=false;
                            clearInterval(t);
                        }
                        times++;
                    },500);
                }
            });
            acg122https(true);
        }else if(/acgnz\.cc/.test(location.href)){
            document.addEventListener('DOMNodeInserted', function(e) {
                if(document.readyState == "complete" && !is2https){
                    is2https=true;
                    var times=0;
                    var t=setInterval(function(){
                        if(times==1){
                            acgnz2https(false);
                        }else if(times==8){
                            is2https=false;
                            clearInterval(t);
                        }
                        times++;
                    },500);
                }
            });
            acgnz2https(true);
        }else if(/nacg\.me/.test(location.href)){
            content=document.querySelector('.article-content');
        }else if(/tianshit\.com/.test(location.href)){
            content=document.querySelector('.article-content');
        }
        if(content){
            var oldDrivers = content.childNodes;
            for(var childOd of oldDrivers){
                if(childOd.innerHTML){
                    processTxt(childOd);
                }
            }
        }
        var link;
        if (document.querySelectorAll) {
            link = document.querySelectorAll('a');
        } else {
            link = document.getElementsByTagName('a');
        }
        for (var i = 0, k = link.length; i < k; i++) {
            if (/.*http:.*\.hacg\./i.test(link[i].outerHTML)) {
                link[i].href = link[i].outerHTML.match(/(?<=href=").*?(?=")/i)[0].replace(/http/, 'https');
            }
            var target=link[i];
            if(/baidu.com/i.test(target.href)&&!/(?:eyun|tieba)\.baidu\.com/i.test(target.href)&&!/#/i.test(target.href)){
                if(/(acggj\.com|oomoe\.moe|kaze5\.com)\/storage-download/.test(location.href)){
                    var pass=document.querySelector('#theme_custom_storage-0-download-pwd');
                    if(pass)target.href+='#'+pass.value;
                } else if(/acg12\.com\/download/.test(location.href)){
                    var pass2=document.querySelector('#downloadPwd-0');
                    if(pass2)target.href+='#'+pass2.value;
                } else if(codeRule.test(target.textContent)){
                    target.href+='#'+extCode(target);
                } else if(target.nextSibling&&codeRule.test(target.nextSibling.textContent)){
                    if(!/#\S+/i.test(target.href)){
                        target.href+=/#/i.test(target.href)?extCode(target.nextSibling):('#'+extCode(target.nextSibling));
                    }
                } else if(codeRule.test(target.parentNode.textContent)){
                    if(!/#\S+/i.test(target.href)) target.href+=/#/i.test(target.href)?extCode(target.nextSibling):('#'+extCode(target.nextSibling));
                } 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;
                    }
                }
            }
        }
    }

    function moxacg2https(init){
        var httpsTag=init?["body","a","img","link","script"]:["a","img"];
        for(var tag of httpsTag){
            var link = document.querySelectorAll(tag);
            for (var i = 0, k = link.length; i < k; i++) {
                if (link[i].parentNode && /p:\/\/(www\.)?moxacg/i.test(link[i].outerHTML)) {
                    link[i].outerHTML = link[i].outerHTML.replace(/p:\/\/(www\.)?moxacg/gi, 'ps:\/\/$1moxacg');
                }
            }
        }
    }

    function acg122https(init){
        var httpsTag=init?["a","img","link","script"]:["a","img"];
        for(var tag of httpsTag){
            var link = document.querySelectorAll(tag);
            for (var i = 0, k = link.length; i < k; i++) {
                if (link[i].parentNode && /p:\/\/(www\.|static\.)?acg12/i.test(link[i].outerHTML)) {
                    link[i].outerHTML = link[i].outerHTML.replace(/p:\/\/(www\.|static\.)?acg12/gi, 'ps:\/\/$1acg12');
                }
            }
        }
    }

    function acgnz2https(init){
        var httpsTag=init?["a","img","link","script"]:["a","img"];
        console.log(111);
        for(var tag of httpsTag){
            var acgnzLink = document.querySelectorAll(tag);
            for (var i = 0, k = acgnzLink.length; i < k; i++) {
                if (acgnzLink[i].parentNode && /p:\/\/(www\.)?acgnz/i.test(acgnzLink[i].outerHTML)) {
                    acgnzLink[i].outerHTML = acgnzLink[i].outerHTML.replace(/p:\/\/(www\.)?acgnz/gi, 'ps:\/\/$1acgnz');
                }else if (acgnzLink[i].parentNode && !/\/\//i.test(acgnzLink[i].outerHTML)) {
                    acgnzLink[i].outerHTML = acgnzLink[i].outerHTML.replace(/src="(?!")/gi, 'src="https://'+document.domain+"/").replace(/href="(?!")/gi, 'href="https://'+document.domain+"/");
                }
                if (acgnzLink[i].parentNode && /"\/\/(pic|tc)\.(ffsky|rpgsky)/i.test(acgnzLink[i].outerHTML)) {
                    acgnzLink[i].outerHTML = acgnzLink[i].outerHTML.replace(/"\/\/(pic|tc)\.(ffsky|rpgsky)/gi, '"http:\/\/$1\.$2');
                }
            }
        }
    }

    function createBlockBtn(){
        var pre = document.querySelector("pre");
        var author = document.querySelector(".author-info");
        if (author && !document.querySelector("#blockBtn")) {
            var blockBtn=document.createElement("button");
            blockBtn.id="blockBtn";
            blockBtn.type="button";
            blockBtn.textContent="好孩子看不到";
            blockBtn.style="padding:4px 0;position: relative;width:120px;";
            if(pre){
                pre.before(blockBtn);
            }else{
                blockBtn.style="display:none;";
                author.appendChild(blockBtn);
            }
        }
    }

    function clickBlockListener(){
        if(document.querySelector("#blockBtn")){
            document.querySelector("#blockBtn").addEventListener("click", function(){
                if(this.nextSibling.style.display == 'block'){
                    this.nextSibling.style.display = '';
                }else{
                    this.nextSibling.style.display = 'block';
                }
            });
        }
    }

    if (/reimu\./.test(location.href)){
        document.querySelector("#main").addEventListener('DOMNodeInserted', function(e) {
            var author = document.querySelector(".author-info");
            if (author && !document.querySelector("#blockBtn")) {
                createBlockBtn();
                process();
                clickBlockListener();
            }
        });
        createBlockBtn();
    }

    //防爆补丁
    var feiZao=document.getElementsByTagName("p1");
    var fZLength=feiZao.length;
    if (!!fZLength){
        for (var i = 0; i < fZLength; i++){
            feiZao[0].parentNode.removeChild(feiZao[0]);
        }
    }
    var t;
    function checkAcg12(){
        if(document.querySelector('.btn-success')){
            clearInterval(t);
            process();
        }
    }
    if(/acg12\.com\/download/.test(location.href)){
        t=window.setInterval(checkAcg12,1000);
    }
    process();
    clickBlockListener();

    if(!/nacg\.me/.test(location.href)){
        document.getElementsByTagName("head")[0].appendChild(nod);
        var 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";
        };
        oD_box.onmouseout = function(e) {
            oD_link.style.visibility = "hidden";
            oD_link2.style.visibility = "hidden";
        };
        var oD_text=document.createElement("input");
        oD_text.id="oD_text";
        oD_text.type="text";
        oD_text.style="min-height:25px;max-height:33px";
        oD_text.placeholder="输入hash值";
        oD_text.title='将自动添加"magnet:?xt=urn:btih:",去除[]中的内容、非字母数字字符、空格';
        var oD_button=document.createElement("button");
        oD_button.id="oD_button";
        oD_button.type="button";
        oD_button.textContent="开车";
        oD_button.style="padding:4px 0;position: absolute;top:-1px;right:0px;width:40px;height:35px";
        oD_button.onclick=function (){
            var oD_hash=oD_text.value.replace(/(\[.*\])|[\W_]/g,"");
            if(oD_hash===""){
                alert("请输入hash值");
                return;
            }else if(!regObj.btih.test(oD_hash)){
                alert("hash值格式错误");
                return;
            }
            oD_link.href="magnet:?xt=urn:btih:"+oD_hash;
            oD_link.textContent="磁链";
            oD_link2.href="http://www.torrent.org.cn/Home/Convert/magnet2torrent.html?hash="+oD_hash;
            oD_link2.textContent="种子";
            oD_link2.style="margin-left:20px";
            oD_link3.href="http://www.btaia.com/torrent/detail/hash/"+oD_hash;
            oD_link3.textContent="详情";
            oD_link3.style="margin-left:20px";
        };
        var oD_link=document.createElement("a");
        var oD_link2=document.createElement("a");
        var oD_link3=document.createElement("a");
        oD_link2.target="_blank";
        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);
        document.body.appendChild(oD_box);
    }
    //评论区度娘、115、tcn
    seriousReplace('comment-content');
    if(/sexacg\./.test(location.href)){
        seriousReplace('su-quote-inner');
    }

})();