Repository navigation
Expand file tree
/
Copy pathbackground.js
More file actions
1 lines (1 loc) · 6.06 KB
/
Copy pathbackground.js
File metadata and controls
1 lines (1 loc) · 6.06 KB
1
(()=>{"use strict";const t={enabledHosts:["https://calendar.google.com/calendar/*","https://outlook.live.com/calendar/*","https://outlook.office.com/calendar/*","https://discord.com/*","https://*.slack.com/*","https://github.com/*","https://*.github.com/*","https://*.start.gg/*","https://liquipedia.net/*","https://*.twitch.tv/*","https://twitch.tv/*","https://www.youtube.com/*"],pausedHosts:{},showInline:!0,showBadge:!0,timeFormat:"system",customHosts:[]},e={dstEpoch:0};function n(e){const n={...t};if(!e||"object"!=typeof e)return n;const o=e;if(Array.isArray(o.enabledHosts)&&(n.enabledHosts=o.enabledHosts.filter(t=>"string"==typeof t)),o.pausedHosts&&"object"==typeof o.pausedHosts){const t={};for(const[e,n]of Object.entries(o.pausedHosts))!0===n&&(t[e]=!0);n.pausedHosts=t}return"boolean"==typeof o.showInline&&(n.showInline=o.showInline),"boolean"==typeof o.showBadge&&(n.showBadge=o.showBadge),"12h"!==o.timeFormat&&"24h"!==o.timeFormat&&"system"!==o.timeFormat||(n.timeFormat=o.timeFormat),Array.isArray(o.customHosts)&&(n.customHosts=o.customHosts.filter(t=>"string"==typeof t)),n}const o="zovo_lte_settings",s="zovo_lte_license",a="zovo_lte_runtime",r="zovo_lte_funnel";function i(){return chrome?.storage?.sync}function c(){return chrome?.storage?.local}async function l(){const e=i();return e?n((await e.get(o))[o]):{...t}}async function u(){const t=c();return t?function(t){const n={...e};if(!t||"object"!=typeof t)return n;const o=t;return"number"==typeof o.dstEpoch&&(n.dstEpoch=o.dstEpoch),"number"==typeof o.prevOffset&&(n.prevOffset=o.prevOffset),n}((await t.get(a))[a]):{...e}}async function d(t){const e={...await u(),...t},n=c();n&&await n.set({[a]:e})}const h=!0===globalThis.__DEV__;function f(...t){h&&console.debug("[LTE]",...t)}function m(...t){console.error("[LTE]",...t)}Number.POSITIVE_INFINITY;const p=["https://calendar.google.com/calendar/*","https://outlook.live.com/calendar/*","https://outlook.office.com/calendar/*","https://discord.com/*","https://*.slack.com/*","https://github.com/*","https://*.github.com/*","https://*.start.gg/*","https://liquipedia.net/*","https://*.twitch.tv/*","https://twitch.tv/*","https://www.youtube.com/*"];function g(){return chrome?.storage?.local}const y="sb_publishable_RG4IVO9Qm23_xPzdQjdFPQ_QHBwbOLv";const w="lte-core",b="lte-dst-tick";async function A(){if(!chrome?.scripting)return;const t=await l(),e=t.enabledHosts.length>0?[...t.enabledHosts]:[...p];try{await chrome.scripting.unregisterContentScripts({ids:[w]})}catch(t){f("unregisterContentScripts (expected on first run):",t)}if(0!==e.length)try{await chrome.scripting.registerContentScripts([{id:w,matches:e,js:["content.js"],css:["content.css"],runAt:"document_idle",allFrames:!1,world:"ISOLATED"}]),f("registered lte-core on",e.length,"hosts")}catch(t){m("registerContentScripts failed:",t)}}function v(){if(!chrome?.alarms)return;const t=new Date,e=new Date(t);e.setHours(3,7,0,0),e.getTime()<=t.getTime()&&e.setDate(e.getDate()+1);const n=(e.getTime()-t.getTime())/6e4;try{chrome.alarms.create(b,{delayInMinutes:n,periodInMinutes:1440})}catch(t){m("alarms.create failed:",t)}}async function _(t){try{const e=await async function(t){const e=String(t||"").trim();if(e.length<8)return{active:!1,expiresAt:null,lastVerifiedAt:0,reason:"invalid-format"};const n=new AbortController,o=setTimeout(()=>n.abort(),1e4);try{const t=await fetch("https://zgubxqomnbmxgbdhvwja.supabase.co/functions/v1/verify-extension-license",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${y}`,apikey:y},body:JSON.stringify({license_key:e,extension:"lte_pro",product:"lte"}),signal:n.signal});if(!t.ok)return{active:!1,expiresAt:null,lastVerifiedAt:0,reason:`http-${t.status}`};const o=await t.json();if(!o||"object"!=typeof o)return{active:!1,expiresAt:null,lastVerifiedAt:0,reason:"bad-schema"};const s=!0===o.valid||"pro"===o.tier||"trial"===o.tier,a="number"==typeof o.expiresAt?o.expiresAt:"number"==typeof o.trialEndsAt?o.trialEndsAt:null;return{active:Boolean(s),expiresAt:a,lastVerifiedAt:Date.now()}}catch(t){return{active:!1,expiresAt:null,lastVerifiedAt:0,reason:t&&"AbortError"===t.name?"timeout":"network"}}finally{clearTimeout(o)}}(t),n={active:e.active,expiresAt:e.expiresAt,lastVerifiedAt:e.lastVerifiedAt||Date.now(),productId:"lte",extensionKey:"lte_pro"};return await async function(t){const e=c();e&&await e.set({[s]:t})}(n),n}catch(t){return m("license verify failed:",t),{active:!1,expiresAt:null,lastVerifiedAt:0,productId:"lte",extensionKey:"lte_pro"}}}chrome.runtime.onInstalled.addListener(async t=>{await async function(){const t=await l();t.enabledHosts&&0!==t.enabledHosts.length||await async function(t){const e={...await l(),...t},n=i();return n&&await n.set({[o]:e}),e}({...t,enabledHosts:[...p]})}(),await A(),v(),"install"===t.reason&&(await async function(){try{await chrome.tabs.create({url:chrome.runtime.getURL("pages/onboarding/onboarding.html")})}catch(t){m("openOnboarding failed:",t)}}(),await async function(t,e){const n=g();if(n)try{const o=await async function(){const t=g();if(!t)return[];const e=(await t.get(r))[r];return Array.isArray(e)?e:[]}(),s={name:t,ts:Date.now()};e&&(s.meta=e);const a=[...o,s],i=a.length>100?a.slice(a.length-100):a;await n.set({[r]:i})}catch{}}("install",{productId:"lte"}))}),chrome.runtime.onStartup.addListener(async()=>{await A(),v()}),A(),chrome?.alarms?.onAlarm&&chrome.alarms.onAlarm.addListener(t=>{t.name===b&&async function(){const t=(new Date).getTimezoneOffset(),e=(await u()).prevOffset;await d({prevOffset:t}),"number"==typeof e&&e!==t&&(await d({dstEpoch:Date.now()}),f("DST boundary crossed:",e,"->",t))}()}),function(){if(!chrome?.storage?.onChanged)return()=>{};chrome.storage.onChanged.addListener((t,e)=>{"sync"===e&&o in t&&(n(t[o]?.newValue),A())})}(),function(){if(!chrome?.runtime?.onMessage)return()=>{};chrome.runtime.onMessage.addListener((t,e,n)=>{if(!t||"object"!=typeof t)return;const o=t;if(!o.action||!o.action.startsWith("LTE_"))return;const s=(t=>"LTE_VERIFY_LICENSE"===t.action?_(t.payload.key):"LTE_HOSTS_CHANGED"===t.action?(A(),{ok:!0}):void 0)(t);if(s instanceof Promise)return s.then(t=>n(t)).catch(()=>n(void 0)),!0;void 0!==s&&n(s)})}()})();