Last active
November 25, 2022 15:34
-
-
Save eai04191/dbb24432b921bd7870a25432115b5916 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async () => { | |
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
const strings = { | |
subtitle: "字幕", | |
english: "英語", | |
targetLanguage: "日本語", | |
machineTranslation: "自動翻訳", | |
}; | |
const settingsButton = document.querySelector(".ytp-settings-button"); | |
const findMenuItem = (text) => { | |
const menuItems = [...document.querySelectorAll(".ytp-menuitem")]; | |
return menuItems.find((item) => item.innerText.includes(text)); | |
}; | |
try { | |
// open | |
settingsButton.click(); | |
await wait(100); | |
// close | |
settingsButton.click(); | |
await wait(100); | |
findMenuItem(strings.subtitle).click(); | |
await wait(500); | |
// if target language is provided? choose it | |
if (findMenuItem(strings.targetLanguage)) { | |
findMenuItem(strings.targetLanguage).click(); | |
return; | |
} | |
// choose english and machine translation | |
findMenuItem(strings.english).click(); | |
await wait(2000); | |
findMenuItem(strings.subtitle).click(); | |
await wait(100); | |
findMenuItem(strings.machineTranslation).click(); | |
await wait(500); | |
findMenuItem(strings.targetLanguage).click(); | |
} catch (error) { | |
console.error(error); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment