forked from mozilla/price-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.js
More file actions
108 lines (89 loc) · 3.22 KB
/
Copy pathconfig.js
File metadata and controls
108 lines (89 loc) · 3.22 KB
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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/* eslint-disable no-unused-vars */
/**
* Config values that are shared between files or otherwise useful to have in
* a separate file. Config values can be overridden by setting a pref at the
* subtree extensions.shopping-testpilot@mozilla.org.prefName.
*
* Content scripts cannot access the preference API, and thus cannot use this
* module to get config values. Use commerce/config/content instead to use
* message passing to fetch the config values from the background script.
* @module
*/
class Value {
constructor(defaultValue) {
this.defaultValue = defaultValue;
}
async get(name) {
throw new Error('The Value config class cannot be used directly; use a type-specific subclass.');
}
}
class StringValue extends Value {
async get(name) {
return browser.shoppingPrefs.getCharPref(name, this.defaultValue);
}
}
class IntValue extends Value {
async get(name) {
return browser.shoppingPrefs.getIntPref(name, this.defaultValue);
}
}
class BoolValue extends Value {
async get(name) {
return browser.shoppingPrefs.getBoolPref(name, this.defaultValue);
}
}
class ListValue extends Value {
async get(name) {
const prefValue = await browser.shoppingPrefs.getCharPref(name, this.defaultValue.join(','));
return prefValue.split(',');
}
}
const CONFIG = {
/** Time to wait between price checks for a product */
priceCheckInterval: new IntValue(1000 * 60 * 60 * 6), // 6 hours
/** Time to wait between checking if we should fetch new prices */
priceCheckTimeoutInterval: new IntValue(1000 * 60 * 15), // 15 minutes
/** Delay before removing iframes created during price checks */
iframeTimeout: new IntValue(1000 * 60), // 1 minute
// URLs to files within the extension
browserActionUrl: new StringValue(browser.extension.getURL('/browser_action/index.html')),
// Price alert config
alertPercentThreshold: new IntValue(5), // 5%
alertAbsoluteThreshold: new IntValue(1000), // $10
/** Color of the toolbar badge for showing active price alerts. */
badgeAlertBackground: new StringValue('#00FEFF'),
/** Color of the toolbar badge when a product on the current page is trackable. */
badgeDetectBackground: new StringValue('#33F70C'),
/** URL for the add-on's page on support.mozilla.org */
supportUrl: new StringValue('https://support.mozilla.org/kb/new-test-pilot-experiments'),
/** URL for the add-on's feedback form */
feedbackUrl: new StringValue('https://www.surveygizmo.com/s3/4649085/Price-Wise-Feedback'),
/** List of domains that extraction is performed on. */
extractionAllowlist: new ListValue([
'amazon.com',
'www.amazon.com',
'smile.amazon.com',
'bestbuy.com',
'www.bestbuy.com',
'ebay.com',
'www.ebay.com',
'homedepot.com',
'www.homedepot.com',
'walmart.com',
'www.walmart.com',
'mkelly.me',
'www.mkelly.me',
]),
};
export default {
async get(configName) {
const value = CONFIG[configName];
if (!value) {
throw new Error(`Invalid config ${configName}`);
}
return value.get(configName);
},
};