ThinkGeek Affiliate Helper Bookmarklet
This was a tool I put together to get people to use my ThinkGeek Affiliate account when they shop on ThinkGeek. If you want to tweak it for your own affiliate account, just change the first variable value.
by Adam Patridge
October 21, 2011
HTML
<p class="result"></p>
<script type="text/javascript">
var tools = {},
resultOutput;
tools.getByClassName = function(className) {
var allElements = document.getElementsByTagName('*'),
foundElements = [],
i;
for (i in allElements) {
if ((" " + allElements[i].className + " ").indexOf(" " + className + " ") > -1) {
foundElements.push(allElements[i]);
}
}
return foundElements;
};
resultOutput = tools.getByClassName("result")[0];
</script>
JavaScript
(function() {
var urlToProcess = "http://www.thinkgeek.com/geektoys/plush/e943/?pfm=homepage_Featured_3", //window.location,
affiliateUrlBase = 'http://www.anrdoezrs.net/click-5456339-10746449?url=',
affiliateUrl = (function(url) {
var anchorOfUrl = document.createElement('a'),
isThinkGeek,
resultUrl;
anchorOfUrl.href = url;
// vague to allow m. and www.
isThinkGeek = anchorOfUrl.host.indexOf('thinkgeek.com') !== -1;
if (isThinkGeek) {
resultUrl = affiliateUrlBase + encodeURIComponent(anchorOfUrl.href);
}
else {
resultUrl = affiliateUrlBase + encodeURIComponent('http://www.thinkgeek.com/');
}
return resultUrl;
}(urlToProcess));
resultOutput.innerHTML = affiliateUrl;
//window.location = affiliateUrl;
}());