16 lines
29 KiB
JavaScript
16 lines
29 KiB
JavaScript
import { e } from '../../index-2879cf47.js';
|
|
import { e as e$3 } from '../../background.injected-4f2074c6.js';
|
|
import { n, e as e$1, t } from '../../get_stream_details-70a52c12.js';
|
|
import { d as dt, t as t$1 } from '../../parse_token.util-73818eef.js';
|
|
import { c, e as e$4, a } from '../../constants-27e12ede.js';
|
|
import { s } from '../../router.interface-6cdbc015.js';
|
|
import { e as e$2 } from '../../style-inject.es-a0e1a0ba.js';
|
|
|
|
const h=e=>void 0!==(null==e?void 0:e.months),m=e=>void 0!==(null==e?void 0:e.slug);function f(e){if(!e)return 0;e=e.toLowerCase();const t=/\((.+)\)/.exec(e);if(!t)return 1;const n=t[1].split(/\s/),s=parseInt(n[0]);return isNaN(s)?0:n[1].startsWith("year")?12*parseInt(n[0]):parseInt(n[0])}function p(e,t){const n=t;for(let t=0;t<n.length;t++)if(n[t][0]>e)return n[t-1][1];return n[n.length-1][1]}function g(e){var t,n,s;return {liveChatAuthorBadgeRenderer:{accessibility:{accessibilityData:{label:null!==(t=e.slug)&&void 0!==t?t:"none"}},tooltip:null!==(n=e.slug)&&void 0!==n?n:"none",customThumbnail:{thumbnails:[{url:e.url,width:18,height:18}],accessibility:{accessibilityData:{label:null!==(s=e.slug)&&void 0!==s?s:"none"}}}}}}function v(e,t,n,s,o){const i=t(e.authorExternalChannelId);!function(e,t){(null==t?void 0:t.a)&&(e.authorName={simpleText:t.a});}(e,i),function(e,t){var n,s;e.authorBadges||(e.authorBadges=[]);for(const o of e.authorBadges){const e=o.liveChatAuthorBadgeRenderer;(null===(n=e.icon)||void 0===n?void 0:n.iconType)?e._mtvType=null===(s=e.icon)||void 0===s?void 0:s.iconType.toLowerCase():e.customThumbnail&&(e._mtvType="member"),"moderator"===e._mtvType&&(delete e.icon,e._mtvType="moderator",e.customThumbnail={thumbnails:[{url:t,width:18,height:18}]});}}(e,o),(null==s?void 0:s.length)&&function(e,t,n){if((null==n?void 0:n.b)&&!(n.b<=0))for(const s of e.authorBadges){const e=s.liveChatAuthorBadgeRenderer;if("member"!==e._mtvType)continue;const o=f(e.tooltip);if(0===o)continue;const i=o+n.b,r=`Member (${i} months)`,a=p(i,t);e.customThumbnail=a,delete e.icon,e.tooltip=r,e.accessibility.accessibilityData.label=r;}}(e,s,i),function(e,t){const n=t(e.authorExternalChannelId);if(e.authorBadges||(e.authorBadges=[]),n)for(const t of n)e.authorBadges.push(t);}(e,n);}const w=/[\s.,?!]/;function y(e){const t=[];let n=0;for(let s=0;s<e.length-1;s++)w.test(e[s])!==w.test(e[s+1])&&(t.push(e.substring(n,s+1)),n=s+1);return t.push(e.substring(n)),t}function b(e){let t;if(e.provider===t$1.Twitch)t=`https://static-cdn.jtvnw.net/emoticons/v2/${e.id}/static/dark/1.0`;else if(e.provider===t$1.FFZ)t=`https://cdn.frankerfacez.com/emote/${e.id}/1`;else if(e.provider===t$1.BTTV)t=`https://cdn.betterttv.net/emote/${e.id}/1x`;else {if(e.provider!==t$1.Spore||!(null==e?void 0:e.ext))return;t=`https://cdn.bio/ugc/collectible/${e.id}.tiny.${e.ext}`;}return {emojiId:"mogultv-"+e.name+"-"+e.id,image:{thumbnails:[{url:t}],accessibility:{accessibilityData:{label:e.name}}},isCustomEmoji:!0,isSporeEmote:e.provider===t$1.Spore,searchTerms:[e.name],shortcuts:[":"+e.name+":",e.name]}}class C{constructor(e){this.gatewayService=e;}addAliasesToMessage(e){v(e,(e=>this.gatewayService.getUserInfo(e)),(e=>this.gatewayService.getSporeBadges(e)),this.gatewayService.monthBadgeList,"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAABg2lDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV/TiiIVBzuIOGRonSyIijpqFYpQIdQKrTqYXPoFTRqSFBdHwbXg4Mdi1cHFWVcHV0EQ/ABxc3NSdJES/5cUWsR4cNyPd/ced+8AoVFhmhUaAzTdNtPJhJjNrYrdrwgjBGAaMZlZxpwkpeA7vu4R4OtdnGf5n/tz9Kl5iwEBkXiWGaZNvEE8tWkbnPeJI6wkq8TnxKMmXZD4keuKx2+ciy4LPDNiZtLzxBFisdjBSgezkqkRTxJHVU2nfCHrscp5i7NWqbHWPfkLw3l9ZZnrNIeRxCKWIEGEghrKqMBGnFadFAtp2k/4+Idcv0QuhVxlMHIsoAoNsusH/4Pf3VqFiXEvKZwAul4c5yMGdO8CzbrjfB87TvMECD4DV3rbX20AM5+k19ta9Ajo3wYurtuasgdc7gCDT4Zsyq4UpCkUCsD7GX1TDhi4BXrXvN5a+zh9ADLUVeoGODgERoqUve7z7p7O3v490+rvB3pIcqqJKL5aAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAC4jAAAuIwF4pT92AAAAB3RJTUUH5QwEARQDdqq2HwAAABl0RVh0Q29tbWVudABDcmVhdGVkIHdpdGggR0lNUFeBDhcAAAGkSURBVDjLpdSxS5tBGMfx7+V9JamLGbSQNNAQdBBJhZKWLPkHxKmQEgd9xUFwCRQKHe1cKHSztCCmLyQlkriULu2kSyBQkCCCg0bQCJrhTSUxoW+8DuLRNPqq8aa7hx8f7nk4TpDXDCQfAC+9rTKCt4KctgcEnZKJ/pcYoRmG+oewz21Wdlb4+PvzvxFLvwlJD5vEx+Lomg5A6ahE/nTt/5hXd0Le+98x9WRKnUtHJSYKkxzLalfW5djSaKILOZCHqvZQDLIwMO8MPdOf4h/wq3Or3epAAuIRP6M/MEYMZyjY1zm6SCBC8XlBId+j3wj7wuiui+lcO6PVszxNu4lH93RiFHBrbsK+MAAnjRNnKBVaxq25u+qRQETt7bZNavfL9a2lQstMj08jhHB8idmtLF8b2atvdBUipaTVbqk2K7UKme0MrytvVEa/DWJumhi7c8QfvKD8p0zR/tV1O0FOk7dBblougE+Pl+6FKGijukGtWesZUZBZT5NcT2KdWT0hl8O2AK9ZT8M6xAZjzO8v3PFLkmVBTpsFuQgi2Nu/Ji3QXv0FPBynaffELJkAAAAASUVORK5CYII=");}}var I={exports:{}},A="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof window.msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto);if(A){var S=new Uint8Array(16);I.exports=function(){return A(S),S};}else {var M=new Array(16);I.exports=function(){for(var e,t=0;t<16;t++)0==(3&t)&&(e=4294967296*Math.random()),M[t]=e>>>((3&t)<<3)&255;return M};}for(var E=[],B=0;B<256;++B)E[B]=(B+256).toString(16).substr(1);var x,k,R=function(e,t){var n=t||0,s=E;return [s[e[n++]],s[e[n++]],s[e[n++]],s[e[n++]],"-",s[e[n++]],s[e[n++]],"-",s[e[n++]],s[e[n++]],"-",s[e[n++]],s[e[n++]],"-",s[e[n++]],s[e[n++]],s[e[n++]],s[e[n++]],s[e[n++]],s[e[n++]]].join("")},T=I.exports,O=R,U=0,_=0;var q=function(e,t,n){var s=t&&n||0,o=t||[],i=(e=e||{}).node||x,r=void 0!==e.clockseq?e.clockseq:k;if(null==i||null==r){var a=T();null==i&&(i=x=[1|a[0],a[1],a[2],a[3],a[4],a[5]]),null==r&&(r=k=16383&(a[6]<<8|a[7]));}var l=void 0!==e.msecs?e.msecs:(new Date).getTime(),c=void 0!==e.nsecs?e.nsecs:_+1,u=l-U+(c-_)/1e4;if(u<0&&void 0===e.clockseq&&(r=r+1&16383),(u<0||l>U)&&void 0===e.nsecs&&(c=0),c>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");U=l,_=c,k=r;var d=(1e4*(268435455&(l+=122192928e5))+c)%4294967296;o[s++]=d>>>24&255,o[s++]=d>>>16&255,o[s++]=d>>>8&255,o[s++]=255&d;var h=l/4294967296*1e4&268435455;o[s++]=h>>>8&255,o[s++]=255&h,o[s++]=h>>>24&15|16,o[s++]=h>>>16&255,o[s++]=r>>>8|128,o[s++]=255&r;for(var m=0;m<6;++m)o[s+m]=i[m];return t||O(o)},N=I.exports,j=R;var L=function(e,t,n){var s=t&&n||0;"string"==typeof e&&(t="binary"===e?new Array(16):null,e=null);var o=(e=e||{}).random||(e.rng||N)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t)for(var i=0;i<16;++i)t[s+i]=o[i];return t||j(o)},P=q,D=L,W=D;W.v1=P,W.v4=D;var V=W;const F=100,Q=-1,K={"-32601":"Method not found"};K[F]="Invalid origin",K[Q]="Error";class J{constructor({postMessage:e,timeout:t=3e3}={}){this.postMessage=e,this.timeout=t,this.pendingRequests={},this.callbackFunctions={},this.call=this.call.bind(this),this.resolve=this.resolve.bind(this),this.resolveRPCResponse=this.resolveRPCResponse.bind(this);}call(e,t,n={}){const{timeout:s=this.timeout}=n,o=function(){let e=null,t=null;const n=new Promise(((n,s)=>(e=n,t=s,t)));return n.resolve=e,n.reject=t,n}(),i=[];for(const e of Array.from(t||[]))if("function"==typeof e){const t={_browserComms:!0,_browserCommsGunCallback:!0,callbackId:V.v4()};this.callbackFunctions[t.callbackId]=e,i.push(t);}else i.push(e);const r=function({method:e,params:t}){if(null==t)throw new Error("Must provide params");for(const e of Array.from(t))if("function"==typeof e)throw new Error("Functions are not allowed. Use RPCCallback instead.");return {_browserComms:!0,id:V.v4(),method:e,params:t}}({method:e,params:i});this.pendingRequests[r.id]={reject:o.reject,resolve:o.resolve,isAcknowledged:!1};try{this.postMessage(JSON.stringify(r),"*");}catch(e){return o.reject(e),o}return setTimeout((()=>{if(!this.pendingRequests[r.id].isAcknowledged)return o.reject(new Error("Message Timeout"))}),s),o}resolve(e){switch(!1){case!(!0===e?.acknowledge):return this.resolveRPCRequestAcknowledgement(e);case!H(e):return this.resolveRPCResponse(e);case!function(e){return e?.callbackId&&null!=e.params}(e):return this.resolveRPCCallbackResponse(e);default:throw new Error("Unknown response type")}}resolveRPCResponse(e){const t=this.pendingRequests[e.id];if(null==t)throw new Error("Request not found");t.isAcknowledged=!0;const{result:n,error:s}=e;return s?t.reject(s.data||new Error(s.message)):null!=n?t.resolve(n):t.resolve(null),null}resolveRPCRequestAcknowledgement(e){const t=this.pendingRequests[e.id];if(null==t)throw new Error("Request not found");return t.isAcknowledged=!0,null}resolveRPCCallbackResponse(e){const t=this.callbackFunctions[e.callbackId];if(null==t)throw new Error("Callback not found");return t.apply(null,e.params),null}}function X({params:e,callbackId:t}){return {_browserComms:!0,callbackId:t,params:e}}function z({requestId:e,result:t=null,rPCError:n=null}){return {_browserComms:!0,id:e,result:t,error:n}}function Z({code:e,data:t=null}){return {_browserComms:!0,code:e,message:K[e],data:t}}function G(e){return e?._browserComms}function H(e){return e?.id&&(void 0!==e.result||void 0!==e.error)}const Y=1e4,$="undefined"!=typeof window?window:self;class ee{constructor(e={}){const{timeout:t,shouldConnectToServiceWorker:n,handshakeTimeout:s=Y,isParentValidFn:o=(()=>!0)}=e;this.handshakeTimeout=s,this.isParentValidFn=o,this.isListening=!1;const i=globalThis?.window?._browserCommsIsInAppBrowser||-1!==navigator.userAgent.indexOf("/InAppBrowser");this.hasParent="undefined"!=typeof window&&window.self!==window.top||i,this.parent=globalThis?.window?.parent,this.client=new J({timeout:t,postMessage:(e,t)=>{if(i){let t=(()=>{try{return JSON.parse(localStorage["portal:queue"])}catch(e){return null}})();return null==t&&(t=[]),t.push(e),localStorage["portal:queue"]=JSON.stringify(t),localStorage["portal:queue"]}return this.parent?.postMessage(e,t)}}),this.ready=n?function(){return new Promise(((e,t)=>{const n=setTimeout(e,5e3);return navigator?.serviceWorker?.ready.catch((function(){return console.log("caught sw error"),null})).then((t=>{const s=t?.active;return s&&(this.sw=new J({timeout:this.timeout,postMessage:(e,t)=>{const n=new MessageChannel;if(n)return n.port1.onmessage=e=>this.onMessage(e,{isServiceWorker:!0}),s.postMessage(e,[n.port2])}})),clearTimeout(n),e()}))}))}():Promise.resolve(!0),this.registeredMethods={ping:()=>Object.keys(this.registeredMethods)},this.parentsRegisteredMethods=[],this.setParent=this.setParent.bind(this),this.setInAppBrowserWindow=this.setInAppBrowserWindow.bind(this),this.replyInAppBrowserWindow=this.replyInAppBrowserWindow.bind(this),this.onMessageInAppBrowserWindow=this.onMessageInAppBrowserWindow.bind(this),this.listen=this.listen.bind(this),this.close=this.close.bind(this),this.call=this.call.bind(this),this.onRequest=this.onRequest.bind(this),this.onMessage=this.onMessage.bind(this),this.on=this.on.bind(this);}setParent(e){this.parent=e,this.hasParent=!0;}setInAppBrowserWindow(e,t){this.iabWindow=e;const n=-1!==navigator.userAgent.indexOf("iPhone")?"loadstop":"loadstart";return this.iabWindow.addEventListener(n,(()=>{this.iabWindow.executeScript({code:"window._browserCommsIsInAppBrowser = true;"}),clearInterval(this.iabInterval),this.iabInterval=setInterval((()=>this.iabWindow.executeScript({code:"localStorage.getItem('portal:queue');"},(e=>{try{return (e=JSON.parse(e?.[0]))&&e.length&&this.iabWindow.executeScript({code:"localStorage.setItem('portal:queue', '[]')"}),e.map((e=>t(e)))}catch(t){return console.log(t,e)}}))),100);})),this.iabWindow.addEventListener("exit",(()=>clearInterval(this.iabInterval)))}replyInAppBrowserWindow(e){const t=e.replace(/'/g,"'");return this.iabWindow.executeScript({code:`if(window._browserCommsOnMessage) window._browserCommsOnMessage('${t}')`})}onMessageInAppBrowserWindow(e){return this.onMessage({data:e,source:{postMessage:e=>this.call("browser.reply",{data:e})}})}listen(){this.isListening=!0,$.addEventListener("message",this.onMessage),"undefined"!=typeof window&&null!==window&&(window._browserCommsOnMessage=e=>this.onMessage({debug:!0,data:(()=>{try{return JSON.parse(e)}catch(t){return console.log("error parsing",e),null}})()})),this.clientValidation=this.client.call("ping",null,{timeout:this.handshakeTimeout}).then((e=>{this.hasParent&&(this.parentsRegisteredMethods=this.parentsRegisteredMethods.concat(e));})).catch((()=>null)),this.swValidation=this.ready.then((()=>this.sw?.call("ping",null,{timeout:this.handshakeTimeout}))).then((e=>{this.parentsRegisteredMethods=this.parentsRegisteredMethods.concat(e);}));}close(){return this.isListening=!0,$.removeEventListener("message",this.onMessage)}async call(e,...t){if(!this.isListening)return new Promise(((e,t)=>t(new Error("Must call listen() before call()"))));const n=(e,t)=>{const n=this.registeredMethods[e];if(!n)throw new Error("Method not found");return n.apply(null,t)};if(await this.ready,this.hasParent){let s=null;await this.clientValidation;if(!(-1!==this.parentsRegisteredMethods.indexOf(e)))return n(e,t);{const o=await this.client.call(e,t);try{if("ping"===e){const s=n(e,t);return (o||[]).concat(s)}return o}catch(o){try{if(s=o,!this.sw)return n(e,t);try{const s=await this.sw.call(e,t);if("ping"===e){const o=n(e,t);return (s||[]).concat(o)}return s}catch{return n(e,t)}}catch(e){throw "Method not found"===e.message&&s?s:e}}}}else {if(!this.sw)return n(e,t);if(await this.swValidation,-1===this.parentsRegisteredMethods.indexOf(e))return n(e,t);try{const s=await this.sw.call(e,t);if("ping"===e){const o=n(e,t);return (s||[]).concat(o)}return s}catch(s){return n(e,t)}}}async onRequest(e,t){const n=[];for(const s of Array.from(t.params||[]))s?._browserCommsGunCallback?(t=>{n.push(((...n)=>e(X({params:n,callbackId:t.callbackId}))));})(s):n.push(s);e(function({requestId:e}){return {_browserComms:!0,id:e,acknowledge:!0}}({requestId:t.id}));try{const s=await this.call(t.method,...Array.from(n));return e(z({requestId:t.id,result:s}))}catch(n){return e(z({requestId:t.id,rPCError:Z({code:Q,data:n})}))}}onMessage(e,{isServiceWorker:t}={}){try{const s="string"==typeof e.data?JSON.parse(e.data):e.data;if(!G(s))return;const o=function(t){return "undefined"!=typeof window&&null!==window?e.source?.postMessage(JSON.stringify(t),"*"):e.ports[0].postMessage(JSON.stringify(t))};if(null!=(n=s)?.id&&null!=n.method)return this.onRequest(o,s);if(G(s)){let n;if(this.isParentValidFn(e.origin))return n=t?this.sw:this.client,n.resolve(s);if(H(s))return n=t?this.sw:this.client,n.resolve(z({requestId:s.id,rPCError:Z({code:F})}));throw new Error("Invalid origin")}throw new Error("Unknown RPCEntity type")}catch(e){}var n;}on(e,t){this.registeredMethods[e]=t;}}class te{constructor(){this.call=(e,t)=>this.browserComms.call(e,t),this.listen=()=>{this.browserComms.listen(),this.browserComms.on("context.getCredentials",this.getCredentials),this.browserComms.on("dom.setStyle",this.setStyle);},this.setStyle=({querySelector:e,style:t})=>{const n=document.querySelector(e);null==n||n.setAttribute("style",t);},this.getCredentials=()=>this.credentials,this.setCredentials=e=>{this.credentials=e;},this.browserComms=new ee,this.credentials={};}}class ne{constructor(e){this.gatewayService=e;}addEmotesToMessage(e){return function(e,t){const n=e.authorExternalChannelId,s=[];for(const o of e.message.runs)if("string"==typeof o.text){const{text:e}=o;let i=0,r=0;const a=y(e);let l=!1;for(const o of a){const a=t("🌝"===o?"Kappa":o,n);a&&(l=!0,i>0&&s.push({text:e.substring(r,i)}),s.push({emoji:a}),r=i+o.length),i+=o.length;}l?s.push({text:e.substring(r,i)}):s.push(o);}else if("🌝"===o.emoji.emojiId){const e=t("Kappa",n);e&&s.push({emoji:e});}else s.push(o);return e.message.runs=s,e.message}(e,((e,t)=>this.gatewayService.getEmote(e,t)))}}class se extends e.exports.EventEmitter{constructor(e){super(),this.backgroundService=e,this.extensionMappings=[],this.extensionMappingDomElements=new Map,this.handleTabUpdate(),window.addEventListener("message",(e=>{var t,n,s,o;if("tab:updated"===e.data.type){const i=(null===(n=null===(t=e.data)||void 0===t?void 0:t.tab)||void 0===n?void 0:n.url)===window.location.href;if(e.data.tab&&i){"complete"===(null===(o=null===(s=e.data)||void 0===s?void 0:s.changeInfo)||void 0===o?void 0:o.status)&&this.handleTabUpdate();}}}));}async fetchExtensionMappings(e,t){var n;const s$1=await this.backgroundService.fetch("/spore/fetch-extension-mappings",{channelId:e,extensionVersion:t});s(s$1)&&(this.extensionMappings=null!==(n=s$1.body)&&void 0!==n?n:[]),this.emit("inject-mappings",this.extensionMappings);}async handleTabUpdate(){this.emit("cleanup-mappings",this.extensionMappingDomElements);const e=setInterval((async()=>{const o=n();if(o){clearInterval(e);const t$1=o.channelId,i=e$1(!1)&&t(!1);t$1&&i&&await this.fetchExtensionMappings(t$1,"3.0.1");}}),1e3);}setDomElementMapping(e,t){this.extensionMappingDomElements.set(e,t);}}class oe extends e.exports.EventEmitter{constructor(e,t){super(),this.backgroundService=e,this.channelId=t,this.monthBadgeList=[],this.emoteCache=new Map,this.sporeUserEmoteCache=new Map,this.sporeBadgeCache=new Map,e.getLiveStorageValue("auth.token2",dt).then((e=>this.myUserInfo=e)).catch((e=>console.error("error parsing auth.token",e))),this.fetchUserInfo().then((()=>{this.fetchEmotes(),this.fetchBadges(),this.fetchSporeOrgId().then((()=>{this.fetchCurrentUserSporeInfo();}));})),setInterval((()=>{this.fetchEmotes(),this.fetchBadges();}),c.FIVE_MINUTE_MS),setInterval((()=>{this.fetchUserInfo();}),c.ONE_MINUTE_MS),setInterval((()=>{this.fetchCurrentUserSporeInfo();}),5*c.ONE_SECOND_MS);}async fetchBadges(){const e=await this.backgroundService.fetch("/gateway/badges");if(!s(e))return;const t=e.body.filter(h).sort(((e,t)=>e.months-t.months)),n=e.body.filter(m);this.monthBadgeList=t.map((e=>[e.months,{thumbnails:[{url:e.url,width:16,height:16}]}])),this.sporeBadgeCache.clear();for(const e of n){const t=g(e);t&&this.sporeBadgeCache.set(e.slug,t);}console.log("monthbadges",this.monthBadgeList),console.log("sporeBadgeCache",this.sporeBadgeCache),this.emit("monthBadges",this.monthBadgeList),this.emit("sporeBadges",this.sporeBadgeCache);}async fetchEmotes(){const e=await this.backgroundService.fetch("/gateway/emotes");if(s(e)){this.emoteCache.clear();for(const t of e.body){const e=b(t);e&&this.emoteCache.set(t.name,e);}console.log("emoteCache",this.emoteCache),this.emit("emotes",this.emoteCache);}}async fetchUserInfo(){const e=await this.backgroundService.fetch("/gateway/users",this.channelId);s(e)&&(this.infoCache=new Map(e.body),console.log("this.infoCache",this.infoCache),this.emit("users",this.infoCache));}async fetchSporeOrgId(){var e;const t=await this.backgroundService.fetch("/spore/fetch-youtube-channel",this.channelId);s(t)&&(this.sporeOrgId=null===(e=t.body)||void 0===e?void 0:e.sporeOrgId);}async fetchCurrentUserSporeInfo(){var e,t,n,s$1,o;console.log("spore fetching current user",null===(t=null===(e=this.myUserInfo)||void 0===e?void 0:e.value)||void 0===t?void 0:t.sub);const i=null===(n=this.myUserInfo.value)||void 0===n?void 0:n.sub;if(i&&this.sporeOrgId)try{const e=await this.backgroundService.fetch("/spore/fetch-spore-user",{connectionSourceId:i,sporeOrgId:this.sporeOrgId,preferCache:!1});if(!s(e))return;if(this.mySporeUserInfo=e.body,console.log("spore user info",this.mySporeUserInfo),(null===(s$1=null==e?void 0:e.body)||void 0===s$1?void 0:s$1.emotes)&&(null===(o=null==e?void 0:e.body)||void 0===o?void 0:o.serializedEmotes)){const t=new Map;for(const n of e.body.serializedEmotes){const e=b(n);e&&!this.sporeUserEmoteCache.get(n.name)&&(t.set(n.name,e),this.sporeUserEmoteCache.set(n.name,e));}this.emit("spore-user-emotes",t);}}catch(e){console.warn("error fetching spore user",e);}}getSerializedMetadata(e){const t=e.links.find((t=>t.prv===e.prv)),n={a:null==t?void 0:t.name,b:e.meta.sub,c:e.meta.col};return Object.values(n).filter((e=>void 0!==e)).length>0?n:void 0}getUserInfo(e){var t,n,s;if((null===(n=null===(t=this.myUserInfo)||void 0===t?void 0:t.value)||void 0===n?void 0:n.sub)===e){const e=this.getSerializedMetadata(this.myUserInfo.value);if(e)return e}return null===(s=this.infoCache)||void 0===s?void 0:s.get(e)}getSporeBadges(e){var t,n,s;const o=[];if(this._isCurrentUser(e)){const e=null!==(n=null===(t=this.mySporeUserInfo)||void 0===t?void 0:t.badges)&&void 0!==n?n:[];if(e)for(const t of e){const e=this.sporeBadgeCache.get(t);e&&o.push(e);}}else {const t=this.infoCache.get(e);if(t){const e=new Set(null!==(s=null==t?void 0:t.e)&&void 0!==s?s:[]);if(e)for(const t of e){const e=this.sporeBadgeCache.get(t);e&&o.push(e);}}}return o}getEmote(e,t){var n,s,o,i,r,a,l;const c=null===(n=this.emoteCache)||void 0===n?void 0:n.get(e);if(null==c?void 0:c.isSporeEmote)if(this._isCurrentUser(t)){const t=null!==(o=null===(s=this.mySporeUserInfo)||void 0===s?void 0:s.emotes)&&void 0!==o?o:[];if((null===(i=this.mySporeUserInfo)||void 0===i?void 0:i.emotes)&&!t.includes(e))return}else {const n=null!==(a=null===(r=this.infoCache.get(t))||void 0===r?void 0:r.d)&&void 0!==a?a:[];if(!this.infoCache.get(t))return;if((null===(l=this.infoCache.get(t))||void 0===l?void 0:l.d)&&!n.includes(e))return}return c}_isCurrentUser(e){var t;return e===(null===(t=this.myUserInfo.value)||void 0===t?void 0:t.sub)}}
|
|
/*!
|
|
* cookie
|
|
* Copyright(c) 2012-2014 Roman Shtylman
|
|
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
* MIT Licensed
|
|
*/var ie=function(e,t){if("string"!=typeof e)throw new TypeError("argument str must be a string");for(var n={},s=t||{},o=e.split(ae),i=s.decode||re,r=0;r<o.length;r++){var a=o[r],l=a.indexOf("=");if(!(l<0)){var c=a.substr(0,l).trim(),u=a.substr(++l,a.length).trim();'"'==u[0]&&(u=u.slice(1,-1)),null==n[c]&&(n[c]=le(u,i));}}return n},re=decodeURIComponent,ae=/; */;function le(e,t){try{return t(e)}catch(t){return e}}function ce(e,t,n=15){var s,o;if(!e)return;if(n<0)return;const i=function(e){var t,n;if(e.iframeQuerySelector){const s=document.querySelector(e.querySelector),o=null!==(t=null==s?void 0:s.contentDocument)&&void 0!==t?t:null===(n=null==s?void 0:s.contentWindow)||void 0===n?void 0:n.document;if(!o)return;return o.querySelector(e.iframeQuerySelector)}return document.querySelector(e.querySelector)}(e),a=function(e){var t,n;if(e.iframeQuerySelector){const s=document.querySelector(e.querySelector),o=null!==(t=null==s?void 0:s.contentDocument)&&void 0!==t?t:null===(n=null==s?void 0:s.contentWindow)||void 0===n?void 0:n.document;if(!o)return;return o.getElementById(e.slug)}return document.getElementById(e.slug)}(e);if(i&&!a){const n=document.createElement("iframe");n.src=e.iframeUrl,n.setAttribute("key",e.slug),n.setAttribute("style",c.DEFAULT_EXTENSION_MAPPING_IFRAME_STYLES),n.id=e.slug,"append"===e.domAction?i.appendChild(n):"before"===e.domAction?null===(s=i.parentNode)||void 0===s||s.insertBefore(n,i):"after"===e.domAction?null===(o=i.parentNode)||void 0===o||o.insertBefore(n,i.nextSibling):"replace"===e.domAction&&i.replaceWith(n),t.setDomElementMapping(null==e?void 0:e.id,n);}else setTimeout((()=>{ce(e,t,n-1);}),250);}var ue;async function de(e,t){await customElements.whenDefined(e);const s=customElements.get(e);if(!s)return void console.warn(`Polymer: ${e} not found`);const o=s.prototype[t.functionName];s.prototype[t.functionName]=function(...e){if(t.ludwigOnly&&!e$1())return o.apply(this,e);if(console.log("%cRule:","color: hsl(0deg, 100%, 70%); font-weight: bold;",t),console.log("%cArgs:","color: hsl(30deg, 100%, 70%); font-weight: bold;",e),t.type===ue.OverrideFunction)try{return t.function.apply(this,e)}catch(e){console.error(JSON.stringify(t)),console.error(e);}if(t.type===ue.RunBefore)try{t.function.apply(this,e);}catch(e){console.error(e);}let s=o.apply(this,e);if(t.type===ue.RunAfter)try{s=t.function.apply(this,[s]);}catch(e){console.error(e);}return console.log("%cResult:","color: hsl(60deg, 100%, 70%); font-weight: bold;",s),s};}!function(e){e[e.OverrideFunction=0]="OverrideFunction",e[e.RunBefore=1]="RunBefore",e[e.RunAfter=2]="RunAfter";}(ue||(ue={}));const he=(e,t,{LudwigOnly:n})=>({functionName:e,function:t,ludwigOnly:n||!1,type:ue.OverrideFunction}),me=(e,t,{LudwigOnly:n})=>({functionName:e,function:t,ludwigOnly:n||!1,type:ue.RunBefore});function fe(e,t,s){de("yt-live-chat-item-list-renderer",me("handleAddChatItemAction_",(function(n){n.item.liveChatTextMessageRenderer&&(t.addAliasesToMessage(n.item.liveChatTextMessageRenderer),e.addEmotesToMessage(n.item.liveChatTextMessageRenderer));}),{LudwigOnly:true})),de("yt-live-chat-text-input-field-renderer",((e,t,{LudwigOnly:n})=>({functionName:e,function:t,ludwigOnly:n||!1,type:ue.RunAfter}))("calculateLiveChatRichMessageInput_",(function(e){var t;if(!(null==e?void 0:e.textSegments))return e;for(const n of e.textSegments)if(null===(t=n.emojiId)||void 0===t?void 0:t.startsWith("mogultv")){const[,e]=n.emojiId.split("-");delete n.emojiId,n.text=e;}return e}),{LudwigOnly:true})),s.on("emotes",(e=>{if(!e$1())return;const t=document.querySelector("yt-live-chat-item-list-renderer");if(null==t?void 0:t.emojiManager){if(t.emojiManager._mogulTvLoaded)return;t.emojiManager._mogulTvLoaded=!0,t.emojiManager.load(Array.from(e.values()).filter((e=>!(null==e?void 0:e.isSporeEmote))));}else console.warn("Cannot find chat list");})),s.on("spore-user-emotes",(e=>{if(!e$1())return;const t=document.querySelector("yt-live-chat-item-list-renderer");(null==t?void 0:t.emojiManager)?t.emojiManager.load([...e.values()]):console.warn("Cannot find chat list");}));}function pe(e){return e?e._mtvType?e._mtvType:e.icon?e.icon.iconType.toLowerCase():e.customThumbnail?"member":"":""}async function ge(e){de("yt-live-chat-author-badge-renderer",he("computeType_",(e=>pe(e.liveChatAuthorBadgeRenderer)),{LudwigOnly:true})),de("yt-live-chat-author-chip",he("computeAuthorType_",(function(t){var n,s;const o=this.$["author-name"];if(o){let t;const i=null===(n=this.parentElement)||void 0===n?void 0:n.parentElement,r=null===(s=null==i?void 0:i.data)||void 0===s?void 0:s.authorExternalChannelId;if(r){const n=e.getUserInfo(r);(null==n?void 0:n.c)&&(t=n.c);}t||(t=a(this.authorName.simpleText)),o.style.color=t;}return function(e){if(!e)return "";for(const t of e){if(!t.liveChatAuthorBadgeRenderer)continue;const e=pe(t.liveChatAuthorBadgeRenderer);if("verified"!==e)return e}return ""}(t)}),{LudwigOnly:true}));}function ve(e,t,n,s){fe(s,n,t),async function(e){const t=await e.getLiveStorageValue("settings.chatBatching");de("yt-timed-continuation",me("dataChanged_",(function(){t.value&&(this.data.timeoutMs/=3*Math.random()+2);}),{LudwigOnly:!0})),de("yt-live-chat-renderer",me("preprocessActions_",(function(e){const n=Object.getPrototypeOf(this.smoothedQueue_);for(const e in n)if(e.includes("emitSmoothedMessages")){n[e]=function(){if(this.nextUpdateId_=null,this.messageQueue_.length){let s=1e4;this.estimatedUpdateInterval_&&(s=this.estimatedUpdateInterval_-Date.now()+this.lastUpdateTime_);const o=this.messageQueue_.length<s/80?1:Math.ceil(this.messageQueue_.length/(s/80)),i=this.messageQueue_.splice(0,o);if(this.callback&&this.callback(i[0]),this.messageQueue_.length){let i=1;t.value||(1===o?(i=s/this.messageQueue_.length,i*=Math.random()+.5,i=Math.min(1e3,i),i=Math.max(80,i)):i=80),this.nextUpdateId_=window.setTimeout(n[e].bind(this),i);}}};break}return e}),{LudwigOnly:!0}));}(e),ge(t);}e$2("\n/* Make the masthead transparent unless we are hovering it */\nbody[data-mogul-theater-mode] #masthead-container {\n opacity: 0.1;\n transition: opacity .2s ease;\n}\n\nbody[data-mogul-theater-mode] #masthead-container:hover {\n opacity: 1;\n}\n\n\n@media screen and (min-width: 1014px) {\n /* Make chat fill screen vertically */\n body[data-mogul-theater-mode] #chat.ytd-watch-flexy {\n height: calc(100vh - 56px) !important;\n width: var(--ytd-watch-flexy-sidebar-width);\n position: absolute;\n top: 56px;\n right: 0;\n }\n\n body[data-mogul-theater-mode] #player-theater-container.ytd-watch-flexy {\n width: calc(100vw - var(--ytd-watch-flexy-sidebar-width) - var(--ytd-watch-flexy-scrollbar-width)) !important;\n max-width: calc(100vw - var(--ytd-watch-flexy-sidebar-width) - var(--ytd-watch-flexy-scrollbar-width)) !important;\n height: calc(100vh - 56px) !important;\n max-height: calc(100vh - 56px) !important;\n }\n}");const we=null!==document.querySelector("yt-live-chat-app"),ye=new e$3;if(we){const e=setInterval((()=>{const n$1=n(),s=null==n$1?void 0:n$1.channelId;if(s){clearInterval(e);const t=new oe(ye,s),n=new ne(t),o=new C(t);ve(ye,t,o,n);}}),c.ONE_SECOND_MS);}else {!async function(e){async function t(){const t=document.querySelector("ytd-watch-flexy"),s=(null==t?void 0:t.hasAttribute("theater"))||!1,o=(null==t?void 0:t.hasAttribute("fullscreen"))||!1,i=await e.getStorage("settings.theaterMode"),r=e$1(!1);return s&&!o&&i&&r}let s=await t();setInterval((async()=>{await t()?(document.body.setAttribute("data-mogul-theater-mode",""),s||window.dispatchEvent(new Event("resize")),s=!0):(s=!1,document.body.removeAttribute("data-mogul-theater-mode"));}),250);}(ye),async function(e){if(!window.ytcfg)return;const t={key:window.ytcfg.get("INNERTUBE_API_KEY"),authUser:window.ytcfg.get("SESSION_INDEX"),pageId:window.ytcfg.get("DELEGATED_SESSION_ID"),href:window.location.href,context:window.ytcfg.get("INNERTUBE_CONTEXT")};n=await e$4(Object.assign(Object.assign({},t),{cookies:ie(document.cookie)})),s=await e.fetch("/auth/@me"),(!n.success||!s.meta.isSuccess||n.data.id!==(null===(o=s.body)||void 0===o?void 0:o.sub)||!(null===(i=s.body)||void 0===i?void 0:i.googleId))&&await e.fetch("/auth/login",t);var n,s,o,i;}(ye);const e=new te;e.listen();const s=new se(ye);!async function(e,t,n){if(!window.ytcfg)return;const s={sourceType:"youtube",token:(await e.fetch("/auth/token")).body,version:"3.0.1"};n.setCredentials(s),t.on("cleanup-mappings",(e=>{!function(e){if(e)for(const t of e.values())t.remove();}(e);})),t.on("inject-mappings",(e=>{e.forEach((e=>ce(e,t)));}));}(ye,s,e),setInterval((()=>{const e=document.querySelector("ytd-live-chat-frame iframe");if(e&&!e.src.includes("OpXmfbXQaCyUDUFX")){const n$1=n();e.src+=`#OpXmfbXQaCyUDUFX=${encodeURIComponent(JSON.stringify(n$1))}`;}}),c.ONE_SECOND_MS);}
|