您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Hides chat on YouTube live streams by default
当前为
- // ==UserScript==
- // @name YouTube Hide Chat by Default
- // @namespace https://skoshy.com
- // @version 0.2.3
- // @description Hides chat on YouTube live streams by default
- // @author Stefan K.
- // @match https://*.youtube.com/*
- // @grant none
- // @icon https://youtube.com/favicon.ico
- // ==/UserScript==
- (function() {
- "use strict";
- const scriptId = "youtube-hide-chat-by-default";
- const buttonSelector = "paper-button";
- function log(...toLog) {
- console.log(`[${scriptId}]:`, ...toLog);
- }
- function setAndGetNodeId(node) {
- const nodeIdString = `${scriptId}-id`;
- let nodeId = node.getAttribute(nodeIdString);
- let hadNodeIdSet = true;
- // log("new node found", { nodeId, hadNodeIdSet, node });
- if (!nodeId) {
- hadNodeIdSet = false;
- nodeId = Math.random().toString();
- node.setAttribute(nodeIdString, nodeId);
- }
- return { nodeId, hadNodeIdSet };
- }
- function addedNodeHandler(node) {
- if (!node.matches || !node.matches(buttonSelector)) {
- return;
- }
- const { nodeId, hadNodeIdSet } = setAndGetNodeId(node);
- if (!hadNodeIdSet) {
- // this is a new element
- if (node.innerText.toUpperCase().trim() === "HIDE CHAT") {
- node.click();
- log(`Hid the chat by default`);
- }
- }
- }
- const bodyObserver = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- mutation.addedNodes.forEach(addedNode => {
- addedNodeHandler(addedNode);
- // it might be text node or comment node which don't have querySelectorAll
- addedNode.querySelectorAll &&
- addedNode.querySelectorAll(buttonSelector).forEach(addedNodeHandler);
- });
- });
- });
- bodyObserver.observe(document.body, {
- attributes: true,
- childList: true,
- subtree: true,
- characterData: true
- });
- })();