-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
124 lines (119 loc) · 2.73 KB
/
background.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
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
const { runningTotal, baseCurrency, newCurrency } = request;
if (request.contentScriptQuery == "getConversion") {
let url = `https://currency-converter5.p.rapidapi.com/currency/convert?format=json&from=${baseCurrency}&to=${newCurrency}&amount=${runningTotal}`;
console.log("URL:", url);
fetch(url, {
headers: {
"X-RapidAPI-Host": "currency-converter5.p.rapidapi.com",
"X-RapidAPI-Key": "443ad39d7emshd5a159e64a17efcp114583jsndaf97a539a59"
}
})
.then(r => r.json())
.then(result => {
console.log("this is the result:", result.rates);
sendResponse({ res: result.rates });
})
.catch(err => console.log(err));
return true;
}
});
let items = [
"anorak",
"apron",
"baseball-cap",
"belt",
"bikini",
"blazer",
"blouse",
"boots",
"bow-tie",
"boxers",
"bra",
"cardigan",
"coat",
"dress",
"dressing-gown",
"gloves",
"hat",
"high-heels",
"jacket",
"jeans",
"jumpsuit",
"jumper",
"knickers",
"leather-jacket",
"leggings",
"miniskirt",
"nightie",
"overalls",
"overcoat",
"pants",
"pyjamas",
"raincoat",
"sandals",
"scarf",
"shirt",
"shoelace",
"shoes",
"shorts",
"skirt",
"slippers",
"sliders",
"socks",
"stilettos",
"stockings",
"suit",
"sweater",
"sweatshirt",
"swimming-costume",
"swimming-trunks",
"thong",
"tie",
"tights",
"top",
"tracksuit",
"trainers",
"trousers",
"t-shirt",
"underpants",
"vest",
"wellingtons"
];
items.forEach(item => {
chrome.runtime.onInstalled.addListener(() => {
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {
chrome.declarativeContent.onPageChanged.addRules([
{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: { urlContains: item }
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}
]);
});
});
});
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
const { url, word, targetLang } = request;
if (request.contentScriptQuery == "getTranslation") {
fetch(url, {
method: "post",
headers: {
"X-RapidAPI-Host": "translator.p.rapidapi.com",
"X-RapidAPI-Key": "443ad39d7emshd5a159e64a17efcp114583jsndaf97a539a59",
"Content-Type": "application/x-www-form-urlencoded"
},
body: `input=${word}&target=${targetLang}`
})
.then(r => r.json())
.then(result => {
console.log("this is the translate result:", result);
sendResponse({ res: result });
})
.catch(err => console.log(err));
return true;
}
});