-
Notifications
You must be signed in to change notification settings - Fork 0
/
localData
52 lines (52 loc) · 1.6 KB
/
localData
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
QQ.localData = {
userData: null,
name: location.hostname,
isLocalStorage: typeof localStorage == 'undefined'?false:true,
init: function(){
if (!this.userData) {
try {
this.userData = document.createElement('INPUT');
this.userData.type = "hidden";
this.userData.style.display = "none";
this.userData.addBehavior ("#default#userData");
document.body.appendChild(this.userData);
var expires = new Date();
expires.setDate(expires.getDate()+365);
this.userData.expires = expires.toUTCString();
} catch(e) {
return false;
}
}
return true;
},
set: function(key, value) {
if(this.isLocalStorage){
localStorage.setItem(key, value);
}
else if(this.init()){
this.userData.load(this.name);
this.userData.setAttribute(key, value);
this.userData.save(this.name);
}
},
get: function(key) {
if(this.isLocalStorage){
return localStorage.getItem(key);
}
else if(this.init()){
this.userData.load(this.name);
return this.userData.getAttribute(key)
}
return null;
},
remove: function(key) {
if(this.isLocalStorage){
localStorage.removeItem(key);
}
else if(this.init()){
this.userData.load(this.name);
this.userData.removeAttribute(key);
this.userData.save(this.name);
}
}
};