TeleParty Addon

Nuke the TeleParty chat and all the other TeleParty crap, all while keeping TeleParty enabled and working :)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         TeleParty Addon
// @namespace    http://tampermonkey.net/
// @version      1.0
// @license      MIT
// @description  Nuke the TeleParty chat and all the other TeleParty crap, all while keeping TeleParty enabled and working :)
// @author       CandiceJoy
// @match        http*://hulu.com/*
// @match        http*://*.netflix.com/*
// @match        http*://*.disneyplus.com/*
// @match        http*://play.hbomax.com/*
// @match        http*://*.amazon.com/*/video/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=teleparty.com
// @require      https://code.jquery.com/jquery-3.6.0.min.js
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const header = "[Candi Teleparty]";

    function log(msg,obj=null)
    {
        console.log( header + " " + msg );
    }

    let tpActive = false;
    let findPlayer;

    if( window.location.href.match( /netflix\.com/ig ) )
    {
        log("Netflix detected");
        findPlayer = function(){return document.querySelector(".watch-video--player-view");};
    }
    else if( window.location.href.match( /hulu\.com/ig ) )
    {
        log("Hulu detected");
        findPlayer = function(){return document.querySelector("#dash-player-container");};
    }
    else if( window.location.href.match( /disneyplus\.com/ig ) )
    {
        log("Disney+ detected");
        findPlayer = function(){return document.querySelector("#hudson-wrapper");};
    }
    else if( window.location.href.match( /hbomax\.com/ig ) )
    {
        log("HBO Max detected");
        findPlayer = function(){return null;};
    }
    else if( window.location.href.match( /amazon\.com/ig ) )
    {
        log("Amazon Prime detected");
        findPlayer = function(){return document.querySelector(".webPlayerSDKContainer");};
    }
    else
    {
        log("Streaming service not supported");
    }

    function callback(mutations,observer)
    {
        if( window.location.href.match( /hbomax/ig ) )
        {
            const area = document.querySelector("div.default");

            if( area )
            {
                const size = area.style.width;
                const player = document.querySelector(".tp-video");

                if( player )
                {
                    log("Resizing video");
                    player.style.width = size;
                }
            }
        }
        else
        {
            const player = findPlayer();

            if( player && player.classList.contains("with-chat") )
            {
                log("Resizing video");
                player.classList.remove("with-chat");
            }
        }

        if( !tpActive )
        {
            for(const mutation of mutations)
            {
                const target = mutation.target;
                const classes = mutation.target.classList;

                if( classes.contains("PlayerMetadata__subTitle") || classes.contains("ControlsContainer__transition") )
                {
                    continue;
                }

                //console.log("Mutated ",target);

                if( target.querySelector("#tpIconContainer") || target.querySelector("#chat-wrapper") )
                {
                    log("Detected Teleparty");
                    tpActive = true;
                    break;
                }
            }
        }

        if( !tpActive )
        {
            return;
        }

        const popup = document.querySelector("#tpIconContainer");

        if( popup )
        {
            log("Removing popup");
            popup.remove();
        }

        const chat = document.querySelector("#chat-wrapper");

        if( chat )
        {
            log("Removing chat");
            chat.remove();
        }

        if( !popup && !chat )
        {
            //observer.disconnect();
            log("Teleparty no longer detected");
            tpActive = false;
        }
    }

    log("Enabling observer");
    const targetNode = document.getElementsByTagName("body")[0];
    const config = { attributes: true, childList: true, subtree: true };
    const observer = new MutationObserver(callback);
    observer.observe(targetNode, config);
    //observer.disconnect();
})();