-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmigration.js
More file actions
29 lines (25 loc) · 1.09 KB
/
migration.js
File metadata and controls
29 lines (25 loc) · 1.09 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
const LegacyIsVisitedStorageKey = "isVisited_"
const LegacyPersonalNoteStorageKey = "personalNote_"
function migrateLocalStorage() {
var keysToRemove = []
for (var i = 0; i < localStorage.length; i++) {
var key = localStorage.key(i)
if (key.startsWith(LegacyIsVisitedStorageKey)) {
var name = key.slice(LegacyIsVisitedStorageKey.length)
if (!currentProfile.islandsData[name]) currentProfile.islandsData[name] = {}
currentProfile.islandsData[name].IsVisited = localStorage.getItem(key) === 'true'
keysToRemove.push(key)
} else if (key.startsWith(LegacyPersonalNoteStorageKey)) {
var name = key.slice(LegacyPersonalNoteStorageKey.length)
if (!currentProfile.islandsData[name]) currentProfile.islandsData[name] = {}
currentProfile.islandsData[name].PersonalNote = localStorage.getItem(key)
keysToRemove.push(key)
}
}
if (keysToRemove.length > 0) {
saveProfiles()
keysToRemove.forEach(key => localStorage.removeItem(key))
console.log('Migrated ' + keysToRemove.length + ' legacy storage keys to IslandData')
}
}
migrateLocalStorage()