1/** 2 * Update Amazon links with affiliate tracking parameters. 3 */ 4function tmbiUpdateAmazonLinks() { 5 if ( typeof amazonAffiliateTrackingData === "undefined" || ! amazonAffiliateTrackingData.disclaimer ) { 6 return; 7 } 8 9 var tmbiAmazonAffiliateSource = document.referrer; 10 var tmbiAmazonAffiliateRefUrl = document.location.href; 11 var tmbiAmazonAffiliateLinks = document.getElementsByTagName( "a" ); 12 13 for ( var i = 0; i < tmbiAmazonAffiliateLinks.length; i++ ) { 14 try { 15 var url = new URL( tmbiAmazonAffiliateLinks[i].href ); 16 } 17 catch ( e ) { 18 continue; 19 } 20 var regex = /.*amazon./; 21 22 if ( ! url.hostname.match( regex ) ) { 23 continue; 24 } 25 26 if ( ! url.searchParams.has( "asc_refurl" ) ) { 27 url.searchParams.set( "asc_refurl", tmbiAmazonAffiliateRefUrl ); 28 } 29 30 if ( tmbiAmazonAffiliateSource && ! url.searchParams.has( "asc_source" ) ) { 31 url.searchParams.set( "asc_source", tmbiAmazonAffiliateSource ); 32 } 33 34 tmbiAmazonAffiliateLinks[i].href = decodeURIComponent( url ); 35 } 36} 37 38document.addEventListener( "DOMContentLoaded", function() { 39 tmbiUpdateAmazonLinks(); 40});
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.