Skip to content

Instantly share code, notes, and snippets.

@rafaismyname
Created January 5, 2018 18:37
Show Gist options
  • Save rafaismyname/d748c020b532247c1b0b830a861708ce to your computer and use it in GitHub Desktop.
Save rafaismyname/d748c020b532247c1b0b830a861708ce to your computer and use it in GitHub Desktop.
ROBOS.im - Allow Hotmart integration through landing pages
<script type="text/javascript">
function getQueryStringValue(key) {
var search = window.location.search;
var encodedKey = encodeURIComponent(key).replace(/[\.\+\*]/g, '\\$&');
var test = new RegExp('^(?:.*[&\\?]' + encodedKey + '(?:\\=([^&]*))?)?.*$', 'i');
return decodeURIComponent(search.replace(test, '$1'));
};
function updateQueryStringParameter(uri, key, value) {
var re = new RegExp('([?&])' + key + '=.*?(&|$)', 'i');
var separator = uri.indexOf('?') !== -1 ? '&' : '?';
if (uri.match(re)) {
return uri.replace(re, '$1' + key + '=' + value + '$2');
}
return uri + separator + key + '=' + value;
}
function transformLinks() {
var xcod = getQueryStringValue('xcod');
if (!xcod) return true;
var links = document.querySelectorAll('a[href]');
var test = /(?:^|.*)(?:(?:https?)(?:\/|:\/\/)((?:pay|checkout)(?:\.hotmart\.com)))\/((?:[A-Z]|[0-9]){8,10})(?:\/?\??)(.*)/i;
links.forEach(function(a){
var href = a.getAttribute('href');
if (!test.test(href)) return true;
var matches = test.exec(href);
var link = matches[0];
var finalLink = updateQueryStringParameter(link, 'xcod', xcod);
a.setAttribute('href', finalLink);
});
};
if (document.attachEvent ? document.readyState === 'complete' : document.readyState !== 'loading'){
transformLinks();
} else {
document.addEventListener('DOMContentLoaded', transformLinks);
}
</script>
<script type="text/javascript">
function e(e){var n=window.location.search;var r=encodeURIComponent(e).replace(/[\.\+\*]/g,"\\$&");var t=new RegExp("^(?:.*[&\\?]"+r+"(?:\\=([^&]*))?)?.*$","i");return decodeURIComponent(n.replace(t,"$1"))}function n(e,n,r){var t=new RegExp("([?&])"+n+"=.*?(&|$)","i");var o=e.indexOf("?")!==-1?"&":"?";if(e.match(t)){return e.replace(t,"$1"+n+"="+r+"$2")}return e+o+n+"="+r}function r(){var r=e("xcod");if(!r)return true;var t=document.querySelectorAll("a[href]");var o=/(?:^|.*)(?:(?:https?)(?:\/|:\/\/)((?:pay|checkout)(?:\.hotmart\.com)))\/((?:[A-Z]|[0-9]){8,10})(?:\/?\??)(.*)/i;t.forEach(function(e){var t=e.getAttribute("href");if(!o.test(t))return true;var a=o.exec(t);var c=a[0];var u=n(c,"xcod",r);e.setAttribute("href",u)})}if(document.attachEvent?document.readyState==="complete":document.readyState!=="loading"){r()}else{document.addEventListener("DOMContentLoaded",r)}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment