Greasy Fork

Greasy Fork is available in English.

抖音一键清屏

//抖音一键清屏

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         抖音一键清屏
// @namespace    http://tampermonkey.net/
// @version      3.1
// @description  //抖音一键清屏
// @author       梦呓萤殇
// @match        https://www.douyin.com/
// @icon         https://lf1-cdn-tos.bytegoofy.com/goofy/ies/douyin_web/public/favicon.ico
// @grant        none
// ==/UserScript==

(function() {
    var qingping = document.getElementsByClassName('xg-switch');
    var wei = "xg-switch"; // 未清屏状态
    var wei1 = "xg-switch xg-switch-checked"; // 清屏状态
    var isCleared = false;
    var lastClearTime = 0;
    var minClearInterval = 1000; // 最小清屏间隔时间(毫秒)

    // 添加监听器以检测页面变化
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            var currentTime = Date.now();
            if (currentTime - lastClearTime >= minClearInterval) {
                clearScreen();
                lastClearTime = currentTime;
            }
        });
    });

    // 开始监听 DOM 变化
    observer.observe(document.body, { childList: true, subtree: true });

    function clearScreen() {
        try {
            if (qingping.length > 0 && qingping[0].className == wei) {
                qingping[0].click();
                console.log("清屏了");
                isCleared = true;
            } else if (qingping.length > 0 && qingping[0].className == wei1) {
                if (isCleared) {
                    console.log("已清屏");
                    isCleared = false;
                }
            }
        } catch (error) {
            console.error("清屏操作时出现错误:", error);
        }
    }
})();