抖音直播间净化

抖音直播界面美化, 去除大部分非直播相关元素.

目前为 2023-08-24 提交的版本。查看 最新版本

// ==UserScript==
// @name		抖音直播间净化
// @description		抖音直播界面美化, 去除大部分非直播相关元素. 
// @version		1.0.3
// @author		Yiero
// @match		https://live.douyin.com/*
// @icon		https://live.douyin.com/favicon.ico
// @namespace		https://github.com/AliubYiero/TamperMonkeyScripts/
// @license		GPL
// @run-at		document-start
// @grant		GM_addStyle
// ==/UserScript==
var __defProp = Object.defineProperty;

var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
    enumerable: true,
    configurable: true,
    writable: true,
    value: value
}) : obj[key] = value;

var __publicField = (obj, key, value) => {
    __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
    return value;
};

class Info {
    constructor(projectName) {
        __publicField(this, "projectName");
        __publicField(this, "header");
        this.projectName = projectName;
        this.header = `[${projectName}]`;
    }
    log(...msg) {
        (() => {})(...this.contentInfo(...msg));
    }
    info(...msg) {
        console.info(...this.contentInfo(...msg));
    }
    warn(...msg) {
        console.warn(...this.contentInfo(...msg));
    }
    error(...msg) {
        console.error(...this.contentInfo(...msg));
    }
    contentInfo(...msg) {
        return [ this.header, `[${(new Date).toLocaleString("zh-ch")}]`, ...msg ];
    }
}

class AddStyle {
    constructor() {
        __publicField(this, "cssRuleSet", new Set);
        __publicField(this, "styleDom", document.createElement("style"));
    }
    push(selector, rule) {
        let ruleString = "";
        for (let ruleKey in rule) {
            const ruleValue = rule[ruleKey];
            ruleString += `${ruleKey}:${ruleValue};`;
        }
        this.cssRuleSet.add(`${selector} {${ruleString}}`);
    }
    pushImportant(selector, rule) {
        let ruleString = "";
        for (let ruleKey in rule) {
            let ruleValue = rule[ruleKey];
            if (typeof ruleValue === "string") {
                ruleValue = ruleValue.replace("!important", "");
            }
            ruleString += `${ruleKey}:${ruleValue} !important;`;
        }
        this.cssRuleSet.add(`${selector} {${ruleString}}`);
    }
    pushHide(selector) {
        this.pushImportant(selector, {
            display: "none"
        });
    }
    pushList(ruleList) {
        ruleList.forEach((({selector: selector, rule: rule}) => {
            this.push(selector, rule);
        }));
    }
    submit() {
        this.removeAll();
        new Info("AddStyle").log(Array.from(this.cssRuleSet).join(" "));
        this.styleDom = GM_addStyle(Array.from(this.cssRuleSet).join(" "));
    }
    removeAll() {
        if (this.styleDom) {
            this.styleDom.remove();
        }
    }
}

function douyinAddNewStyle() {
    const CSSRule = new AddStyle;
    CSSRule.pushHide(".hide-element");
    CSSRule.pushHide(".N_HNXA04");
    CSSRule.pushHide(".CPQ46DEr");
    CSSRule.pushHide(".mNaEBJlG");
    CSSRule.pushHide(".s49a85m9 > button:nth-of-type(n + 2)");
    CSSRule.pushHide(".AbLfr3ao");
    CSSRule.pushHide(".f64hQYrh");
    CSSRule.pushImportant("#_douyin_live_scroll_container_ > div, .UKFpY5tW.H9SQ3Q3i.dpbdzIVu, .SxCiQ8ip.H9SQ3Q3i.jY7kuyKe", {
        height: "100%"
    });
    CSSRule.pushHide(".is-theater .tgMCqIjJ");
    CSSRule.pushImportant(".is-theater > .EDvjMGPs.FKQqfehj", {
        height: "100%"
    });
    CSSRule.pushHide(".nex5gRxd");
    CSSRule.pushHide(".webcast-chatroom___bottom-message");
    CSSRule.pushHide(".OAJeuZUg");
    CSSRule.pushHide(".OkoVu3vW");
    CSSRule.pushHide(".douyin-sidebar, .G0S7YWl4");
    CSSRule.submit();
}

function isMatchURL(regExp) {
    return !!document.URL.match(regExp);
}

(() => {
    if (!isMatchURL(/^https:\/\/live.douyin.com\/\d+/)) {
        return;
    }
    douyinAddNewStyle();
})();