含羞草

含羞草-解析脚本

Verze ze dne 08. 07. 2023. Zobrazit nejnovější verzi.

// ==UserScript==
// @name         含羞草
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  含羞草-解析脚本
// @author       院长
// @match       *://*.fi11av29.com/*
// @match       *://*.fi11tv29.com/*
// @match       *://*.网站域名/*
// @match       *://*.失效后自行替换域名,如上面的fi11av29.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=3kjs.com
// @grant        none
// @require      https://cdn.bootcdn.net/ajax/libs/crypto-js/4.1.1/crypto-js.min.js
// @require      https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.min.js
// ==/UserScript==

//若是脚本网址失效,请在在上方的@match标签,自行在替换网址,附上一个导航http://www.Fi11.tv
//遇到播放地址为旧播放地址,请自行刷新当前页面,重新播放即可


/**********************************/
/*
含羞草-解析脚本
参考来源https://yaohuo.me/bbs-1210512.html

实现游客无限试用,无限获取真实播放地址

已兼容手机和电脑

*/
/**********************************/
(function() {
    'use strict';
    // 权限认证标识
    const TOKEN = 'hxc_1.0.0_token';
    // 服务地址
    let baseUrl = location.origin;
    // 视频试看地址
    const PRE_URL = baseUrl + '/api/videos/getPreUrl';
    // 用户注册地址
    const REG_URL = baseUrl + '/api/login/userReg';




    // 参数加密
    function Encrypt(word) {
        let keyStr = 'B77A9FF7F323B5404902102257503C2F';
        const key = CryptoJS.enc.Utf8.parse(keyStr);
        const iv = CryptoJS.enc.Utf8.parse(keyStr);
        const srcs = CryptoJS.enc.Utf8.parse(word);
        const encrypted = CryptoJS.AES.encrypt(srcs, key, {
            iv: iv,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        });
        return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
    }

    // 请求封装
    const fetchData = (url, body) => {
        return fetch(url, {
            method: 'post',
            body: JSON.stringify({
                endata: Encrypt(JSON.stringify(body))
            }),
            headers: {
                // 携带认证头
                auth: localStorage.getItem(TOKEN)?.replace(/"/g, ''),
                'Content-Type': 'application/json'
            }
        });
    };




    /**********************************/
    // hook: 拦截路由地址变化
    const _historyWrap = function (type) {
        const orig = history[type];
        const e = new Event(type);
        return function () {
            const rv = orig.apply(this, arguments);
            e.arguments = arguments;
            window.dispatchEvent(e);
            return rv;
        };
    };
    // 监听路由操作
    ['pushState', 'replaceState'].forEach(method => {
        history[method] = _historyWrap(method);
        window.addEventListener(method, () => {
            setValue();
        });
    });

    window.addEventListener('popstate', function(event) {
        console.log('当前URL为:', document.location.href);
        setValue();
    });

    /**********************************/



    // 去除限制
    const setValue = () => {
        let isDetail = location.href.includes('play/video');


        if (isDetail) {
            //判断是h5还是电脑
            let videoId = location.href.match(/.+\/h5\..+\/play\/video\/(\d+)\/.+/);
            console.log(videoId)
            if(!videoId){
                videoId = location.href.match(/.+\/play\/video\/(\d+)/)[1];


                //电脑
                console.log("电脑")
                var preInfo = localStorage.getItem("preInfo");
                if(preInfo){
                    preInfo = JSON.parse(preInfo)
                    preInfo.count = 0;
                    preInfo = JSON.stringify(preInfo)
                    localStorage.setItem("preInfo", preInfo);
                }


                //先删除按键
                let delete_el = document.querySelector('.el-divider.el-divider--horizontal');
                if(delete_el){
                    delete_el.remove();
                }
                fetchData(PRE_URL, {
                    videoId: Number(videoId)
                }).then(response => {
                    response.json().then(json => {
                        const isSuccess = !!json.data.url;
                        var el = document.querySelector('.el-divider.el-divider--horizontal');
                        let a = document.createElement('a');
                        a.style =
                            'display:block;font-size:18px;padding:12px;color:#1890ff;';
                        a.text = isSuccess ? '视频地址' : '获取失败';
                        a.target = "_blank";
                        if (isSuccess) {
                            let parseUrl = json.data.url.replace(/start=\d+&end=\d+/, '');
                            a.href = parseUrl;
                            // 获取ts切片
                            fetch(parseUrl).then(async res => {
                                let m3u8Str = await res.text();
                                // 提取第一条记录
                                let tsUrl = m3u8Str.split('\n').find(item => {
                                    return /^[^#]/.test(item);
                                });
                                // 拼接
                                const linkUrl =
                                      'https://m3u8play.com/?play=' +
                                      new URL(parseUrl).origin +
                                      tsUrl;
                                let external = document.createElement('a');
                                external.style =
                                    'display:block;font-size:18px;padding:12px;color:#1890ff;';
                                external.text = '外部播放';
                                external.href = linkUrl;
                                external.target = "_blank";
                                el.parentNode.insertBefore(external, el);
                            });
                        }
                        el.parentNode.insertBefore(a, el);
                    });
                });


            }else{
                //手机
                console.log("手机")
                videoId = videoId[1];
                var tryPlayNum = localStorage.getItem("tryPlayNum");
                if(tryPlayNum){
                    tryPlayNum = JSON.parse(tryPlayNum)
                    tryPlayNum.num = 0;
                    tryPlayNum = JSON.stringify(tryPlayNum)
                    localStorage.setItem("tryPlayNum", tryPlayNum);
                }

                //先删除按键
                let delete_el = document.querySelector('.tendency-row');
                if(delete_el){
                    delete_el.remove();
                }
                fetchData(PRE_URL, {
                    videoId: Number(videoId)
                }).then(response => {
                    response.json().then(json => {
                        const isSuccess = !!json.data.url;
                        var el = document.querySelector('.tendency-row');
                        let a = document.createElement('a');
                        a.style =
                            'display:block;font-size:18px;padding:12px;color:#1890ff;';
                        a.text = isSuccess ? '视频地址' : '获取失败';
                        a.target = "_blank";
                        if (isSuccess) {
                            let parseUrl = json.data.url.replace(/start=\d+&end=\d+/, '');
                            a.href = parseUrl;
                            // 获取ts切片
                            fetch(parseUrl).then(async res => {
                                let m3u8Str = await res.text();
                                // 提取第一条记录
                                let tsUrl = m3u8Str.split('\n').find(item => {
                                    return /^[^#]/.test(item);
                                });
                                // 拼接
                                const linkUrl =
                                      'https://m3u8play.com/?play=' +
                                      new URL(parseUrl).origin +
                                      tsUrl;
                                let external = document.createElement('a');
                                external.style =
                                    'display:block;font-size:18px;padding:12px;color:#1890ff;';
                                external.text = '外部播放';
                                external.href = linkUrl;
                                external.target = "_blank";
                                el.parentNode.insertBefore(external, el);
                            });
                        }
                        el.parentNode.insertBefore(a, el);
                    });
                });
            }

            console.log(videoId)
            var videoId_File = localStorage.getItem("videoId");
            //console.log("===========================")
            if(videoId_File && videoId_File === videoId){
                //console.log("----------------------------")
                return
            }
            localStorage.setItem("videoId", videoId);
        }


    }



})();