Remove Carousel on twitch.tv home page

Removes the annoying carousel on the twitch.tv homepage

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Remove Carousel on twitch.tv home page
// @namespace    KrümelKing
// @version      1.0
// @description  Removes the annoying carousel on the twitch.tv homepage
// @author       https://linktr.ee/kruemelking
// @match        https://www.twitch.tv/
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
//Check for homepage
    if (window.location.pathname !== '/') {
        return;
    }

    function aggressivelyRemoveCarouselAndAudio() {
        const carousel = document.querySelector('.front-page-carousel');
        if (carousel) {
            carousel.style.display = 'none';
//Disables all video and audio elements on startpage if found
            function disableMediaElements(element) {
                if (element.tagName === 'VIDEO' || element.tagName === 'AUDIO') {
                    element.muted = true;
                    element.volume = 0;
                    element.removeAttribute('src');
                    element.load();
                    element.pause();
                    element.style.display = 'none';
                }
                for (let child of element.children) {
                    disableMediaElements(child);
                }
            }

            disableMediaElements(carousel);
//Overwrite play method
            carousel.querySelectorAll('video, audio').forEach(mediaElement => {
                mediaElement.play = function() {
                    this.pause();
                    return new Promise(() => {});
                };
            });
        }
    }
//creates observer
    const observer = new MutationObserver((mutations) => {
        for (let mutation of mutations) {
            if (mutation.addedNodes.length) {
                aggressivelyRemoveCarouselAndAudio();
            }
        }
    });
//Observer checks for changes
    const config = { childList: true, subtree: true };
//Immediate execution so no short noise
    function immediateAndRepeatedExecution() {
        aggressivelyRemoveCarouselAndAudio();
        observer.observe(document.body, config);
//Sometimes it reloads so do it multiple times
        for (let i = 1; i <= 5; i++) {
            setTimeout(aggressivelyRemoveCarouselAndAudio, i * 100);
        }
    }
//yeah do it a lot
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', immediateAndRepeatedExecution);
    } else {
        immediateAndRepeatedExecution();
    }
//and on load
    window.addEventListener('load', aggressivelyRemoveCarouselAndAudio);
})();