屏蔽html5播放器p2p上传

屏蔽html5播放器使用WebRTC技术进行p2p上传,以及防止通过p2p泄露ip,如斗鱼直播后台上传等。需要注意默认屏蔽所有网站html5的p2p功能,需要使用p2p的网站请自行加入排除列表,如网易uu语音、twitch等。嫌麻烦的请勿用。

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==UserScript==
// @name         屏蔽html5播放器p2p上传
// @version      0.1.4
// @description  屏蔽html5播放器使用WebRTC技术进行p2p上传,以及防止通过p2p泄露ip,如斗鱼直播后台上传等。需要注意默认屏蔽所有网站html5的p2p功能,需要使用p2p的网站请自行加入排除列表,如网易uu语音、twitch等。嫌麻烦的请勿用。
// @author       binsee
// @namespace    https://github.com/binsee/tampermonkey-scripts
// @supportURL   https://github.com/binsee/tampermonkey-scripts/issues
// @license      GPL
// @run-at       document-start
// @match        *://*.douyu.com/*
// @match        *://*.qq.com/*
// @match        *://*.huya.com/*
// @match        *://*/*
// @exclude      *://*.bilibili.com/*
// @exclude      *://*.discord.com/*
// @exclude      *://*.twitch.tv/*
// @exclude      *://*.ext-twitch.tv/*
// @grant        none
// ==/UserScript==
let HookFlag = false

let debugFlag = true
let jsName = '屏蔽html5播放器p2p上传'
let logger = {
    debug: createDebugMethod('debug'),
    info: createDebugMethod('info'),
    warn: createDebugMethod('warn'),
    error: createDebugMethod('error')
};

function createDebugMethod(name) {
    const bgColorMap = {
        debug: '#0070BB',
        info: '#009966',
        warn: '#BBBB23',
        error: '#bc0004'
    };
    name = bgColorMap[name] ? name : 'info';
    return function () {
        const args = Array.from(arguments);
        args.unshift(`color: white; background-color: ${bgColorMap[name] || '#FFFFFF'}`);
        args.unshift(`【${jsName}】 %c[${name.toUpperCase()}]:`);
        console[name].apply(console, args);
    }
}


(function () {
    'use strict';
    let funNameList = [
        'RTCPeerConnection',
        'webkitRTCPeerConnection',
        'mozRTCPeerConnection',
        'msRTCPeerConnectio',
    ]
    funNameList.forEach(name => {
        if (typeof window._RTCPeerConnection === "undefined") window._RTCPeerConnection = window[name];
        if (typeof window[name] !== "undefined") window[name] = debugFlag ? MyPeerConnection : undefined;
    })
    logger.info('已屏蔽p2p上传功能')

    function MyPeerConnection(args) {
        logger.debug(`PeerConnection() 被调用!
当前页面尝试建立p2p连接!
调用参数: ${JSON.stringify(args)}`)
        return HookFlag ? new window._RTCPeerConnection(args) : undefined
    }
})();