-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
97 lines (85 loc) · 3.56 KB
/
config.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
const defaultConfig = {
globalRules: {
// Allow all websites to send a referrer to *.codepen.io and *.jsfiddle.net
excludedRequestDomains: ['codepen.io', 'cdpn.io', 'jsfiddle.net'],
// Allow *.example.com to send a referrer to any URL it wants
excludedInitiatorDomains: ['example.com'],
// Strip cross-origin referrers only
domainType: 'thirdParty',
// Strip GET & HEAD request referrers only
requestMethods: ['get', 'head'],
// Strip 'origin' header for cross-origin font requests
stripFontOrigin: true,
// Strip 'referer' header for these resource types
resourceTypes: [
'main_frame', // top level requests from website
'sub_frame', // sub level requests from website (iframes, popups, about:*, data:*, etc)
'object', // embedded html objects
'font', // font files
'stylesheet', // css files
'script', // js files
/* 'xmlhttprequest', // js fetch requests, not recommended enabling */
/* 'image', // image files, causes a lot of breakage without adding siteRules exceptions */
/* 'media', // audio & video files, causes a lot of breakage without adding siteRules exceptions */
],
},
/* Site specific rules */
siteRules: [
{
// Allow *.reddit.com to send referrers to *.redditstatic.com and others listed, but NOT vice versa
initiatorDomains: ['reddit.com'],
excludedRequestDomains: ['redditstatic.com', 'redditmedia.com', 'cdn.embedly.com'],
// setReferrerValue: 'example.com',
},
{
// Allow *.sony.com to send referrers to *.playstation.com AND vice versa
initiatorDomains: ['sony.com', 'playstation.com'],
excludedRequestDomains: ['playstation.com', 'sony.com'],
},
{
initiatorDomains: ['icloud.com', 'apple.com'],
excludedRequestDomains: ['apple.com', 'cdn-apple.com', 'icloud.com'],
},
{
initiatorDomains: ['binance.com'],
excludedRequestDomains: ['bnbstatic.com'],
},
{
initiatorDomains: ['google.com'],
excludedRequestDomains: ['googleapis.com', 'gstatic.com'],
},
],
};
/**
* Performs a deep merge of objects and returns new object. Does not modify
* objects (immutable) and merges arrays via concatenation.
* Source: https://stackoverflow.com/a/48218209
*
* @param {...object} objects - Objects to merge
* @returns {object} New object with merged key/values
*/
function mergeDeep(...objects) {
const isObject = (obj) => obj && typeof obj === 'object';
return objects.reduce((prev, obj) => {
Object.keys(obj).forEach((key) => {
const pVal = prev[key];
const oVal = obj[key];
/* eslint-disable no-param-reassign */
if (Array.isArray(pVal) && Array.isArray(oVal)) {
prev[key] = [...pVal, ...oVal].filter((element, index, array) => array.indexOf(element) === index);
} else if (isObject(pVal) && isObject(oVal)) {
prev[key] = mergeDeep(pVal, oVal);
} else {
prev[key] = oVal;
}
/* eslint-enable no-param-reassign */
});
return prev;
}, {});
}
export default async function SetupStorage() {
const existingConfig = await chrome.storage.local.get(null);
const config = mergeDeep(defaultConfig, existingConfig);
await chrome.storage.local.set(config);
return config;
}