Skip to content

Instantly share code, notes, and snippets.

@mohemohe
Created October 21, 2023 19:07
Show Gist options
  • Save mohemohe/ae53ef515a28eae5213b3d69160c663a to your computer and use it in GitHub Desktop.
Save mohemohe/ae53ef515a28eae5213b3d69160c663a to your computer and use it in GitHub Desktop.
Enhancer for YouTube 日本語字幕
(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