PageSourceSearch

https://softwarediscountusa.com/cdn/shop/t/37/assets/currency-engine.js?v=45026668462995871581790857759

js softwarediscountusa.com collected 2026-10-07 01:13:58 UTC 4,351 bytes, 2 lines download raw bytes

1window.CurrencyEngine=(function(){const STORAGE_KEY="currency_preference",RATES_KEY="currency_rates_cache";let config={enabled:!1,autoDetect:!1,defaultCurrency:"USD",currentCurrency:"USD",exchangeRates:{},supportedCurrencies:[]},isInitialized=!1,observer=null;async function init(options){if(config=Object.assign({},config,options),config.supportedCurrencies&&(config.supportedCurrencies=config.supportedCurrencies.map(c=>(c||"").trim())),!config.enabled)return;let cachedRates=null;try{const stored=localStorage.getItem(RATES_KEY);if(stored){const parsed=JSON.parse(stored);Date.now()-parsed.timestamp<864e5&&(cachedRates=parsed.rates,config.exchangeRates=cachedRates)}}catch{console.warn("CurrencyEngine: Failed to read cached rates")}let ratesPromise=null;cachedRates||(ratesPromise=fetch("https://download.softwarediscountusa.com/api/exchange-rates").then(res=>res.json()).then(data=>{if(data&&data.success&&data.data){const newRates={};data.data.forEach(item=>{newRates[item.currency_code]=parseFloat(item.rate_vs_usd)}),config.exchangeRates=newRates,localStorage.setItem(RATES_KEY,JSON.stringify({timestamp:Date.now(),rates:newRates}))}}).catch(e=>console.error("CurrencyEngine: Failed to fetch exchange rates",e)));const savedCurrency=localStorage.getItem(STORAGE_KEY);let ipapiPromise=null;savedCurrency&&config.supportedCurrencies.includes(savedCurrency)?config.currentCurrency=savedCurrency:config.autoDetect?ipapiPromise=fetch("https://ipapi.co/currency/").then(res=>res.text()).then(code=>{const trimmedCode=code?code.trim():"";trimmedCode&&config.supportedCurrencies.includes(trimmedCode)?(config.currentCurrency=trimmedCode,localStorage.setItem(STORAGE_KEY,trimmedCode)):config.currentCurrency=config.defaultCurrency}).catch(()=>{config.currentCurrency=config.defaultCurrency}):config.currentCurrency=config.defaultCurrency;const promisesToWait=[];ratesPromise&&promisesToWait.push(ratesPromise),ipapiPromise&&promisesToWait.push(ipapiPromise),promisesToWait.length>0&&await Promise.all(promisesToWait),config.currentCurrency!==config.defaultCurrency&&!config.exchangeRates[config.currentCurrency]&&(config.currentCurrency=config.defaultCurrency),isInitialized=!0,convertContainer(document.body),document.querySelectorAll(".currency-engine-select").forEach(select=>{select.value=config.currentCurrency}),document.dispatchEvent(new CustomEvent("currency:changed",{detail:config.currentCurrency})),setupObserver()}function setCurrency(code){config.enabled&&(config.currentCurrency=code,localStorage.setItem(STORAGE_KEY,code),convertContainer(document.body),document.querySelectorAll(".currency-engine-select").forEach(select=>{select.value=code}),document.dispatchEvent(new CustomEvent("currency:changed",{detail:code})))}function getCurrency(){return config.currentCurrency}function refresh(){convertContainer(document.body)}function convertContainer(container){if(!config.enabled||!isInitialized||!container)return;(container.querySelectorAll?container.querySelectorAll("[data-cents]"):[]).forEach(convertElement),container.hasAttribute&&container.hasAttribute("data-cents")&&convertElement(container)}function convertElement(element){if(!config.enabled||!isInitialized)return;const centsAttr=element.getAttribute("data-cents");if(!centsAttr)return;const cents=parseInt(centsAttr.replace(/[^0-9]/g,""),10);if(isNaN(cents))return;const rate=config.exchangeRates[config.currentCurrency]||1,convertedValue=Math.round(cents*rate)/100;let formatted;try{formatted=new Intl.NumberFormat(void 0,{style:"currency",currency:config.currentCurrency,currencyDisplay:"narrowSymbol"}).format(convertedValue)}catch{formatted="$"+convertedValue.toFixed(2)}const htmlContent=`<span class="money">${formatted}</span>`;element.innerHTML!==htmlContent&&(element.innerHTML=htmlContent)}function setupObserver(){observer&&observer.disconnect(),observer=new MutationObserver(mutations=>{let newNodes=[];mutations.forEach(mutation=>{mutation.type==="childList"&&mutation.addedNodes.forEach(node=>{node.nodeType===1&&newNodes.push(node)})}),newNodes.length>0&&requestAnimationFrame(()=>{newNodes.forEach(node=>{convertContainer(node)})})}),observer.observe(document.body,{childList:!0,subtree:!0})}return{init,setCurrency,getCurrency,refresh,convertContainer}}
1)();
2//# sourceMappingURL=/cdn/shop/t/37/assets/currency-engine.js.map?v=45026668462995871581790857759

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.