import{n as e}from"../assets/chunk-BVfgdVh5.js";import{Pt as t,i as n,n as r,t as i}from"../assets/video-platforms-CAHJOg_P.js";import{_ as a,c as o,d as s,g as c,h as l,i as u,m as d,p as f,r as p,s as m}from"../assets/navigation-DThsntKi.js";var h,g,_,v,y,b,x,S,C;e((()=>{n(),a(),p(),m(),f(),i(),h=`agreement-reminder`,(async()=>{let e=(await chrome.declarativeNetRequest.getDynamicRules()).map(e=>e.id),t=[{id:1,priority:1,action:{type:`modifyHeaders`,responseHeaders:[{header:`Timing-Allow-Origin`,operation:`set`,value:`*`}]},condition:{initiatorDomains:r.map(e=>e.replace(/^\*\./,``))}},{id:2,priority:1,action:{type:`modifyHeaders`,responseHeaders:[{header:`Content-Security-Policy`,operation:`remove`}]},condition:{regexFilter:`^https://.+\\.youtube(-nocookie)?\\.com/`,resourceTypes:[`main_frame`,`sub_frame`]}}];await chrome.declarativeNetRequest.updateDynamicRules({removeRuleIds:e,addRules:t})})(),chrome.webRequest.onResponseStarted.addListener(async e=>{let t=new URL(e.url);if(t.host&&e.ip){let n=await d.get(`hostToIp`)||{};await d.set(`hostToIp`,{...n,[t.host]:e.ip})}},{urls:[`<all_urls>`]},[`responseHeaders`]),g=async()=>{let e=await d.get(`AgreedTerm`),n=chrome.action??chrome.browserAction;e?n.setPopup({popup:`/index.html#/popup`}):t(o)?n.setPopup({popup:`/index.html#/onboarding`}):n.onClicked.addListener(()=>u(`#/onboarding`))},g(),_=async e=>{let t=Object.entries(e).filter(([e])=>e.match(/^\d+$/)),n=[],r=[];t.forEach(([e,t])=>{let i=Number(e),{session_id:a,video_id:o,user_agent:s,location:c,media_size:l,domain_name:u,start_time:d,end_time:f,thumbnail:p,title:m,calc:h,qoe:g,transfer_size:_,log:v}=t;n.push([i,{sessionId:a,playbackId:o,userAgent:s,location:c,mediaSize:l,domain:u,startTime:d,endTime:f,thumbnail:p,title:m,calculable:h,qoe:g}]),r.push([i,{transferSize:_,logs:v}])}),await Promise.all([l.saveEntries(n),c.saveEntries(r)]),await d.delete([`index`,...t.map(([e])=>e)])},chrome.runtime.onInstalled.addListener(async({reason:e})=>{if(e===`install`&&u(`#/onboarding`),e===`update`){let e=await d.getAll()||{},{version:t,AgreedTerm:n=!1}=e;t&&t<s&&(await d.clear(),await d.set(`AgreedTerm`,n)),e.index&&_(e)}}),v=async()=>{let e=await d.get(`settings`);return e===null||e.display_on_player===null||e.display_on_player},y={},b=async e=>{if(typeof y[e]==`string`||Number.isFinite(y[e]))return y[e];let t=await l.keys()??[],n=t.length?t.sort((e,t)=>Number(e)-Number(t)).pop()+1:0;return y[e]=n,n},x={updatePlaybackInfo:async(e,t)=>{C(e.id,!!t)},updateHistory:async(e,{id:t,data:n})=>{if(!t||!n)return;let r=await b(t);`logs`in n||`transferSize`in n?await c.set(r,n):await l.set(r,n)},setDisplayOnPlayer:async(e,t)=>{let n=await d.get(`tabStatus`)||{},r=n[e.id]||{};r.displayOnPlayer=t,await d.set(`tabStatus`,{...n,[e.id]:r})},getDisplayOnPlayer:async e=>{let{displayOnPlayer:t}=(await d.get(`tabStatus`)||{})[e.id]||{};return t===void 0&&(t=await v()),{displayOnPlayer:t}},getPlatformInfo:async()=>({platformInfo:await new Promise(e=>{chrome.runtime.getPlatformInfo(e)})}),getIp:async(e,t)=>({ip:(await d.get(`hostToIp`)||{})[t]}),showAgreementReminder:async()=>{await chrome.notifications.clear(h),await chrome.notifications.create(h,{type:`basic`,iconUrl:`/images/icons/videomark-128.png`,title:chrome.i18n.getMessage(`agreementReminderTitle`),message:chrome.i18n.getMessage(t(o)?`agreementReminderMessageMobile`:`agreementReminderMessageDesktop`)})}},chrome.notifications.onClicked.addListener(e=>{e===h&&(u(`#/onboarding`),chrome.notifications.clear(e))}),S={getTabStatus:async e=>{let t=(await d.get(`tabStatus`)||{})[e]||{};return t.displayOnPlayer===void 0&&(t.displayOnPlayer=await v()),t}},C=async(e,t)=>{let n=await d.get(`tabStatus`)||{},r=n[e]||{};r.alive!==t&&(r.alive=t,await d.set(`tabStatus`,{...n,[e]:r}),(chrome.action??chrome.browserAction).setIcon({tabId:e,path:t?`/images/icons/enabled.png`:`/images/icons/disabled.png`}))},chrome.runtime.onMessage.addListener((e,t,n)=>{let{method:r,args:i=[]}=e,{tab:a}=t;return r?((async()=>{n((a?await x[r].apply(null,[a,...i]):await S[r].apply(null,[...i]))||{})})(),!0):!1}),chrome.tabs.onRemoved.addListener(async e=>{let t=await d.get(`tabStatus`)||{};delete t[e],await d.set(`tabStatus`,t)}),chrome.runtime.setUninstallURL(`https://videomark.webdino.org/offboarding`)}))();