/
migrate.js
45 lines (39 loc) · 1.22 KB
/
migrate.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
if ( typeof localStorage == "undefined" && typeof globalStorage != "undefined" ) {
var localStorage = globalStorage[location.hostname];
}
function getItemList() {
var itemList = [];
for ( i = 0; i<localStorage.length; i++ ) {
itemList.push(localStorage.key(i));
}
return itemList;
}
function copyDataToHost(newHost, path) {
if ( JIL.ready == true ) {
var originalOrigin = JIL.origin, originalPath = JIL.path, items = getItemList();
JIL.origin = newHost;
JIL.path = path;
JIL.loadFrame(function() {
JIL.trust(function(trusted) {
if (trusted == true) {
for ( var i=0; i<items.length; i++ ) { if ( items[i] != 'trustedHosts' && items[i] === items[i].toLowerCase() ) { // can't be trusedHosts or non-lowercase items
JIL.set(items[i], localStorage.getItem(items[i]));
}}
JIL.untrust();
alert('Data copy complete.');
}
});
});
JIL.origin = originalOrigin;
JIL.path = originalPath;
JIL.loadFrame();
}
}
function removeAllItems() {
if ( confirm('Are you sure you want to remove all items from '+location.host+'?') ) {
var items = getItemList();
for ( i=0; i<items.length; i++) {
if ( items[i] != 'trustedHosts' && items[i] === items[i].toLowerCase() ) localStorage.removeItem(items[i]);
}
}
}