粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网去视频内嵌广告

去除粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网视频里的嵌入的广告

目前為 2024-06-03 提交的版本,檢視 最新版本

// ==UserScript==
// @name         粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网去视频内嵌广告
// @name:zh-CN   粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网去视频内嵌广告
// @name:zh-TW   粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网去视频内嵌广告
// @name:zh-HK   粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网去视频内嵌广告
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      3.0.0
// @description  去除粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网视频里嵌入的广告
// @description:zh-CN 去除粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网视频里的嵌入的广告
// @description:zh-TW 去除粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网视频里的嵌入的广告
// @description:zh-HK 去除粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网视频里的嵌入的广告
// @author       hua
// @grant        unsafeWindow
// @license      MIT
// @include      https://m3u8.yueyuwu.cc/player/*
// @include      https://xbyy.app/player/*
// @include      https://kandaju.net/js/player/*
// @include      https://ffzyplayer.com/*
// @include      https://api.yktvb.com/dplayer.html*
// @run-at       document-start
// ==/UserScript==

//粤语屋 小宝影院 看剧吧 剧集屋 爱看港剧网




(function () {
    let href = document.location.href;
    const page_type = get_page_type();
    const origin_console = console;
    const log = origin_console.log;
    if (page_type === 'unknown') {
        log('unknown page type');
        return;
    }
    const process_api = get_m3u8_process_api();
    const config_infos = {
        'yyw': {
            'm3u8_file_flag': /mixed\.m3u8$/,
            'process_method': process_api.common
        },
        'xbyy': {
            'm3u8_file_flag': /\.m3u8$/,
            'process_method': process_api.common
        },
        "kjb": {
            'm3u8_file_flag': /mixed\.m3u8$/,
            'process_method': process_api.common
        },
        "jjw": {
            'm3u8_file_flag': /mixed\.m3u8$/,
            'process_method': process_api.common
        },
        "akgjw": {
            'm3u8_file_flag': /mixed\.m3u8$/,
            'process_method': process_api.common
        }
    };
    let config_info = config_infos[page_type];
    init_hook();
    log('脚本注入成功!');

    function init_hook() {
        unsafeWindow.XMLHttpRequest = class extends unsafeWindow.XMLHttpRequest {
            get xhrResponseValue() {
                const xhr = this;
                if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) {
                    const url = xhr.responseURL;
                    if (url.match(config_info.m3u8_file_flag)) {
                        try {
                            return config_info.process_method(super.response);
                        } catch (error) {
                            log('m3u8处理异常!', error);
                        }
                    }
                }
                return super.response;
            }
            get responseText() {
                return this.xhrResponseValue;
            }
            get response() {
                return this.xhrResponseValue;
            }
        };
    }

    function get_page_type() {
        if (href.includes('m3u8.yueyuwu.cc'))
            return 'yyw';
        else if (href.includes('xbyy.app'))
            return 'xbyy';
        else if (href.includes('kandaju.net'))
            return 'kjb';
        else if (href.includes('ffzyplayer.com'))
            return 'jjw';
        else if (href.includes('api.yktvb.com'))
            return 'akgjw';
        else
            return 'unknown';
    }

    function get_m3u8_process_api() {
        return {
            xbyy: function (file) {
                let lines = file.split('\n');
                let processed_lines = [];
                let pre_name;
                for (let line of lines) {
                    if (line.endsWith('.ts')) {
                        pre_name = line.match(/^.*\//)[0];
                        break;
                    }
                }
                for (let line of lines) {
                    if (line.endsWith('.ts')) {
                        if (!line.startsWith(pre_name)) {
                            processed_lines.pop();
                            if (processed_lines[processed_lines.length - 1] == '#EXT-X-DISCONTINUITY') {
                                processed_lines.pop();
                            }
                            log('删除', line);
                            continue;
                        }
                    }
                    processed_lines.push(line);
                }
                return processed_lines.join('\n');
            },
            common: function (file) {
                let lines = file.split('\n');
                let processed_lines = [];
                let index = 0;
                let name_len;
                let pre_name;
                let next_name;
                for (let line of lines) {
                    if (line.endsWith('.ts')) {
                        if (!next_name) {
                            pre_name = line.split('.ts')[0];
                            name_len = pre_name.length;
                            index++;
                            const str_index = String(index);
                            next_name = `${pre_name.substring(0, name_len - str_index.length)}${str_index}.ts`;
                        } else {
                            if (next_name != line) {
                                processed_lines.pop();
                                if (processed_lines[processed_lines.length - 1] == '#EXT-X-DISCONTINUITY') {
                                    processed_lines.pop();
                                }
                                console.log(`删除${line}`);
                                continue;
                            } else {
                                index++;
                                const str_index = String(index);
                                next_name = `${pre_name.substring(0, name_len - str_index.length)}${str_index}.ts`;
                            }
                        }
                    }
                    processed_lines.push(line);
                }
                let processed_file = processed_lines.join('\n');
                return processed_file;
            }
        };
    }
})();