-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
62 lines (42 loc) · 1.63 KB
/
content.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
import { AmazonPriceReplacer } from './price-replacers/AmazonPriceReplacer';
import { NewEggPriceReplacer } from './price-replacers/NewEggPriceReplacer';
import { GenericPriceReplacer } from './price-replacers/GenericPriceReplacer';
let priceReplacers = [];
priceReplacers.push(new AmazonPriceReplacer());
priceReplacers.push(new NewEggPriceReplacer());
priceReplacers.push(new GenericPriceReplacer());
import { AppStateStore } from './AppStateStore';
import { ExchangeRateStore } from './ExchangeRateStore';
const updateSpeed = 200;
const appStateStore = new AppStateStore();
const exchangeRateStore = new ExchangeRateStore();
let state = appStateStore.getAppState();
let exchangeRates = exchangeRateStore.getRates();
let updateInterval = null;
(async function update() {
try {
clearInterval(updateInterval);
let oldState = state;
state = await appStateStore.getAppState();
if(state.dogMoneyModeEnabled) {
exchangeRates = await exchangeRateStore.getRates();
convertPrices();
} else if(oldState.dogMoneyModeEnabled) {
location.reload();
}
if (state.comicSansModeEnabled) {
document.documentElement.classList.add("dogmoneymode-comic-sans");
}
else {
document.documentElement.classList.remove("dogmoneymode-comic-sans");
}
updateInterval = setInterval(update, updateSpeed);
} catch (error) {
console.error(error);
}
})();
function convertPrices() {
priceReplacers.forEach(priceReplacer => {
priceReplacer.replace(window, document.body, exchangeRates);
});
}