/**
 * VideoPlayer MPD/M3U8/IPTV/EPG
 *
 * @author Sharkiller
 * @license VideoPlayer MPD/M3U8/IPTV/EPG © 2026 by Sharkiller is licensed under CC BY-NC-ND 4.0.
 * To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-nd/4.0/
 */
!function(){const e=()=>{chrome.storage.local.set({enabled:!1}),chrome.action.setIcon({path:"play-off.png"}),chrome.action.setTitle({title:chrome.i18n.getMessage("extension_name")}),chrome.declarativeNetRequest.updateDynamicRules({removeRuleIds:[1,2]}),chrome.declarativeNetRequest.updateSessionRules({removeRuleIds:[1]})},t=()=>{chrome.storage.local.get(["enabled","ignoreDomains"],({enabled:e,ignoreDomains:t})=>{if(!1===e)return;const a=new URL(chrome.runtime.getURL("")).hostname,o=[{id:1,priority:1,action:{type:"redirect",redirect:{regexSubstitution:chrome.runtime.getURL("iptv/player.html")+"#\\0"}},condition:{regexFilter:"^.*\\.m3u(?:\\?|$)",excludedInitiatorDomains:[a],resourceTypes:["main_frame"]}},{id:2,priority:2,action:{type:"redirect",redirect:{regexSubstitution:chrome.runtime.getURL("pages/player.html")+"#\\0"}},condition:{regexFilter:"^.*\\.(mpd|m3u8)(?:\\?|$)",excludedInitiatorDomains:[a],resourceTypes:["main_frame"]}},{id:3,priority:3,action:{type:"redirect",redirect:{regexSubstitution:chrome.runtime.getURL("pages/player.html")}},condition:{regexFilter:"^.*/isInstalled\\.mpd$",excludedInitiatorDomains:[a],resourceTypes:["xmlhttprequest"]}}];if("string"==typeof t&&t.length>1){const e=e=>/^[a-z0-9][a-z0-9-.]+[a-z0-9]$/.test(e)&&!/-{3,}|[.]{2,}|-\.|\.-/.test(e),r=t.split(",").map(e=>e.trim().toLowerCase()).filter(t=>e(t));r.push(a),r.length>1&&(o[0].condition.excludedRequestDomains=r,o[1].condition.excludedRequestDomains=r,o[2].condition.excludedRequestDomains=r)}chrome.declarativeNetRequest.updateDynamicRules({removeRuleIds:[1,2,3],addRules:o})})};chrome.runtime.onMessage.addListener((a,o,r)=>{switch(a.cmd){case"setEnabled":return!1===a.enabled?e():(chrome.storage.local.set({enabled:!0}),chrome.action.setIcon({path:"play-on.png"}),chrome.action.setTitle({title:chrome.i18n.getMessage("extension_name")}),t()),!1;case"updateRules":return t(),!1;case"updateHeadersRules":return(async(e,t)=>{let a={type:"modifyHeaders",responseHeaders:[{operation:"set",header:"access-control-allow-methods",value:"GET, HEAD, OPTIONS"},{operation:"set",header:"access-control-allow-origin",value:"*"}]};!1!==e&&(a.requestHeaders=e);try{return await chrome.declarativeNetRequest.updateSessionRules({removeRuleIds:[t],addRules:[{id:t,priority:1,action:a,condition:{resourceTypes:["xmlhttprequest"],tabIds:[t]}}]}),{success:!0}}catch(e){return{success:!1,error:e.message}}})(a.requestHeaders,o.tab.id);case"openExtensionSetting":return chrome.runtime.openOptionsPage(),!1;case"focusTab":return chrome.tabs.update(o.tab.id,{active:!0}),chrome.windows.update(o.tab.windowId,{focused:!0}),!1;case"isActive":return(async()=>{const e=await chrome.tabs.get(o.tab.id),t=await chrome.windows.get(o.tab.windowId);r({active:e.active,focused:t.focused})})(),!0;default:return!1}}),chrome.runtime.onStartup.addListener(()=>{chrome.storage.local.get("enabled",t=>{!1===t.enabled&&e()})}),chrome.runtime.onInstalled.addListener(({reason:a})=>{switch(a){case chrome.runtime.OnInstalledReason.INSTALL:chrome.storage.local.get("firstRun",({firstRun:e})=>{!0!==e&&(chrome.storage.local.set({firstRun:!0,installDate:Date.now(),enabled:!0,autoLowLatency:!1,audioLang:"en",epgEnabled:!0,epgKeypress:!1,epgDays:1,compressorEnabled:!1,lk:!1,ld:!1,customWV:!1,customWV_data:"domain1.com>https://example1.com/widevine\ndomain2.com>https://example2.com/widevine",customCK:!1,customCK_data:{"11223344556677889900aabbccddeeff":"11223344556677889900aabbccddeeff","223344556677889900aabbccddeeff11":"223344556677889900aabbccddeeff11","3344556677889900aabbccddeeff1122":"3344556677889900aabbccddeeff1122"},ckGetBypass:!1,ckPostCache:10,ignoreDomains:"github.com,mozgcp.net"},e=>{}),t())}),chrome.extension.inIncognitoContext||chrome.tabs.create({url:"pages/welcome.html"});break;case chrome.runtime.OnInstalledReason.UPDATE:chrome.storage.local.get(["enabled","installDate"],({enabled:a,installDate:o})=>{o||chrome.storage.local.set({installDate:"1735700400000"}),!1===a?e():t()}),chrome.extension.inIncognitoContext||chrome.tabs.create({url:"pages/changelog.html"})}})}("undefined"==typeof VideoPlayer?VideoPlayer={}:VideoPlayer);