import { e } from '../../index-6137f488.js'; import { e as e$2 } from '../../background.injected-af36b849.js'; import { n, e as e$4 } from '../../get_stream_details-b6177000.js'; import { d as dt, t } from '../../parse_token.util-ed270559.js'; import { e as e$3 } from '../../fetch_youtube-71c76849.js'; import { s } from '../../router.interface-6cdbc015.js'; import { e as e$1 } from '../../style-inject.es-a0e1a0ba.js'; function u(t){if(!t)return 0;t=t.toLowerCase();const e=/\((.+)\)/.exec(t);if(!e)return 1;const n=e[1].split(/\s/),i=parseInt(n[0]);return isNaN(i)?0:n[1].startsWith("year")?12*parseInt(n[0]):parseInt(n[0])}function d(t,e){const n=e;for(let e=0;et)return n[e-1][1];return n[n.length-1][1]}function l(t,e,n,i){const a=e(t.authorExternalChannelId);!function(t,e){(null==e?void 0:e.a)&&(t.authorName={simpleText:e.a});}(t,a),function(t,e){var n,i;t.authorBadges||(t.authorBadges=[]);for(const a of t.authorBadges){const t=a.liveChatAuthorBadgeRenderer;(null===(n=t.icon)||void 0===n?void 0:n.iconType)?t._mtvType=null===(i=t.icon)||void 0===i?void 0:i.iconType.toLowerCase():t.customThumbnail&&(t._mtvType="member"),"moderator"===t._mtvType&&(delete t.icon,t._mtvType="moderator",t.customThumbnail={thumbnails:[{url:e,width:18,height:18}]});}}(t,i),function(t,e,n){if((null==n?void 0:n.b)&&!(n.b<=0))for(const i of t.authorBadges){const t=i.liveChatAuthorBadgeRenderer;if("member"!==t._mtvType)continue;const a=u(t.tooltip);if(0===a)continue;const o=a+n.b,r=`Member (${o} months)`,s=d(o,e);t.customThumbnail=s,delete t.icon,t.tooltip=r,t.accessibility.accessibilityData.label=r;}}(t,n,a);}const h=/[\s.,?!]/;function f(t){const e=[];let n=0;for(let i=0;ithis.gatewayService.getUserInfo(t)),this.gatewayService.badgeList,"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAASCAYAAABWzo5XAAABg2lDQ1BJQ0MgcHJvZmlsZQAAKJF9kT1Iw0AcxV/TiiIVBzuIOGRonSyIijpqF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ougE+Pl+6FKGijukGtWesZUZBZT5NcT2KdWT0hl8O2AK9ZT8M6xAZjzO8v3PFLkmVBTpsFuQgi2Nu/Ji3QXv0FPBynaffELJkAAAAASUVORK5CYII=");}}class T{constructor(t){this.gatewayService=t;}addTwitchEmotesToMessage(t){return function(t,e){const n=[];for(const i of t.runs)if("string"==typeof i.text){const{text:t}=i;let a=0,o=0;const r=f(t);let s=!1;for(const i of r){const r=e("🌝"===i?"Kappa":i);r&&(s=!0,a>0&&n.push({text:t.substring(o,a)}),n.push({emoji:r}),o=a+i.length),a+=i.length;}s?n.push({text:t.substring(o,a)}):n.push(i);}else if("🌝"===i.emoji.emojiId){const t=e("Kappa");t&&n.push({emoji:t});}else n.push(i);return t.runs=n,t}(t,(t=>this.gatewayService.getEmote(t)))}}class x extends e.exports.EventEmitter{constructor(t){super(),this.backgroundService=t,this.badgeList=[],this.emoteCache=new Map,t.getLiveStorageValue("auth.token",dt).then((t=>this.myUserInfo=t)),this.fetchUserInfo(),this.fetchEmotes(),this.fetchBadges(),setInterval((()=>{this.fetchUserInfo(),this.fetchEmotes(),this.fetchBadges();}),3e5);}async fetchBadges(){const t=await this.backgroundService.fetch("/gateway/badges");if(!s(t))return;const e=t.body.sort(((t,e)=>t.months-e.months));this.badgeList=e.map((t=>[t.months,{thumbnails:[{url:t.url,width:16,height:16}]}])),this.emit("badges",this.badgeList);}async fetchEmotes(){const t=await this.backgroundService.fetch("/gateway/emotes");if(s(t)){this.emoteCache.clear();for(const e of t.body){const t=m(e);t&&this.emoteCache.set(e.name,t);}this.emit("emotes",this.emoteCache);}}async fetchUserInfo(){const t=await this.backgroundService.fetch("/gateway/users");s(t)&&(this.infoCache=new Map(t.body),this.emit("users",this.infoCache));}getSerializedMetadata(t){const e=t.links.find((e=>e.prv===t.prv)),n={a:null==e?void 0:e.name,b:t.meta.sub,c:t.meta.col};return Object.values(n).filter((t=>void 0!==t)).length>0?n:void 0}getUserInfo(t){var e,n,i;if((null===(n=null===(e=this.myUserInfo)||void 0===e?void 0:e.value)||void 0===n?void 0:n.sub)===t){const t=this.getSerializedMetadata(this.myUserInfo.value);if(t)return t}return null===(i=this.infoCache)||void 0===i?void 0:i.get(t)}getEmote(t){var e;return null===(e=this.emoteCache)||void 0===e?void 0:e.get(t)}}async function I(t,n){await customElements.whenDefined(t);const i=customElements.get(t);if(!i)return void console.warn(`Polymer: ${t} not found`);const a=i.prototype[n.functionName];i.prototype[n.functionName]=function(...t){if(n.ludwigOnly&&!e$4())return a.apply(this,t);if(n.type===b.OverrideFunction)try{return n.function.apply(this,t)}catch(t){console.error(JSON.stringify(n)),console.error(t);}if(n.type===b.RunBefore)try{n.function.apply(this,t);}catch(t){console.error(t);}let i=a.apply(this,t);if(n.type===b.RunAfter)try{i=n.function.apply(this,[i]);}catch(t){console.error(t);}return i};}!function(t){t[t.OverrideFunction=0]="OverrideFunction",t[t.RunBefore=1]="RunBefore",t[t.RunAfter=2]="RunAfter";}(b||(b={}));const B=(t,e,{LudwigOnly:n})=>({functionName:t,function:e,ludwigOnly:n||!1,type:b.OverrideFunction}),E=(t,e,{LudwigOnly:n})=>({functionName:t,function:e,ludwigOnly:n||!1,type:b.RunBefore});function C(t,n,i){I("yt-live-chat-item-list-renderer",E("handleAddChatItemAction_",(function(e){e.item.liveChatTextMessageRenderer&&(t.addTwitchEmotesToMessage(e.item.liveChatTextMessageRenderer.message),n.addAliasesToMessage(e.item.liveChatTextMessageRenderer));}),{LudwigOnly:true})),I("yt-live-chat-text-input-field-renderer",((t,e,{LudwigOnly:n})=>({functionName:t,function:e,ludwigOnly:n||!1,type:b.RunAfter}))("calculateLiveChatRichMessageInput_",(function(t){var e;if(!(null==t?void 0:t.textSegments))return t;for(const n of t.textSegments)if(null===(e=n.emojiId)||void 0===e?void 0:e.startsWith("mogultv")){const[,t]=n.emojiId.split("-");delete n.emojiId,n.text=t;}return t}),{LudwigOnly:true})),i.on("emotes",(t=>{if(!e$4())return;const n=document.querySelector("yt-live-chat-item-list-renderer");if(null==n?void 0:n.emojiManager){if(n.emojiManager._mogulTvLoaded)return;n.emojiManager._mogulTvLoaded=!0,n.emojiManager.load([...t.values()]);}else console.warn("Cannot find chat list");}));}function S(t){return t?t._mtvType?t._mtvType:t.icon?t.icon.iconType.toLowerCase():t.customThumbnail?"member":"":""}async function M(t){I("yt-live-chat-author-badge-renderer",B("computeType_",(t=>S(t.liveChatAuthorBadgeRenderer)),{LudwigOnly:true})),I("yt-live-chat-author-chip",B("computeAuthorType_",(function(e){var n,i;const a=this.$["author-name"];if(a){let e;const o=null===(n=this.parentElement)||void 0===n?void 0:n.parentElement,r=null===(i=null==o?void 0:o.data)||void 0===i?void 0:i.authorExternalChannelId;if(r){const n=t.getUserInfo(r);(null==n?void 0:n.c)&&(e=n.c);}e||(e=function(t){const e=function(t){let e=0;if(0===t.length)return 0;for(let n=0;n{await n()?(document.body.setAttribute("data-mogul-theater-mode",""),i||window.dispatchEvent(new Event("resize")),i=!0):(i=!1,document.body.removeAttribute("data-mogul-theater-mode"));}),250);}(j),async function(t){if(!window.ytcfg)return;const e={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$3(Object.assign(Object.assign({},e),{cookies:v(document.cookie)})),i=await t.fetch("/auth/@me"),(!n.success||!i.meta.isSuccess||n.data.id!==(null===(a=i.body)||void 0===a?void 0:a.sub))&&await t.fetch("/auth/login",e);var n,i,a;}(j),setInterval((()=>{const t=document.querySelector("ytd-live-chat-frame iframe");if(t&&!t.src.includes("QXZRwEzaeHNfDqtD")){const e=n();t.src+=`#QXZRwEzaeHNfDqtD=${encodeURIComponent(JSON.stringify(e))}`;}}),1e3);var L,O;