-
Notifications
You must be signed in to change notification settings - Fork 0
/
migration.js
45 lines (38 loc) · 1.32 KB
/
migration.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
"use strict"
document.addEventListener('DOMContentLoaded', function () {
const StorageArea = chrome.storage.sync;
StorageArea.get("contentArray", (obj) => {
if(!obj["contentArray"]) {
console.log("no content array exists yet, migrating");
StorageArea.get("maxKey", (obj) => {
if (!obj["maxKey"]) {
console.log("no maxKey set, initializing array to []");
StorageArea.set({"contentArray": []});
return;
}
const maxKeyInt = parseInt(obj["maxKey"]);
if (maxKeyInt === 0) {
console.log("maxKeyInt is 0, initializing array to []");
StorageArea.set({"contentArray": []});
return;
}
migrateContent(1, maxKeyInt, []);
});
}
});
});
function migrateContent(i, maxKey, contentArray) {
const StorageArea = chrome.storage.sync;
const key = i.toString();
StorageArea.get(key, (obj) => {
const insp = obj[key];
contentArray.push(insp);
if (i < maxKey) {
migrateContent(i+1, maxKey, contentArray);
}
else {
StorageArea.set({"contentArray": contentArray});
location.reload();
}
});
}