(function(window, document){ console.log("test: ", window.location.pathname); var el = document.getElementById('smoothie-search-redirects-app-data'); if(el !== null){ // for redirects, if the count changes to 1 or more, then cancel the redirect var count = encodeURIComponent(el.getAttribute('count')); var shop = encodeURIComponent(el.getAttribute('shop')); var query = encodeURIComponent(el.getAttribute('query')); if(query != "" && parseInt(count) == 0){ var xhr = new XMLHttpRequest(); xhr.onload = function() { if (xhr.status === 200) { try{ var redirect = JSON.parse(xhr.responseText).redirect; if(typeof redirect !== 'undefined' && redirect != ''){ window.location.replace(redirect); } } catch(err){} console.log(xhr.responseText); } }; xhr.open('GET', 'https://redirect.smooth.ie/query/' + shop + '/'+ query); xhr.send(); } } })(window, document);