YouTube - Limit Subtitle Languages

Restrict YouTube subtitle language menu to only the target language.

  1. // ==UserScript==
  2. // @name YouTube - Limit Subtitle Languages
  3. // @description Restrict YouTube subtitle language menu to only the target language.
  4. // @version 0.2
  5. // @author to
  6. // @namespace https://github.com/to
  7. // @license MIT
  8. //
  9. //
  10. // @noframes
  11. // @match https://www.youtube.com/watch*
  12. // @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. // チェック対象の言語
  17. const TARGET_LANGUAGE = "日本語";
  18.  
  19. // プレーヤーを監視する
  20. function observePlayer() {
  21. // 変更を監視する
  22. const player = document.querySelector('.html5-video-player');
  23. const observer = new MutationObserver(() => {
  24. // 翻訳言語メニューか?
  25. const menu = document.querySelector('.ytp-panel-menu');
  26. if (!menu || !Array.from(menu.childNodes).some(menuItem =>
  27. menuItem.textContent.trim() == TARGET_LANGUAGE))
  28. return;
  29.  
  30. // 対象言語以外の言語を削除
  31. Array.from(menu.childNodes).forEach(menuItem => {
  32. if (!(menuItem.textContent.trim() == TARGET_LANGUAGE))
  33. menuItem.remove();
  34. });
  35. });
  36. observer.observe(player, {
  37. childList: true,
  38. subtree: true,
  39. });
  40. }
  41.  
  42. // プレーヤーが見つかるのを待つ
  43. const intervalId = setInterval(() => {
  44. const player = document.querySelector('.html5-video-player');
  45. if (player) {
  46. clearInterval(intervalId);
  47. observePlayer();
  48. }
  49. }, 500);
  50. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址