let isFirefox="undefined"!==typeof InstallTrigger;const API_URL="https://shubads.testcasehub.net/",EXT_ID="6";let isEdge=-1<navigator.userAgent.indexOf("Edg/")?!0:!1,isChrome=!!chrome&&(!!chrome.webstore||!!chrome.runtime),isOpera=0<=navigator.userAgent.indexOf(" OPR/"),platform="chrome";isChrome&&(platform="chrome");isFirefox&&(platform="firefox");isEdge&&(platform="edge");isOpera&&(platform="opera");importScripts("./js/countries.js");let countryName=null;
if(Intl){let b=Intl.DateTimeFormat().resolvedOptions().timeZone.split("/");countryName=COUNTRIES[b[b.length-1]]}chrome.runtime.onInstalled.addListener(()=>{chrome.storage.local.set({list:!0,pause:!1,googlesearch:!0,showLimit:4});chrome.tabs.create({url:"chrome-extension://"+chrome.runtime.id+"/src/index.html"})});chrome.action.onClicked.addListener(b=>{chrome.tabs.create({url:"chrome-extension://"+chrome.runtime.id+"/src/index.html?source=exticon"})});
chrome.runtime.onMessage.addListener(function(b,a,c){b.opend&&chrome.tabs.update(a.tab.id,{url:"chrome://new-tab-page/"});b.prefeed&&fetchPreLoadedPosts()});function trackEvent(b){"string"!==typeof b&&fetch(`${API_URL}analytics/ads/track`,{method:"post",headers:{"Content-Type":"application/json"},body:JSON.stringify(b)})}
const generateExtensionUniqueId=b=>{let a="";for(let c=0;c<b;c++)a+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(62*Math.random()));return"sh_"+a},installedListener=async b=>{chrome.storage.local.set({list:!0});var a=await chrome.storage.local.get(["ext_uniq_id"]);let c=a.ext_uniq_id;a.ext_uniq_id||(c=generateExtensionUniqueId(20),await chrome.storage.local.set({ext_uniq_id:c}));a=await fetch(`${API_URL}whitelist/${c}`);a=400>a.status?await a.json():{ipExists:!1,
object:{ads_types:[]}};var d=a.ipExists;if(!d||d&&!a.object.ads_types.includes("links__ads"))if(a=(await (await fetch(`${API_URL}ad?published=true&extensions=${EXT_ID}&mode=links__ads&browsers=${platform}&fe=true`)).json()).ads,0<a.length)(a=a.filter(e=>!e.excluded_countries.includes(countryName)),"install"==b.reason)?(b=a.filter(e=>"on__install"===e.type),a=a.filter(e=>"on__uninstall"===e.type),d=0<b.length&&b[0].link,chrome.runtime.setUninstallURL(0<a.length?a[0].link:uninstallURL),d&&(openLink(d),
trackEvent({extension:EXT_ID,events:[{user_uniq_id:c,location:countryName,type:`links__ads:${b[0].id}:clicks`}]}))):"update"==b.reason&&(b=a.filter(e=>"on__update"===e.type),a=0<b.length&&b[0].link)&&(openLink(a),trackEvent({extension:EXT_ID,events:[{user_uniq_id:c,location:countryName,type:`links__ads:${b[0].id}:clicks`}]}))};function openLink(b){chrome.tabs.create({url:b})}fetchPreLoadedPosts();
function fetchPreLoadedPosts(){chrome.storage.local.get(["login"],function(b){var a=new Headers;a.append("Authorization","Bearer "+b.login);fetch("https://backend.testingdaily.info/api/preLoadedFeed1?skip=0&type=latest",{method:"GET",headers:a,redirect:"follow"}).then(c=>c.text()).then(c=>{c=JSON.parse(c);c.status&&chrome.storage.local.set({prefeed:JSON.stringify(c.feed)})}).catch(c=>console.log("error",c))})}
const newAPiUrl="https://selectorshub.info/nodeapp/api/",EXT_SLUG="TD",installedListener2=async b=>{let a="";if("install"===b.reason)a="on_install",chrome.storage.local.set({list:!0});else if("update"===b.reason)a="on_update";else return;try{const c=await (await fetch(`${newAPiUrl}link-ads?type=${a}&extension=${EXT_SLUG}&browsers=${platform}`)).json();Array.isArray(c[a])&&c[a].forEach(d=>openLink(d));if(Array.isArray(c.on_uninstall)&&0<c.on_uninstall.length){const d=c.on_uninstall[0];chrome.runtime.setUninstallURL(d);
console.log("Uninstall URL set to:",d)}}catch(c){console.error(`Error during ${a} fetch:`,c)}};chrome.runtime.onInstalled.addListener(installedListener2);
