360软件宝库下载地址解析【修改版】

【重要更新】已全局支持下载解析,不限于首页、分类、详情页等

// ==UserScript==
// @name         360软件宝库下载地址解析【修改版】
// @namespace    https://greasyfork.org/zh-CN/scripts/392699
// @version      0.3.4.1
// @description  【重要更新】已全局支持下载解析,不限于首页、分类、详情页等
// @author       AN drew
// @match        *://baoku.360.cn/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==


function getLink(appid)
{
    GM_xmlhttpRequest({
        method: "GET",
        url: "http://q.soft.360.cn/get_download_url.php?soft_ids="+appid,
        headers: {
            //"User-Agent": "",// If not specified, navigator.userAgent will be used.
            "Accept": "*/*"// If not specified, browser defaults will be used.
        },
        onload: function(response) {
            var responseXML = null;
            // Inject responseXML into existing Object (only appropriate for XML content).
            if (!response.responseXML) {
                responseXML = new DOMParser()
                    .parseFromString(response.responseText, "text/xml");
            }
            //上面是发送get请求获取xml数据

            //var xmltext=response.responseText;
            var parser=new DOMParser();
            var xmlDoc=parser.parseFromString(response.responseText,"text/xml");
            //var x=xmlDoc.getElementsByTagName("softs");

            if(xmlDoc.getElementsByTagName("durls").length==0)
            {
                alert("没有解析到软件链接,请下载其他软件");
                return;
            }

            var pdown=xmlDoc.getElementsByTagName("softs")[0].getElementsByTagName("durls")[0].childNodes[0].nodeValue;//解析获取那个xml中pdown节点的数据
            //alert(pdown);
            var str=pdown.substring(pdown.indexOf("|http"),);//分割文本
            //alert(str);
            var n=str.split("|")
            var downlink=new Array();//存放地址,理论上应该够用了
            for(var i=0;i<n.length;i++)
            {
                if(n[i]!="")
                {
                    if(n[i].indexOf(";") > -1)
                    {
                        let t=n[i].split(";");
                        for(let x=0; x<t.length; x++)
                        {
                            downlink.push(t[x]);
                        }
                    }
                    else
                    {
                        downlink.push(n[i]);
                    }
                }
            }

            console.log(downlink)
            showLinks(downlink);

        }
    });
}

function showLinks(downlink)
{
    var $box =$('<div id="box">'+
                '<span id="closeBtn">'+
                '<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBzdGFuZGFsb25lPSJubyI/Pjw'+
                'hRE9DVFlQRSBzdmcgUFVCTElDICItLy9XM0MvL0RURCBTVkcgMS4xLy9FTiIgImh0dHA6Ly93d3cu'+
                'dzMub3JnL0dyYXBoaWNzL1NWRy8xLjEvRFREL3N2ZzExLmR0ZCI+PHN2ZyB0PSIxNTk0NDc5MjM4M'+
                'Tc1IiBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgdmVyc2lvbj0iMS4xIiB4bW'+
                'xucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHAtaWQ9IjEzMDQiIHhtbG5zOnhsaW5rPSJ'+
                'odHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iMjAwIiBoZWlnaHQ9IjIwMCI+PGRl'+
                'ZnM+PHN0eWxlIHR5cGU9InRleHQvY3NzIj5AZm9udC1mYWNlIHsgZm9udC1mYW1pbHk6IGVsZW1lb'+
                'nQtaWNvbnM7IHNyYzogdXJsKCJjaHJvbWUtZXh0ZW5zaW9uOi8vYmJha2hubWZramVuZmJoamRkZG'+
                'lwY2VmbmhwaWtqYmovZm9udHMvZWxlbWVudC1pY29ucy53b2ZmIikgZm9ybWF0KCJ3b2ZmIiksIHV'+
                'ybCgiY2hyb21lLWV4dGVuc2lvbjovL2JiYWtobm1ma2plbmZiaGpkZGRpcGNlZm5ocGlramJqL2Zv'+
                'bnRzL2VsZW1lbnQtaWNvbnMudHRmICIpIGZvcm1hdCgidHJ1ZXR5cGUiKTsgfQo8L3N0eWxlPjwvZ'+
                'GVmcz48cGF0aCBkPSJNNTEyIDg1LjMzMzMzM0MyNzYuNDggODUuMzMzMzMzIDg1LjMzMzMzMyAyNz'+
                'YuNDggODUuMzMzMzMzIDUxMlMyNzYuNDggOTM4LjY2NjY2NyA1MTIgOTM4LjY2NjY2NyA5MzguNjY'+
                '2NjY3IDc0Ny41MiA5MzguNjY2NjY3IDUxMiA3NDcuNTIgODUuMzMzMzMzIDUxMiA4NS4zMzMzMzN6'+
                'IG0xMzYuNTMzMzMzIDUzMS4zNDIyMjNjMTEuMzc3Nzc4IDExLjM3Nzc3OCAxMS4zNzc3NzggMjkuN'+
                'TgyMjIyIDAgMzkuODIyMjIyLTUuNjg4ODg5IDUuNjg4ODg5LTEyLjUxNTU1NiA3Ljk2NDQ0NC0yMC'+
                '40OCA3Ljk2NDQ0NHMtMTQuNzkxMTExLTIuMjc1NTU2LTIwLjQ4LTcuOTY0NDQ0TDUxMiA1NTkuNzg'+
                '2NjY3bC05Ni43MTExMTEgOTYuNzExMTExYy01LjY4ODg4OSA1LjY4ODg4OS0xMi41MTU1NTYgNy45'+
                'NjQ0NDQtMjAuNDggNy45NjQ0NDRzLTE0Ljc5MTExMS0yLjI3NTU1Ni0yMC40OC03Ljk2NDQ0NGMtM'+
                'TEuMzc3Nzc4LTExLjM3Nzc3OC0xMS4zNzc3NzgtMjkuNTgyMjIyIDAtMzkuODIyMjIybDk2LjcxMT'+
                'ExMS05Ni43MTExMTItMTA0LjY3NTU1Ni0xMDQuNjc1NTU1Yy0xMS4zNzc3NzgtMTEuMzc3Nzc4LTE'+
                'xLjM3Nzc3OC0yOS41ODIyMjIgMC0zOS44MjIyMjIgMTEuMzc3Nzc4LTExLjM3Nzc3OCAyOS41ODIy'+
                'MjItMTEuMzc3Nzc4IDM5LjgyMjIyMyAwbDEwNC42NzU1NTUgMTA0LjY3NTU1NSAxMDQuNjc1NTU2L'+
                'TEwNC42NzU1NTVjMTEuMzc3Nzc4LTExLjM3Nzc3OCAyOS41ODIyMjItMTEuMzc3Nzc4IDM5LjgyMj'+
                'IyMiAwIDExLjM3Nzc3OCAxMS4zNzc3NzggMTEuMzc3Nzc4IDI5LjU4MjIyMiAwIDM5LjgyMjIyMmw'+
                'tMTA0LjY3NTU1NiAxMDQuNjc1NTU1IDk3Ljg0ODg4OSA5Ni43MTExMTJ6IiBwLWlkPSIxMzA1IiBm'+
                'aWxsPSIjZDgxZTA2Ij48L3BhdGg+PC9zdmc+">'+
                '</span>'+
                '</div>');
    $("body").append($box);

    for(var i=0;i<downlink.length;i++)
    {
        var link = "<div class='downloadTag'>下载地址"+(i+1)+":</div><br><a href=\""+downlink[i]+"\">"+downlink[i]+"</a><br>"
        $("#box").append($(link));
    }

    $("#box").fadeIn("fast");
    //获取页面文档的高度
    var docheight = $(document).height();
    //追加一个层,使背景变灰
    $("body").append("<div id='greybackground'></div>");
    $("#greybackground").css({"opacity":"0.5","height":docheight});

    var screenwidth,screenheight,mytop,getPosLeft,getPosTop
    screenwidth = $(window).width();
    screenheight = $(window).height();
    //获取滚动条距顶部的偏移
    mytop = $(document).scrollTop();
    //计算弹出层的left
    getPosLeft = screenwidth/2 - 260;
    //计算弹出层的top
    getPosTop = screenheight/2 - 150;
    //css定位弹出层
    $("#box").css({"left":getPosLeft,"top":getPosTop+mytop});
    //当浏览器窗口大小改变时...
    $(window).resize(function(){
        screenwidth = $(window).width();
        screenheight = $(window).height();
        mytop = $(document).scrollTop();
        getPosLeft = screenwidth/2 - 260;
        getPosTop = screenheight/2 - 150;
        $("#box").css({"left":getPosLeft,"top":getPosTop+mytop});
    });

    //当拉动滚动条时...
    $(window).scroll(function(){
        screenwidth = $(window).width();
        screenheight = $(window).height();
        mytop = $(document).scrollTop();
        getPosLeft = screenwidth/2 - 260;
        getPosTop = screenheight/2 - 150;
        $("#box").css({"left":getPosLeft,"top":getPosTop+mytop});
    });

    //点击关闭按钮
    $("#closeBtn").click(function() {
        $("#box").remove();
        //删除变灰的层
        $("#greybackground").remove();
        return false;
    });

}

(function() {
    'use strict';

    var css = '* {margin:0;padding:0;}'+
        '#box {display:none;position:absolute;width:520px;height:300px;border:#f60 solid 2px;z-index:4000;background:#fff;word-break:break-all; word-wrap:break-word; background:linear-gradient(to right, #eee 0%,#ddd 100%)}'+
        '#box img {height:25px; width:25px}'+
        '#box a {font-size:15px;}'+
        '#box .downloadTag {margin-top:30px; font-size:20px;}'+
        '#closeBtn {position:absolute;right:10px;top:10px;cursor:pointer;}'+
        '#greybackground {background:#000;display:block;z-index:3000;width:100%;position:absolute;top:0;left:0;}';

    var head = document.getElementsByTagName('head')[0];
    var style = document.createElement('style');
    var icon = document.createElement('link');
    head.appendChild(icon);

    icon.rel="icon";
    icon.href="https://gitee.com/AN_drew/picBed/raw/master/img/baoku.png";

    style.type = 'text/css';
    if(style.styleSheet)
    {
        style.styleSheet.cssText = css;
    }
    else
    {
        style.appendChild(document.createTextNode(css));
    }
    head.appendChild(style);

    //点击链接弹出窗口
    $(".js-btn-download").click(function(){
        let appid = $(this).attr("data-softid");
        getLink(appid);
        return false;
    });

    $(".safe-btn-download").click(function(){
        let appid = $(this).attr("data-softid");
        getLink(appid);
        return false;
    });

})();