-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathaffililink.js
175 lines (175 loc) · 5.43 KB
/
affililink.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
* Affililink v0.21
* http://affililink.com
* Created by Dean Barrow (http://deanbarrow.co.uk)
*/
var affililink, curronload, newonload;
affililink = function() {
/* enter your affiliate codes below */
var a, addTagToEnd, domain, ebay, ebayCode, host, options, track, universalCode, url, _i, _len, _results;
ebayCode = {
'campaign': 0,
'country': ''
};
universalCode = {
'amazon.co.uk': 'tag=',
'amazon.com': 'tag=',
'amazon.de': 'tag=',
'amazon.fr': 'tag=',
'javari.co.uk': 'tag=',
'javari.de': 'tag=',
'javari.fr': 'tag=',
'amazonsupply.com': 'tag=',
'amazonwireless.com': 'tag=',
'endless.com': 'tag='
};
options = {
'replace_links': true,
'track_views': false,
'track_clicks': true
/* DO NOT EDIT BELOW THIS LINE */
};
track = function() {
if (window.gat_ && window.gat_.getTracker_) {
if (options['track_clicks']) {
url.setAttribute('onclick', "_gaq.push(['_trackEvent', 'Affililink', 'Click', " + url.href + "]);");
}
if (options['track_views']) {
_gaq.push(['_trackEvent', 'Affililink', 'View', url.href]);
}
}
return true;
};
ebay = function() {
var ebayDomain, ebayDomains, _i, _len;
if (ebayCode['campaign'] && ebayCode['country']) {
ebayDomains = ['ebay.com.au', 'ebay.at', 'ebay.be', 'ebay.ca', 'ebay.ch', 'ebay.de', 'ebay.es', 'ebayanuncios.es', 'ebay.fr', 'ebay.ie', 'ebay.it', 'ebay.nl', 'ebay.co.uk', 'ebay.com', 'half.com'];
for (_i = 0, _len = ebayDomains.length; _i < _len; _i++) {
ebayDomain = ebayDomains[_i];
if (!(domain === ebayDomain || domain.substring(domain.length - ebayDomain.length - 1) === '.' + ebayDomain)) {
continue;
}
switch (ebayCode['country']) {
case 'AT':
ebayCode['code'] = '5221-53469-19255-0';
break;
case 'AU':
ebayCode['code'] = '705-53470-19255-0';
break;
case 'BE':
ebayCode['code'] = '1553-53471-19255-0';
break;
case 'CA':
ebayCode['code'] = '706-53473-19255-0';
break;
case 'CH':
ebayCode['code'] = '5222-53480-19255-0';
break;
case 'DE':
ebayCode['code'] = '707-53477-19255-0';
break;
case 'ES':
ebayCode['code'] = '1185-53479-19255-0';
break;
case 'FR':
ebayCode['code'] = '709-53476-19255-0';
break;
case 'IE':
ebayCode['code'] = '5282-53468-19255-0';
break;
case 'IT':
ebayCode['code'] = '724-53478-19255-0';
break;
case 'NL':
ebayCode['code'] = '1346-53482-19255-0';
break;
case 'UK':
ebayCode['code'] = '710-53481-19255-0';
break;
case 'US':
ebayCode['code'] = '711-53200-19255-0';
}
if (domain === 'rover.ebay.com') {
if (options['replace_links']) {
url.href = url.href.replace(/campid=([0-9]+)/g, 'campid=' + ebayCode['campaign']);
url.href = url.href.replace(/rover\/1\/([0-9\-]+)/g, 'rover/1/' + ebayCode['code']);
return true;
} else {
return false;
}
}
if (domain.substring(domain.length - 'half.com'.length) === 'half.com') {
ebayCode['code'] = '8971-56017-19255-0';
}
url.href = 'http://rover.ebay.com/rover/1/' + ebayCode['code'] + '/1?ff3=4&pub=5574962087&toolid=10001&campid=' + ebayCode['campaign'] + '&customid=affililink&mpre=' + encodeURIComponent(url.href);
return true;
}
}
};
addTagToEnd = function(links) {
var link, match, match2, tag;
for (link in links) {
tag = links[link];
if (!(domain === link || domain.substring(domain.length - link.length - 1) === '.' + link)) {
continue;
}
if (!(link && tag)) {
return false;
}
match = tag.match(/([a-zA-Z0-9\-]+)=([a-zA-Z0-9\-]+)/);
if (!match[2]) {
return false;
}
match2 = new RegExp(match[1] + '=([a-zA-Z0-9\-]+)');
if (url.href.search(match2) > -1) {
if (options['replace_links']) {
url.href = url.href.replace(match2, match[1] + '=' + match[2]);
return true;
} else {
return false;
}
}
if (url.href.substring(url.href.length, url.href.length - 1) === '/') {
url.href += '?' + match[1] + '=' + match[2];
return true;
}
if (url.href.match(/(\?)/)) {
url.href += '&' + match[1] + '=' + match[2];
} else {
url.href += '/?' + match[1] + '=' + match[2];
}
return true;
}
};
a = document.getElementsByTagName('a');
host = window.location.hostname;
_results = [];
for (_i = 0, _len = a.length; _i < _len; _i++) {
url = a[_i];
if (!(url.href.substring(0, 7) === 'http://' || url.href.substring(0, 8) === 'https://')) {
continue;
}
domain = url.href.split("/")[2];
if (!domain) {
continue;
} else {
ebay();
addTagToEnd(universalCode);
track();
}
}
return _results;
};
if (window.attachEvent) {
window.attachEvent("onload", affililink);
} else {
if (window.onload) {
curronload = window.onload;
newonload = function() {
curronload; return affililink;
};
window.onload = newonload;
} else {
window.onload = affililink;
}
}