Created
October 21, 2023 19:07
-
-
Save mohemohe/ae53ef515a28eae5213b3d69160c663a to your computer and use it in GitHub Desktop.
Enhancer for YouTube 日本語字幕
This file contains 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 waitAsync = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); | |
document.querySelector(".ytp-settings-button").click(); | |
await waitAsync(500); | |
let items = document.querySelectorAll(".ytp-settings-menu .ytp-menuitem-label"); | |
let ok = false; | |
for (const item of Array.from(items)) { | |
if (item.innerText.includes("字幕")) { | |
ok = true; | |
item.click(); | |
} | |
} | |
if (!ok) { | |
return; | |
} | |
await waitAsync(500); | |
items = document.querySelectorAll(".ytp-settings-menu .ytp-menuitem-label"); | |
ok = false; | |
for (const item of Array.from(items)) { | |
if (item.innerText === "オフ") { | |
ok = true; | |
item.click(); | |
} | |
} | |
if (!ok) { | |
return; | |
} | |
items = document.querySelectorAll(".ytp-settings-menu .ytp-menuitem-label"); | |
ok = false; | |
for (const item of Array.from(items)) { | |
if (item.innerText.includes("字幕")) { | |
ok = true; | |
item.click(); | |
} | |
} | |
if (!ok) { | |
return; | |
} | |
await waitAsync(500); | |
items = document.querySelectorAll(".ytp-settings-menu .ytp-menuitem-label"); | |
ok = false; | |
for (const item of Array.from(items)) { | |
if (item.innerText.includes("日本語")) { | |
ok = true; | |
item.click(); | |
return; | |
} | |
} | |
if (!ok) { | |
for (const item of Array.from(items)) { | |
if (item.innerText.includes("英語")) { | |
ok = true; | |
item.click(); | |
} | |
} | |
} | |
if (!ok) { | |
return; | |
} | |
await waitAsync(500); | |
items = document.querySelectorAll(".ytp-settings-menu .ytp-menuitem-label"); | |
ok = false; | |
for (const item of Array.from(items)) { | |
if (item.innerText.includes("字幕")) { | |
ok = true; | |
item.click(); | |
} | |
} | |
if (!ok) { | |
return; | |
} | |
await waitAsync(500); | |
items = document.querySelectorAll(".ytp-settings-menu .ytp-menuitem-label"); | |
ok = false; | |
for (const item of Array.from(items)) { | |
if (item.innerText.includes("自動翻訳")) { | |
ok = true; | |
item.click(); | |
} | |
} | |
if (!ok) { | |
return; | |
} | |
await waitAsync(500); | |
items = document.querySelectorAll(".ytp-settings-menu .ytp-menuitem-label"); | |
ok = false; | |
for (const item of Array.from(items)) { | |
if (item.innerText.includes("日本語")) { | |
ok = true; | |
item.click(); | |
} | |
} | |
if (!ok) { | |
return; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment