VIP会员视频在线解析大集合

[腾讯|爱奇艺|优酷|乐视|芒果|AB站|音悦台]等VIP或会员视频,在线解析接口插件

目前为 2020-05-02 提交的版本。查看 最新版本

// ==UserScript==
// @name         VIP会员视频在线解析大集合
// @namespace    https://greasyfork.org/zh-CN/users/505018
// @iconURL      https://v.qq.com/favicon.ico
// @version      1.0.2
// @description  [腾讯|爱奇艺|优酷|乐视|芒果|AB站|音悦台]等VIP或会员视频,在线解析接口插件
// @author       DreamFly
// @noframes
// @require      https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @match        http*://v.qq.com/x/cover/*
// @match        http*://*.iqiyi.com/*
// @match        http*://*.youku.com/*
// @match        http*://*.le.com/*
// @match        http*://*.letv.com/*
// @match        http*://*.tudou.com/*
// @match        http*://*.mgtv.com/*
// @match        http*://film.sohu.com/*
// @match        http*://tv.sohu.com/*
// @match        http*://*.acfun.cn/v/*
// @match        http*://*.bilibili.com/*
// @match        http*://vip.1905.com/play/*
// @match        http*://*.pptv.com/*
// @match        http*://v.yinyuetai.com/video/*
// @match        http*://v.yinyuetai.com/playlist/*
// @match        http*://*.fun.tv/vplay/*
// @match        http*://*.wasu.cn/Play/show/*
// @match        http*://*.56.com/*
// @exclude      http*://*.bilibili.com/blackboard/*
// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        unsafeWindow
// @grant        GM_xmlhttpRequest
// @grant        GM.xmlHttpRequest
// @grant        GM_openInTab
// @grant        GM.openInTab
// ==/UserScript==

(function() {
    'use strict';

    const VQQIcon = '<svg height="1.2em" width="1.2em" viewbox="0 0 185 170"><defs><path id="vQQ" d="M7 20 Q14 -10 55 7 Q100 23 145 60 Q170 80 145 102 Q108 138 47 165 Q15 175 4 146 Q-5 80 7 20"></path></defs><use style="fill:#44B9FD;" transform="translate(27,0)" xlink:href="#vQQ"></use><use style="fill:#FF9F01;" transform="translate(0,18),scale(0.8,0.75)" xlink:href="#vQQ"></use><use style="fill:#97E61B;" transform="translate(23,18),scale(0.80.75)" xlink:href="#vQQ"></use><use style="fill:#fff;" transform="translate(50,45),scale(0.4)" xlink:href="#vQQ"></use></svg>';
    const IQiyiIcon = '<svg xmlns="http://www.w3.org/2000/svg" x="0" y="0" width="12" height="12"><image width="12" height="12" x="0" y="0" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMEAYAAAAG5YCkAAAABGdBTUEAALGPC/xhBQAAACBjSFJN AAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0T///////8JWPfcAAAA B3RJTUUH4wgJFC0QN86G4AAAA8FJREFUOMsFwX1MlHUAwPHv73meu5PjnWMSkSZYDHRuzj8UEbXN CudEQXQunAOzWnO1+V5BC5i6U7NcqPmW4cK0mSaWIYWJQbrKNSCiVGwnKHpyceDD2z33PPf8+nyE c/judTh3jQamQ2GZ7KALVJ/soxtA5tEDwBkeA6ARBqCIWABxjWcBRCI5AGI2z0NkKkX4of6kcMZ3 u8FUtZep13Zplme9OsPjh8Sl6s7EnyC6Rfkz5mlwbRVB5+dANhGRAeF+OdlogZG37byRKTDksvcN HYSBYqtt4DqEe8gyf7Y0kZx150psh5Tlucn5H3wI6XOV/Rn7QLetXL0XzDq5x/wM7DRZZieCXMYd uQTUcXFTBVwlSvuEzRC9RPW4C+DhXftgXwvsXDhQUd0JWmoueWmLIcFt3UisgOOr9DnHciA1yrE9 tQru9Zu7fT/AvQ7zG58B7iPKafdfoFVxWTsB+opIly5g2rDz9PTbULgvzrviCDzj4/CkvaCJ3Eir 2A4PDhiLHpyD/A1x8xaXQ/JsdifnQ/ze+OL4m9CxJxRoL4CYI+LNGBU8L2plHjfoL8iA/hqELlsF 4W0Q9bX6vdsBCRPF/oRaUBw75B5HMyQsUI2EcYhtZU7MGugtNk/dbwe73z4kN0L0CZke7YbRj6zV YzXwz9nR0VvLYEV03L8rl8B1j36q9SJMaBFRrpdAO2Ab2gNQ3CVybfS3MMXrqkyfBsph2a02AXX2 PO4DvfIWIcBvzweQbfKCXQu/TNNLW9PAVzxe6/NB++8jt9s6QZkrtyk5QE9kHYAS2RDZFCmHcZ/V O74Y+meFegOX4Lkapzb1PrjWYjjjYKzQzBkvhHC7NSncBU8qTNdQJvStNi48fAfGqqzvxtJhNGJO HTsKps9Ktx6Bps8xFj3JgsH1xuygA85/2b/1bBdMXCMcKQZk/u1uzUyCplf0vh+/AP1Xe7peDEPL ZdLgVdj1ru+r6hhwNyp/uL3wX6PRF6iB4KdGVrASNH9BKOzXwVpgLYy8Du95J22pOAPB49beoBfC Jfal8ElIb499I6MH5HzxvqwCx0bqHevAuVJsdh6FxAa1JakDAtmhmYFK8BeFmh/FgtDym7PBdDob I1tcqZrx1BQlLSUFkoJaadJGiKlVumN7wHVD2eTSgIWYzIJwtX0gvBqG6+yS4VIYfMs6HRwEf5P9 yeMGMPJVbyhoOYUj7aoK5yfLHXIAlsfJj6kBtdP+TW4DIA8vgDzGFQAkQQBRwioAmigHUGaKQwCi mlchMkMcFh64OPI/QLSjdm0wihoAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTktMDgtMTBUMDM6NDU6 MTYtMDc6MDBV2/HBAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE5LTA4LTEwVDAzOjQ1OjE2LTA3OjAw JIZJfQAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAAASUVORK5CYII="/></svg>';
    const YoukuIcon = '<svg width="1.2em" height="1.2em" viewbox="0 0 72 72"><defs><circle id="youkuC1" r="5.5" style="stroke:none;;fill:#0B9BFF;"></circle><path id="youkuArow" d="m0,10 a5,5 0,0,1 0,-10 h20 a5,5 0,0,1 0,10z" style="fill:#FF4242;"></path></defs><circle cx="36" cy="36" r="30.5" style="stroke:#30B4FF;stroke-width:11;fill:none;"></circle><use x="10.5" y="19" xlink:href="#youkuC1"/><use x="61.5" y="53" xlink:href="#youkuC1"/><use x="39" y="1" transform="rotate(30)" xlink:href="#youkuArow"/><use x="-1" y="52" transform="rotate(-35)" xlink:href="#youkuArow"/></svg>';
    var websites = [/qq.com/i, /iqiyi.com/i, /youku.com/i]
    var webIcons = [VQQIcon, IQiyiIcon, YoukuIcon]
    var icon = '';

    for (let i in websites) {
        if (websites[i].test(location.href)) {
            icon = webIcons[i];
        }
    }

    var defaultApi = {
        title: "618G,失效请更换接口",
        url: "http://jx.618g.com/?url="
    };

    //fixedApis name:显示的文字  url:接口  title:提示文字  intab:是否适合内嵌(嵌入判断:GMgetValue("replaceRaw",false)值||intab值)
    var fixedApis = [
        { name: "618G" + icon, url: "http://jx.618g.com/?url=", title: "618G", intab: 0 },
        { name: "玩的嗨" + icon, url: "http://tv.wandhi.com/go.html?url=", title: "综合接口,一键VIP*** 更新可用【作者mark zhang】脚本的接口", intab: 0 },
        { name: "搜你妹" + icon, url: "http://www.sonimei.cn/?url=", title: "综合接口,VIP视频*** 更新可用【作者sonimei134】脚本的接口", intab: 0 },
        { name: "TIMERD" + icon, url: "https://timerd.me/static/cv.html?zwx=", title: "不稳定,广告过滤软件可能有影响", intab: 1 },
        { name: "石头解析" + icon, url: "https://jiexi.071811.cc/jx.php?url=", title: "手动点播放", intab: 1 },
        { name: "乐乐云" + icon, url: "https://660e.com/?url=", title: "乐乐云,未知效果", intab: 1 },
        { name: "小鑫视频" + icon, url: "https://www.3aym.cn/?url=", title: "小鑫视频,未知效果", intab: 0 },
        { name: "VIP看看" + icon, url: "http://q.z.vip.totv.72du.com/?url=", title: "更换线路成功率会提高", intab: 1 },
        { name: "163人" + icon, url: "http://jx.api.163ren.com/vod.php?url=", title: "偶尔支持腾讯", intab: 1 },
        { name: "无名小站" + icon, url: "http://www.sfsft.com/admin.php?url=", title: "无名小站同源", intab: 1 },
        { name: "无名小站2" + icon, url: "http://www.wmxz.wang/video.php?url=", title: "转圈圈就换线路", intab: 1 },
        { name: "人人发布" + icon, url: "http://v.renrenfabu.com/jiexi.php?url=", title: "综合,多线路", intab: 0 }
    ];

    var cssStyle = `
/*TMDFVideoContainer*/

#TMDFVideoContainer {
    z-index: 999998;
    background: rgba(0, 0, 0, .7);
    position: fixed;
    top: 7em;
    left: 5em;
    height: 65%;
    width: 65%;
    resize: both;
    overflow: auto;
    box-shadow: 2px 2px 5px 5px rgba(125, 125, 250, .8);
}

#TMDFVideoContainer button {
    top: .1em;
    cursor: pointer;
    visibility: hidden;
    font-size: 3em;
    color: #ffffffff;
    background: transparent;
    border: 0;
}

#TMDFVideoContainer:hover button {
    visibility: visible;
}

#TMDFVideoContainer:hover button:hover {
    color: #ff0;
}

/*TMDFIframe*/

#TMDFiframe {
    height: 100%;
    width: 100%;
    overflow: auto;
    position: absolute;
    top: 0;
    left: 0;
    margin: auto;
    border: 0;
    box-shadow: 0 0 3em rgba(0, 0, 0, .4);
    z-index: -1;
}

/*TMDFVideoSetting*/
#TMDFVideoSetting {
     text-align: center;
}

/*TMDFCustomApi*/

#TMDFCustomApi li {
    margin: 5px;
    width: 100%;
    list-style-type: none;
}

/*TMDFul*/

#TMDFul {
    position: fixed;
    top: 5em;
    left: 0;
    padding: 0;
    z-index: 999999;
}

#TMDFul li {
    list-style: none;
}

#TMDFul svg {
    float: right;
}

.TMDFul2 {
    position: absolute;
    top: 0;
    left: 1.5em;
    display: none;
    border-radius: .3em;
    margin: 0;
    padding: 0;
}

.TMDFul2 li {
    float: none;
    width: 7em;
    margin: 0;
    font-size: 1em;
    padding: .15em 1em;
    cursor: pointer;
    color: #3a3a3a!important;
    background: rgba(125, 125, 250, 0.8);
}

.TMDFul2 li:hover {
    color: white!important;
    background: rgba(0, 0, 0, .8);
}

.TMDFul2 li:first-child {
    border-radius: .35em .35em 0 0;
}

.TMDFul2 li:last-child {
    border-radius: 0 0 .35em .35em;
}

.TMDFli1 {
    opacity: 0.3;
    position: relative;
    padding-right: .5em;
    width: 1.5em;
    cursor: pointer;
}

.TMDFli1:hover {
    opacity: 1;
}

.TMDFli1 span {
    display: block;
    border-radius: 0 .3em .3em 0;
    background-color: rgba(125, 125, 250, 1.0);
    border: 0;
    font: bold 1em "微软雅黑"!important;
    color: rgb(0, 255, 255);
    margin: 0;
    padding: 1em .3em;
}

.TMDFli1:hover .TMDFul2 {
    display: block;
}

.TMDFli2 {
     text-align: center;
}

/*自定义解析接口,本页播放窗口设置*/

.TMDFp {
    position: fixed;
    top: 20%;
    left: 20%;
    z-index: 999999;
    background: rgba(125, 125, 250, 0.9);
    padding: 30px 20px 10px 20px;
    border-radius: 10px;
    text-align: left;
}

.TMDFp * {
    font-size: 16px;
    font-family: '微软雅黑';
    color: #3a3a3a;
    //box-shadow: 0 0 3em rgba(0, 0, 0, .4);
}

.TMDFp fieldset {
    margin: 0;
    padding: 10px;
}

.TMDFp legend {
    padding: 0 10px;
    text-align: center;
}

.TMDFp label {
    display: inline-block;
}

.TMDFp input[type=text] {
    border-radius: 5px !important;
    border: 1px solid #3a3a3a;
    margin: 2px 10px 2px 5px;
    padding: 2px 5px;
}

.TMDFp button {
    border: 1px solid #3a3a3a;
    border-radius: 5px;
    cursor: pointer;
    padding: 2px 10px;
    margin: 10px 20px 0 20px;
}

.TMDFp button:hover {
    background: #3a3a3a;
    color: yellow;
}

.TMDFtext1 {
    width: 350px;
}

.TMDFtext2 {
    width: 160px;
}

.TMDFClose {
    position: absolute;
    top: 3px;
    left: 3px;
    margin: 0!important;
}

.TMDFspan80 {
    display: inline-block;
    text-align: right;
    width: 80px;
}

.TMDFspan120 {
    display: inline-block;
    text-align: right;
    width: 120px;
}

.TMDFDelete {
    float: left;
    display: inline-block;
    color: red;
    padding: 0 10px !important;
    cursor: pointer;
}

.TMDFCheckbox {
    margin-left: 4px;
    margin-right: 4px;
}

.TMDFName {
}

.TMDFLink {
}

li:hover .TMDFDelete,
li:hover .TMDFCheckbox,
li:hover .TMDFName,
li:hover .TMDFLink {
    background: rgba(73,163,230,0.62);
}
`;
    /* 兼容 Tampermonkey | Violentmonkey | Greasymonkey 4.0+
     * 为了兼容GreasyMonkey 4.0 获取结构化数据,比如 json Array 等,
     * 应当先将字符串还原为对象,再执行后续操作
     * GMgetValue(name,defaultValue)
     */
    function GMgetValue(name, defaultValue) {
        if (typeof GM_getValue === 'function') {
            return GM_getValue(name, defaultValue);
        } else {
            return GM.getValue(name, defaultValue);
        }
    }

    /* 兼容 Tampermonkey | Violentmonkey | Greasymonkey 4.0+
     * 为了兼容GreasyMonkey 4.0 储存结构化数据,比如 json Array 等,
     * 应当先将对象字符串化,
     * GMsetValue(name, JSON.stringify(defaultValue))
     */
    function GMsetValue(name, defaultValue) {
        if (typeof GM_setValue === 'function') {
            GM_setValue(name, defaultValue);
        } else {
            GM.setValue(name, defaultValue);
        }
    }

    /* 兼容 Tampermonkey | Violentmonkey | Greasymonkey 4.0+ */
    function GMxmlhttpRequest(obj) {
        if (GM_xmlhttpRequest === "function") {
            GM_xmlhttpRequest(obj);
        } else {
            GM.xmlhttpRequest(obj);
        }
    }

    /* 兼容 Tampermonkey | Violentmonkey | Greasymonkey 4.0+ */
    function GMaddStyle(cssText) {
        let doc = document.head || document.documentElement;
        let tag = document.createElement('style');
        tag.textContent = cssText;
        doc.appendChild(tag);
    }

    //开启全屏的element调用,找到支持的方法
    function launchFullScreen(element) {
        if (element.requestFullscreen) {
            element.requestFullscreen();
        } else if (element.mozRequestFullScreen) {
            element.mozRequestFullScreen();
        } else if (element.webkitRequestFullscreen) {
            element.webkitRequestFullscreen();
        } else if (element.msRequestFullscreen) {
            element.msRequestFullscreen();
        }
    }

    //打开视频解析
    function openVideoResolve(evt) {
        if (evt.target.dataset.intab === '1') {
            //如果页面有播放窗口,只需更新播放窗口的 src, 如果没有播放窗口,读取播放窗口位置信息,新建一个播放窗
            let iframeTag = document.querySelector('#TMDFiframe');
            if (iframeTag === null) {
                let videoRect = JSON.parse(GMgetValue('videoRect', '{"left":"0","top":"0","width":"800","height":"600"}'));
                let divTag = document.createElement('div');
                divTag.id = 'TMDFVideoContainer';
                divTag.setAttribute('style', 'left:' + videoRect.left + ';top:' + videoRect.top + ';width:' + videoRect.width + ';height:' + videoRect.height + ';');
                divTag.innerHTML = '<button id="TMDFIframeClose" title="关闭">&#9746;</button><button id="TMDFFullScreen" title="全屏">&#10016;</button>';

                let iframeTag = document.createElement('iframe');
                iframeTag.id = 'TMDFiframe';
                iframeTag.src = evt.target.dataset.url + location.href;

                divTag.appendChild(iframeTag);
                document.body.appendChild(divTag);

                document.querySelector('#TMDFIframeClose').addEventListener('click', () => { document.body.removeChild(document.querySelector('#TMDFVideoContainer')); }, false);
                document.querySelector('#TMDFFullScreen').addEventListener('click', () => { launchFullScreen(document.querySelector('#TMDFiframe')); }, false);
            } else {
                iframeTag.src = evt.target.dataset.url + location.href;
            }
        } else {
            //不适合页内播放的,打开新标签
            window.open(evt.target.dataset.url + location.href);
        }
    }

    //保存视频设置
    function saveVideoSetting() {
        var videoRect = {
            left: document.querySelector('#TMDFpL').value,
            top: document.querySelector('#TMDFpT').value,
            width: document.querySelector('#TMDFpW').value,
            height: document.querySelector('#TMDFpH').value
        };

        GMsetValue('videoRect', JSON.stringify(videoRect));
    }

    //检查是否勾选页内解析
    function checkThisPageResolve() {
        let enablePageResolve = document.querySelector("#TMDFPageResolve").checked;
        GMsetValue("enablePageResolve", enablePageResolve);

        var x, arr = document.querySelectorAll('.TMDFul3 li');
        for (x = 0; x < arr.length; x++) {
            if (enablePageResolve) {
                arr[x].addEventListener('click', openVideoResolve, false);
                arr[x].setAttribute('onclick','');
            } else {
                arr[x].removeEventListener('click', openVideoResolve, false);
                arr[x].setAttribute('onclick', 'window.open(this.dataset.url + location.href)');
            }
        }
    }

    /* 正确选集 */
    function rightVideoEpisodes() {
        let enableVideoEpisodes = document.querySelector("#TMDFVideoEpisodes").checked;
        GMsetValue("enableVideoEpisodes", enableVideoEpisodes);

        function getLink(e) {
            var target = e.target.parentNode.tagName == "li" ? e.target.parentNode : (e.target.parentNode.parentNode.tagName == "li" ? e.target.parentNode.parentNode : e.target.parentNode.parentNode.parentNode);
            if (target.tagName != "li") return;

            GMxmlhttpRequest({
                method: 'GET',
                url: "http://cache.video.qiyi.com/jp/vi/" + target.dataset.videolistTvid + "/" + target.dataset.videolistVid + "/?callback=crackIqiyi",
                onload: function(result) {
                    var crackIqiyi = function(d) { location.href = d.vu; };
                    eval(result.responseText);
                }
            });
        }

        try {
            if (enableVideoEpisodes) {
                document.querySelector('#widget-dramaseries').addEventListener('click', getLink);
            } else {
                document.querySelector('#widget-dramaseries').removeEventListener('click', getLink);
            }
        } catch (e) {}
    }

    /*  显示增加接口的面板  */
    function showAddCustomApiPanel() {
        let apiPanel = document.querySelector('#TMDFCustomApi');
        if (apiPanel) {
            apiPanel.style.display = "block";
        } else {
            alert(`(● ̄(エ) ̄●)づ\n\n未启用[增加接口]功能\n请把 '▣增加接口'→'☑增加接口'!`);
        }
    }

    /* 勾选自定义接口 */
    function checkAddCustomApi() {
        let enableCustomApi = document.querySelector('#TMDFAddApi').checked;
        GMsetValue('enableCustomApi', enableCustomApi);
        if (enableCustomApi) {
            showCustomApiPanel();
            setTimeout(showAddCustomApiPanel, 200);
        }
    }

    /*  保存按钮执行函数:获取值并 await GM.setValue()  */
    function getCustomUserApis() {
        let userApis = document.querySelectorAll('.TMDFLink');
        let apiName = document.querySelector('#TMDFname').value;
        let apiUrl = document.querySelector('#TMDFurl').value;
        let apiIntab = document.querySelector('#TMDFintab').checked ? 1 : 0;
        let customUserApis = [];

        if (apiName || apiUrl) {
            customUserApis.push({ name: apiName, url: apiUrl, intab: apiIntab });
        }

        let n, u, l;
        for (let i = 0; i < userApis.length; i++) {
            u = userApis[i].innerText;
            n = userApis[i].previousSibling.innerText.split(':')[0];
            l = userApis[i].previousSibling.previousSibling.checked ? '1' : '0';
            customUserApis.push({ name: n, url: u, intab: l });
        }

        return customUserApis;
    }

    //生成"嵌入页面大小位置设置"面板
    function showVideoSettingPanel() {
        let videoRect = JSON.parse(GMgetValue('videoRect', '{"left":"0","top":"0","width":"800","height":"600"}'));
        let innerHtml = `
<button class="TMDFClose" onclick="document.body.removeChild(this.parentNode)">&#9746;</button>
<fieldset>
<legend>页内播放窗口位置大小</legend>
<li>
<label for="TMDFpL"><span class="TMDFspan80">左边距:</span><input type="text" id="TMDFpL" value="${videoRect.left}" class="TMDFtext2" placeholder='如"300px"或者"65%"'/></label>
<label for="TMDFpT"><span class="TMDFspan80">上边距:</span><input type="text" id="TMDFpT" value="${videoRect.top}" class="TMDFtext2" placeholder='如"300px"或者"65%"'/></label>
</li>
<li>
<label for="TMDFpW"><span class="TMDFspan80">宽度:</span><input type="text" id="TMDFpW" value="${videoRect.width}" class="TMDFtext2" placeholder='如"300px"或者"65%"'/></label>
<label for="TMDFpH"><span class="TMDFspan80">高度:</span><input type="text" id="TMDFpH" value="${videoRect.height}" class="TMDFtext2" placeholder='如"300px"或者"65%"'/></label>
</li>
</fieldset>
<li>
<button id="TMDFSettingCurrentView">获取当前播放窗尺寸</button>
<button id="TMDFSettingPreview">预览</button>
<button id="TMDFSettingSave">保存</button>
</li>`;

        let divTag = document.createElement('div');
        divTag.id = 'TMDFVideoSetting';
        divTag.setAttribute('class', 'TMDFp');
        divTag.innerHTML = innerHtml;
        document.body.appendChild(divTag);

        //添加事件
        document.querySelector('#TMDFSettingCurrentView').addEventListener('click', function() {
            let videoTag = document.querySelector('#TMDFVideoContainer');
            if (videoTag) {
                let videoStyle = getComputedStyle(videoTag)
                document.querySelector('#TMDFpL').value = videoStyle.left;
                document.querySelector('#TMDFpT').value = videoStyle.top;
                document.querySelector('#TMDFpW').value = videoStyle.width;
                document.querySelector('#TMDFpH').value = videoStyle.height;
            }
        }, false);

        document.querySelector('#TMDFSettingPreview').addEventListener('click', function() {
            let videoTag = document.querySelector('#TMDFVideoContainer');
            if (videoTag) {
                videoTag.style.cssText = ''
                videoTag.style.cssText += 'left:' + document.querySelector('#TMDFpL').value + ';';
                videoTag.style.cssText += 'top:' + document.querySelector('#TMDFpT').value + ';';
                videoTag.style.cssText += 'width:' + document.querySelector('#TMDFpW').value + ';';
                videoTag.style.cssText += 'height:' + document.querySelector('#TMDFpH').value + ';';
            }
        }, false);

        document.querySelector('#TMDFSettingSave').addEventListener('click', function() {
            saveVideoSetting();
            setTimeout(function() { document.body.removeChild(document.querySelector("#TMDFVideoSetting")); }, 30);
        }, false);
    }

    /*  生成增加接口面板  */
    function showCustomApiPanel() {
        let innerHtml = `
<button class="TMDFClose" onclick="document.querySelector('#TMDFCustomApi').style.display='none';">&#9746;</button>
<legend>添加解析接口</legend>
<li><span class="TMDFspan120">解析接口名称:</span><input type="text" id="TMDFname" class="TMDFtext1" placeholder="显示的名称"></li>
<li><span class="TMDFspan120">解析接口地址:</span><input type="text" id="TMDFurl" class="TMDFtext1" placeholder="接口需要包含 http 或者 https"></li>
<li><span class="TMDFspan120">解析内嵌本页:</span><label for="TMDFintab"><input type="checkbox" id="TMDFintab"/>适合</label></li>
<li class="TMDFli2">
<button id="TMDFTest">测试</button>
<button id="TMDFAdd">增加</button>
<button id="TMDFSave">保存</button>
</li>`;

        try {
            let customUserApis = JSON.parse(GMgetValue('customUserApis', "[{}]"));
            let checkStatus = '';
            if (customUserApis[0].name !== undefined) {
                for (let i = 0; i < customUserApis.length; i++) {
                    checkStatus = (customUserApis[i].intab === "1") ? 'checked' : '';
                    innerHtml += `<li><span class="TMDFDelete" title="删除" onclick="document.getElementById('TMDFCustomApi').removeChild(this.parentNode)">✘</span><input class="TMDFCheckbox" type="checkbox" ${checkStatus}><span class="TMDFName">${customUserApis[i].name}:</span><span class="TMDFLink">${customUserApis[i].url}</span></li>`;
                }
            }
        } catch (e) {}

        let divTag = document.createElement('div');
        divTag.id = 'TMDFCustomApi';
        divTag.setAttribute('class', 'TMDFp');
        divTag.setAttribute('style', 'display:none');
        divTag.innerHTML = innerHtml;
        document.body.appendChild(divTag);

        /*事件绑定*/
        document.querySelector('#TMDFTest').addEventListener('click', function() {
            let apiUrl = document.querySelector('#TMDFurl').value;
            if (apiUrl && apiUrl.match('^http')){
                window.open(apiUrl + location.href);
            }
            else{
                alert('测试无效,请先添加解析接口地址');
            }
        }, false);

        document.querySelector('#TMDFAdd').addEventListener('click', function() {
            if (document.querySelector('#TMDFname').value && document.querySelector('#TMDFurl').value) {
                let checkStatus = document.querySelector("#TMDFintab").checked ? "checked" : "";
                let liTag = document.createElement('li');
                liTag.innerHTML = `<span class="TMDFDelete" title="删除" onclick="document.getElementById('TMDFCustomApi').removeChild(this.parentNode)">✘</span><input class="TMDFCheckbox" type="checkbox" ${checkStatus}><span class="TMDFName">${document.querySelector('#TMDFname').value}:</span><span class="TMDFLink">${document.querySelector('#TMDFurl').value}</span>`;

                if (document.querySelector('span[class=TMDFName]') === null) {
                    document.querySelector('#TMDFCustomApi').appendChild(liTag);
                    document.querySelector('#TMDFname').value = '';
                    document.querySelector('#TMDFurl').value = '';
                } else {
                    document.querySelector('#TMDFCustomApi').insertBefore(liTag, document.querySelector('span[class=TMDFName]').parentNode);
                    document.querySelector('#TMDFname').value = '';
                    document.querySelector('#TMDFurl').value = '';
                }
            } else {
                alert('添加解析接口名称与地址不能为空,且符合规范');
            }
        }, false);

        document.querySelector('#TMDFSave').addEventListener('click', function() {
            var customUserApis = getCustomUserApis();
            GMsetValue('customUserApis', JSON.stringify(customUserApis));
            console.log(customUserApis);
            alert('解析接口列表已保存');
        }, false);
    }


    /*  显示解析界面 */
    function showResolveApiPanel() {
        /*提供的接口列表*/
        let apisText = ''
        for (let i in fixedApis) {
            apisText += `<li data-order=${i} data-url="${fixedApis[i].url}" data-intab=${fixedApis[i].intab} title="${fixedApis[i].title}" onclick="window.open(this.dataset.url+location.href)">${fixedApis[i].name}</li>`;
        }

        let innerHtml = `
<ul id="TMDFul">
<li class="TMDFli1"><span id="TMDFList" title="${defaultApi.title}" onclick="window.open(\'${defaultApi.url}\'+window.location.href)">▶</span>
<ul class="TMDFul2 TMDFul3">${apisText}</ul></li>
<li class="TMDFli1"><span id="TMDFSet">▣</span>
<ul class="TMDFul2">
<li><label><input type="checkbox" id="TMDFPageResolve" style="vertical-align: middle;">本页解析</label></li>
<li><label><input type="checkbox" id="TMDFVideoEpisodes" style="vertical-align: middle;">播放选集</label></li>
<li><input type="checkbox" id="TMDFAddApi" style="vertical-align: middle;"><label id="TMDFAddApiSettingBtn">增加接口</label></li>
<li><label id="TMDFVideoSettingBtn">播放设置</label></li>
</ul></li>
</ul>
`;

        let divTag = document.createElement("div");
        divTag.id = "TMDFResolveApi";
        divTag.innerHTML = innerHtml;
        document.body.appendChild(divTag);

        //事件绑定
        document.querySelector("#TMDFAddApi").addEventListener('change', checkAddCustomApi, false);

        let enableCustomApi = GMgetValue('enableCustomApi', false)
        document.querySelector("#TMDFAddApi").checked = enableCustomApi;
        /*看看是否需要加载自定义的接口列表*/
        if (enableCustomApi) {
            let customUserApis = JSON.parse(GMgetValue('customUserApis', "[{}]"));
            let innerHtml = '';
            for (let i in customUserApis) {
                try {
                    if (customUserApis[i].url !== null) {
                        innerHtml += `<li data-order=${i} data-url="${customUserApis[i].url}"  data-intab=${customUserApis[i].intab} onclick="window.open(this.dataset.url+location.href)">${customUserApis[i].name}</li>`;
                    }
                } catch (e) { /*console.log(e);*/ }
            }

            document.querySelector('ul.TMDFul2.TMDFul3').innerHTML = innerHtml + document.querySelector('ul.TMDFul2.TMDFul3').innerHTML;
            showCustomApiPanel();
        }

        //本页解析
        document.querySelector("#TMDFPageResolve").addEventListener("click", checkThisPageResolve, false);
        let enablePageResolve = GMgetValue('enablePageResolve', false);
        document.querySelector("#TMDFPageResolve").checked = enablePageResolve;
        if (enablePageResolve) {
            checkThisPageResolve();
        }

        //正确选集
        document.querySelector("#TMDFVideoEpisodes").addEventListener("click", rightVideoEpisodes, false);
        let enableVideoEpisodes = GMgetValue('enableVideoEpisodes', false);
        document.querySelector("#TMDFVideoEpisodes").checked = enableVideoEpisodes;
        if (enableVideoEpisodes && location.href.indexOf("iqiyi") != -1) {
            rightVideoEpisodes();
        }

        //添加接口
        document.querySelector("#TMDFAddApiSettingBtn").addEventListener('click', showAddCustomApiPanel, false);

        //播放设置
        document.querySelector("#TMDFVideoSettingBtn").addEventListener('click', showVideoSettingPanel, false);
    }


    /*  执行  */
    function execute() {
        //添加css
        GMaddStyle(cssStyle);

        //显示界面
        showResolveApiPanel();
    }

    //调用执行
    execute();
})();