-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
61 lines (52 loc) · 1.95 KB
/
service-worker.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
importScripts("./lib/browser-polyfill.min.js");
function applyPrevSetting() {
// v1.2.1までの設定引き継ぎ
browser.storage.local.get("numel").then((result) => {
const numel = result["numel"];
if (numel) {
let prevSetting = {
sortRelevance: true,
sortPopularity: true,
sortSales: true,
sortReview: true,
sortPrice: true,
sortInversePrice: true,
sortReleaseDate: true,
filterAmazonOnly: true,
filterPrice: true,
filterPercentOff: true
};
// 各キーごとに古い設定の値を代入
let cnt = 0;
for (const key of Object.keys(prevSetting)) {
const eleKey = "ele" + cnt;
browser.storage.local.get(eleKey).then((result) => {
prevSetting[key] = result[eleKey];
});
browser.storage.local.remove(eleKey);
cnt++;
}
browser.storage.local.get("isHideElem").then((result) => {
let newSetting = result["isHideElem"];
// 現在のデフォルト設定に古い設定を上書き・マージ
Object.assign(newSetting, prevSetting);
browser.storage.local.set({"isHideElem": newSetting});
});
browser.storage.local.remove("numel");
}
});
}
// 要素非表示設定保存用
const isHideElem = {
"filterAmazonOnly": true,
"filterPercentOff": true,
"filterPrice": true,
"sortInversePrice": true,
"sortPopularity": true,
"sortPrice": true,
"sortReleaseDate": true,
"sortRelevance": true,
"sortReview": true,
"sortSales": true
}
browser.storage.local.set({"isHideElem": isHideElem}).then(applyPrevSetting);