-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheventPage.js
98 lines (84 loc) · 2.32 KB
/
eventPage.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
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if(request.action == "show") {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
chrome.pageAction.show(tabs[0].id);
});
}
});
function replaceUrlParam(url, paramName, paramValue)
{
if (paramValue == null) {
paramValue = '';
}
var pattern = new RegExp('\\b('+paramName+'=).*?(&|$)');
if (url.search(pattern)>=0) {
return url.replace(pattern,'$1' + paramValue + '$2');
}
url = url.replace(/\?$/,'');
return url + (url.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue;
}
var tagMap = [
[".com.au", "interior0016b-22"], // Australia must be checked before US, because .com is a substring of .com.au
[".com", "interior0d3-20"],
[".co.uk", "interior02-21"],
[".de", "interior065-21"],
[".fr", "interior04-21"],
[".es", "interior03-21"],
[".ca", "interior04e-20"],
[".in", "interior0b65-21"],
[".it", "interior0b3-21"]
// I don't think Japan will work
// Brazil and Mexico will not accept US address
];
function getTag(url){
for (var i=0; i < tagMap.length; i++){
var values = tagMap[i];
var tld = values[0];
var tag = values[1];
if (url.indexOf(tld) != -1){
return tag;
}
}
return "";
}
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.url.indexOf("/dp/") != -1 || details.url.indexOf("/gp/") != -1){
return {
redirectUrl: replaceUrlParam(details.url, "tag", getTag(details.url))
}
}
return {
redirectUrl: details.url
};
},
{
urls: [
"*://amazon.com/*",
"*://www.amazon.com/*",
"*://smile.amazon.com/*",
"*://amazon.co.uk/*",
"*://www.amazon.co.uk/*",
"*://smile.amazon.co.uk/*",
"*://amazon.de/*",
"*://www.amazon.de/*",
"*://smile.amazon.de/*",
"*://amazon.fr/*",
"*://www.amazon.fr/*",
"*://amazon.es/*",
"*://www.amazon.es/*",
"*://amazon.it/*",
"*://www.amazon.it/*",
"*://amazon.co.jp/*",
"*://www.amazon.co.jp/*",
"*://amazon.ca/*",
"*://www.amazon.ca/*",
"*://amazon.in/*",
"*://www.amazon.in/*",
"*://amazon.com.au/*",
"*://www.amazon.com.au/*"
],
types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking"]
);