var interceptor=(function(){"use strict";function L(t){return t}const E="READ_FROG_GET_PLAYER_DATA",l="READ_FROG_PLAYER_DATA",T="READ_FROG_WAIT_TIMEDTEXT",g="READ_FROG_TIMEDTEXT_READY",_=5e3,f="READ_FROG_ENSURE_SUBTITLES",R="READ_FROG_ENSURE_SUBTITLES_DONE",a=new Map,s=new Map;function y(t){if(/api\/timedtext/.test(t)){const e=new URL(t),r=e.searchParams.get("v"),n=e.searchParams.get("pot");if(r&&n){a.set(r,t);const o=s.get(r);o&&(o.forEach(i=>i(t)),s.delete(r))}}}function S(t,e){const r=a.get(t);return r?Promise.resolve(r):new Promise(n=>{const o=s.get(t)||[];o.push(n),s.set(t,o),setTimeout(()=>{const i=s.get(t);if(i){const p=i.indexOf(n);p!==-1&&(i.splice(p,1),n(a.get(t)??null))}},e)})}function w(){const t=XMLHttpRequest.prototype.open,e=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.open=function(r,n,...o){return this._url=n.toString(),t.apply(this,[r,n,...o])},XMLHttpRequest.prototype.send=function(...r){return this.addEventListener("load",function(){y(this.responseURL||this._url)}),e.apply(this,r)}}function A(t){return a.get(t)??null}function u(t,e){return{type:l,requestId:t,success:!1,error:e}}function h(t){return t.map(e=>({...e,baseUrl:e.baseUrl?.includes("://")?e.baseUrl:`${location.origin}${e.baseUrl}`}))}function m(t){return(t??[]).flatMap(e=>{try{return[{url:e.url,vssId:e.vssId,kind:e.kind,languageCode:new URL(e.url).searchParams.get("lang")??void 0}]}catch{return[]}})}function d(){return document.querySelector(".html5-video-player.playing-mode, .html5-video-player.paused-mode")}function U(){w(),window.addEventListener("message",P)}function P(t){if(t.origin===window.location.origin){if(t.data?.type===E){const e=t.data,r=I(e);window.postMessage(r,window.location.origin)}if(t.data?.type===T){const{requestId:e,videoId:r}=t.data;S(r,_).then(n=>{window.postMessage({type:g,requestId:e,url:n},window.location.origin)})}if(t.data?.type===f){const{requestId:e}=t.data;D(),window.postMessage({type:R,requestId:e},window.location.origin)}}}function I(t){const{requestId:e,expectedVideoId:r}=t;try{const n=d();if(!n)return u(e,"PLAYER_NOT_FOUND");const o=n.getPlayerResponse?.(),i=o?.videoDetails?.videoId;return!i||i!==r?u(e,"VIDEO_ID_MISMATCH"):{type:l,requestId:e,success:!0,data:{videoId:i,captionTracks:h(o?.captions?.playerCaptionsTracklistRenderer?.captionTracks??[]),audioCaptionTracks:m(n.getAudioTrack?.()?.captionTracks),device:window.ytcfg?.get?.("DEVICE")??null,cver:n.getWebPlayerContextConfig?.()?.innertubeContextClientVersion??null,playerState:n.getPlayerState?.()??-1,selectedTrackLanguageCode:n.getOption?.("captions","track")?.languageCode??null,cachedTimedtextUrl:A(i)}}}catch(n){return u(e,String(n))}}function D(){const t=document.querySelector(".ytp-subtitles-button");if(!t||t.getAttribute("aria-pressed")==="true")return;const e=d();e?.toggleSubtitles?e.toggleSubtitles():t.click()}const M={matches:["*://*.youtube.com/*"],world:"MAIN",runAt:"document_start",main(){U()}};function O(){}function c(t,...e){}const b={debug:(...t)=>c(console.debug,...t),log:(...t)=>c(console.log,...t),warn:(...t)=>c(console.warn,...t),error:(...t)=>c(console.error,...t)};return(async()=>{try{return await M.main()}catch(t){throw b.error('The content script "interceptor" crashed on startup!',t),t}})()})();
interceptor;