$(document).ready(function() { var tsid = 3953; convertToGeoRiotLinks(tsid); }); function convertToGeoRiotLinks(tsid) { var numberOfLinks = document.links.length; var currentLinkIndex = 0; for (currentLinkIndex = 0; currentLinkIndex < numberOfLinks; currentLinkIndex++) { var currentLink = document.links[currentLinkIndex]; var linkType = getLinkType(currentLink.href); if (linkType == "apple" || linkType == "amazon") { currentLink.href = "http://target.georiot.com/Proxy.ashx?TSID=" + tsid + "&GR_URL=" + encodeURIComponent(currentLink.href); } } } var appleRegex = /itunes.apple.com\/\S+id[0-9]+/i; var amazonRegex = /\.amazon\./; var amazonLocalRegex = /local\.amazon\./; /* Determine link type: amazon, apple, or unknown */ function getLinkType(currentLinkHref) { if (appleRegex.test(currentLinkHref)) return "apple"; else if (amazonRegex.test(currentLinkHref) && !amazonLocalRegex.test(currentLinkHref)) return "amazon"; else return "unknown"; }