Advertisement
jcunews

youtube-auto-select-original-audio-language.user.js

Oct 18th, 2023 (edited)
1,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        YouTube Auto Select Original Audio Language
  3. // @namespace   https://greasyfork.org/en/users/85671-jcunews
  4. // @version     1.0.1
  5. // @license     AGPL v3
  6. // @author      jcunews
  7. // @description Context: https://old.reddit.com/r/CodingHelp/comments/17aadka/youtube_pick_a_language_option_on_page_load/
  8. // @match       https://www.youtube.com/*
  9. // @grant       none
  10. // ==/UserScript==
  11.  
  12. (rx => {
  13.   rx = /original/i;
  14.   setInterval((e, a) => {
  15.     if (e = window.movie_player) {
  16.       a = e;
  17.       while (a?.tagName) {
  18.         if (getComputedStyle(a).display === "none") return;
  19.         a = a.parentNode
  20.       }
  21.       if ((a = e.getAvailableAudioTracks()).length && !rx.test(e.getAudioTrack().Qc.name)) {
  22.         a.some(o => {
  23.           if (rx.test(o.Qc.name)) {
  24.             e.setAudioTrack({id: o.id});
  25.             return true
  26.           }
  27.         })
  28.       }
  29.     }
  30.   }, 200)
  31. })()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement