Youtube自动切中文

Youtube-自动切中文

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name                Youtube自动切中文
// @namespace           HeyTang
// @version             0.1.3
// @description         Youtube-自动切中文
// @author              只是条咸鱼罢了
// @match               *://*.youtube.com/watch?*
// ==/UserScript==

async function test() {
    if (document.querySelector(".ytp-subtitles-button").getAttribute("style")!="display: none;") {
        if (document.querySelector(".ytp-subtitles-button").getAttribute("aria-pressed") == "false") {
            document.querySelector(".ytp-subtitles-button").click()
        }
        document.querySelector(".ytp-settings-button").click()
        document.querySelector(".ytp-settings-menu .ytp-panel .ytp-panel-menu > div:nth-last-child(2)").click()
        await sleep(500)
        document.querySelector(".ytp-settings-menu .ytp-panel .ytp-panel-menu > div:nth-last-child(1)").click()
        await sleep(500)
        document.querySelector(".ytp-settings-menu .ytp-panel .ytp-panel-menu > div:nth-last-child(2)").click()
    }

}

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms))
}

test()