Create Download Links for HACG (https)

琉璃神社、灵梦御所、纯爱计划神秘代码转换成下载链接(https版)

Stan na 26-09-2016. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Create Download Links for HACG (https)
// @namespace   hoothin
// @description 琉璃神社、灵梦御所、纯爱计划神秘代码转换成下载链接(https版)
// @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/*
// @version     3.19.8
// @grant       none
// @run-at      document-end
// @require     https://greasyfork.org/scripts/23522-olddriver-js/code/oldDriverjs.js?version=149293
// ==/UserScript==
(function(){
    if(/hacg.*about\.html/.test(location.href)){
        return;
    }
    //度盘填充提取码
    if(/baidu/.test(location.href)){
        if(location.hash.slice(1)){
            document.querySelector("#accessCode").value=location.hash.slice(1);
            document.querySelector('#submitBtn').click();
        }
        return;
    }

    var readyTags = ["p","td","pre"];
    function process(){
        var content=document.querySelector('.entry-content');
        if(/sexacg\./.test(location.href))content=document.querySelector('article');
        if(content){
            if(/sexacg\./.test(location.href)){
                var quote = content.querySelector('.su-quote-inner');
                if(quote){
                    processTxt(quote);
                }
            }

            for(var x in readyTags){
                var oldDrivers = content.querySelectorAll(readyTags[x]);
                for(var i = 0, k = oldDrivers.length; i < k; i++){
                    processTxt(oldDrivers[i]);
                }
            }

        }
        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(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 createBlockBtn(){
        var pre = document.querySelector("pre");
        if (pre && !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;";
            pre.before(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 pre = document.querySelector("pre");
            if (pre && !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]);
        }
    }
    process();
    clickBlockListener();
    document.getElementsByTagName("head")[0].appendChild(nod);
    var oD_box=document.createElement("div");
    oD_box.id="oD_box";
    oD_box.className = "oD_box";
    var oD_text=document.createElement("input");
    oD_text.id="oD_text";
    oD_text.type="text";
    oD_text.style="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,"");
        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');
    }

})();