-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstorage.js
61 lines (61 loc) · 2.03 KB
/
storage.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
var saveSplit1 = '<^>', saveSplit2 = '<*>', saveY;
function storageCheck() {
if (localStorage) {
if (localStorage.length) {
//something is stored
var dataToLoad = storageLoad('AllowSave');
if (dataToLoad == 1) {
//user has said YES to saving.
saveY = 1;
} else if (dataToLoad == 0) {
//user has said NO to saving.
saveY = -1;
} else {
//either there is nothing saved yet, or something is amiss!
saveY = 0;
}
} else {
saveY = 0;
}
} else {
upNotOpen('localStorage appears to be unavailable in this browser. Unable to save anything.','');
saveY = -1;
}
}
function storageChoose(zChoice) {
if (zChoice == 'Y') {
var a = saveY[0]
, b = saveY[1];
saveY = 1;
storageSave('AllowSave', saveY);
storageSave(a, b);
} else {
//disable saving for this session.
saveY = -1;
}
//later on if it is called for by anyone, I can add a 'never' save that disables saving, except for saving the preference to never save :D
upNotClose();
}
function storageLoad(toLoad) {
var dataToLoad = '';
try {
dataToLoad = localStorage.getItem(toLoad);
} catch (ex) {}
return dataToLoad;
}
function storageSave(toSave, dataToSave) {
//ONLY save if if is 1
if (saveY == 1) {
localStorage.setItem(toSave, dataToSave);
}//check wether this is the first time the user has saved something:
else if (saveY == 0) {
//nothing stored
//check if the user has already got a notifyer yet:
if (!document.getElementById('storY')) {
//temporerily store the data in this variable.
saveY = [toSave, dataToSave];
upNotOpen('Remember preferences?<button id="storY" class="uButtons uButtonGreen" type="button " style="font-size:1.5em;width:30%;margin:.1em .2em;float:left;">Yes</button>' + '<button id="storN" class="uButtons uButtonRed" type="button" style="font-size:1.5em;width:30%;margin:.1em .2em;float:right;">No</button>','');
}
}
//else stor is -1 and that means the user has opted to not save anything.
}