1/* Geo-resolver 1.1.1 */ 2(function($){var localStorageKey='wpaal';$(document).ready(function(){if('undefined'===typeof aalGeoResolver){return} 3debugLog('aalGeoResolver',aalGeoResolver);convertAmazonLinksByGeolocation(getJSONObjectCloned(aalGeoResolver.apiProviders))});$('body').on('aal_ajax_loaded_unit',function(event){convertAmazonLinksByGeolocation(getJSONObjectCloned(aalGeoResolver.apiProviders))});var ajaxAPIHandlers={'__base':{dataType:'json',success:function(response){debugLog('response',response);var _sAmazonLocale=this.getAmazonLocale(response);setLocalStorageTTL(localStorageKey,{locale:_sAmazonLocale,time:getTimestampInSeconds()});convertLinks(_sAmazonLocale)},countryCodeKey:'countryCode',getAmazonLocale:function(response){return'undefined'===typeof response[this.countryCodeKey]?'':response[this.countryCodeKey]}},'cloudflare':{dataType:'text',success:function(response){debugLog('response',response);var _data={};var _aText=response.split('\n');for(var i=0;i<_aText.length;i++){var _aKeyValue=_aText[i].split('=');if(_aKeyValue[0]&&('undefined'!==typeof _aKeyValue[1])){_data[_aKeyValue[0]]=_aKeyValue[1]}} 4if(!_data.loc){return} 5setLocalStorageTTL(localStorageKey,{locale:_data.loc,time:getTimestampInSeconds()});convertLinks(_data.loc)},}} 6function convertAmazonLinksByGeolocation(aAPIProviders){if(!getObjectLength(aalGeoResolver.availableLocales)){debugLog('No available locale. Do nothing.');return} 7var localCache=getLocalStorageTTL(localStorageKey,86400*7);debugLog('Stored cache:',localCache);if(localCache&&'undefined'!==typeof localCache.locale){convertLinks(localCache.locale);return} 8debugLog('Not using cache');var _sProviderKey=getRandomPropertyKey(aAPIProviders);
8var _aProvider=aAPIProviders[_sProviderKey];delete aAPIProviders[_sProviderKey];if(!_aProvider){debugLog('No more APIs');return} 9debugLog('API Provider:',_aProvider);var _aAjaxHandler={'url':_aProvider.endpoint,'countryCodeKey':_aProvider.countryCodeKey};var _aAjaxHandlerByProvider=ajaxAPIHandlers.hasOwnProperty(_sProviderKey)?ajaxAPIHandlers[_sProviderKey]:{};_aAjaxHandler=$.extend({},ajaxAPIHandlers.__base,_aAjaxHandlerByProvider,_aAjaxHandler);$.ajax(_aAjaxHandler).error(function(jqXHR,textStatus,errorThrown){debugLog('response error',jqXHR);convertAmazonLinksByGeolocation(aAPIProviders)})} 10function getRandomPropertyKey(obj){var keys=Object.keys(obj);return keys[keys.length*Math.random()<<0]} 11function convertLinks(sLocaleCode,sSelector){var _oLocale=aalGeoResolver.availableLocales.hasOwnProperty(sLocaleCode)?aalGeoResolver.availableLocales[sLocaleCode]:aalGeoResolver.availableLocales[aalGeoResolver.defaultLocale];var bNonPluginLinks=aalGeoResolver.non_plugin_links;var sQueryKey=aalGeoResolver.queryKey;debugLog('Detected locale',sLocaleCode,_oLocale);var _sLocaleDomain=_oLocale.domain.replace(/^www\./,'');var _sSelector=sSelector?sSelector:parseInt(bNonPluginLinks)?'a':'.amazon-auto-links a';debugLog('Target Selector >>>',_sSelector,'<<< Locale Domain >>>',_sLocaleDomain,'<<<');var _oHrefs=$(_sSelector).filter(function(){if(!this.href){return!1} 12if(-1!==this.href.indexOf(_sLocaleDomain)){return!1} 13if(this.href.match(/https?:\/\/(\w+\.?)amazon\./)){return!0} 14var _regexPattern=sQueryKey+'\=.+locale\=';var _regex=new RegExp(_regexPattern);if(this.href.match(_regex)){return!0} 15return!1});var _aUnmodified=[];var _aModified=[];_oHrefs.each(function(index){var _match=this.href.match(/.+\/([A-Z0-9]{10})/);if(_match){this.href='undefined'!==typeof _match[1]?_oLocale.searchURL+_match[1]:this.href;_aModified.push(this.href);$(this).children('img[data-href]').attr('data-href',_oLocale.searchURL+_match[1]) 16return!0} 17var _regexPattern=sQueryKey+'\=(.+?)&locale\=(.+)';var _regex=new RegExp(_regexPattern);_match=this.href.match(_regex);if(_match){var _sURL=getQueryStringAndHashStrippedFromPath(this.href);this.href=_sURL+'?'+sQueryKey+'='+_match[1]+'&locale='+_oLocale.locale+'&tag='+_oLocale.associateID+'&search=1';_aModified.push(this.href);return!0} 18if(-1!==this.href.indexOf('aws/cart/add.html')){this.href=this.href.replace(/^(https?:\/\/)(www\.amazon\..+?)(\W.+)/,'$1'+_oLocale.domain+'$3');this.href=this.href.replace(/(?<=AssociateTag=)(.+-\d{2}?)(?=\W)/,_oLocale.associateID);_aModified.push(this.href);return!0} 19_aUnmodified.push(this.href)});debugLog('hrefs found:',_oHrefs.length,'modified: ',_aModified.length);debugLog(_aUnmodified)} 20function getQueryStringAndHashStrippedFromPath(url){return url.split("?")[0].split("#")[0]} 21function getLocalStorage(key){var localCache=localStorage.getItem(localStorageKey);if(localCache){return JSON.parse(localCache)} 22return{}} 23function setLocalStorage(key,value){debugLog('setting local storage:',key,value);localStorage.setItem(key,JSON.stringify(value))} 24function setLocalStorageTTL(key,value){debugLog('setting local storage:',key,{value:value,time:getTimestampInSeconds()});localStorage.setItem(key,JSON.stringify({value:value,time:getTimestampInSeconds()}))} 25function getLocalStorageTTL(sKey,iLifespan){var _value=getLocalStorage(sKey);if('undefined'===typeof _value.time||'undefined'===typeof _value.value){return{}} 26var _iStoredTime=parseInt(_value.time);_iStoredTime=_iStoredTime?_iStoredTime:0;if(_iStoredTime+iLifespan<getTimestampInSeconds()){debugLog('Local storage c
26ache timed out',_iStoredTime,iLifespan,_iStoredTime+iLifespan,getTimestampInSeconds());return{}} 27return _value.value} 28function getTimestampInSeconds(){return Math.floor(Date.now()/1000)} 29function debugLog(...args){if(!parseInt(aalGeoResolver.debugMode)){return} 30console.log('AAL Debug(Geotargeting):',...args)} 31function getJSONObjectCloned(jsonObj){return JSON.parse(JSON.stringify(jsonObj))} 32function getObjectLength(obj){var size=0,key;for(key in obj){if(obj.hasOwnProperty(key))size++} 33return size}}(jQuery))
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.