-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool_cookie.js
38 lines (35 loc) · 1.29 KB
/
tool_cookie.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
(function () {
var TOOL = window.TOOL;
if (!TOOL) {
TOOL = {};
}
// 因为cookie是基于TOOL.String工具类的,所以如果发现没有显示引用的话,主动加载,但是前提得存在该js
if (!TOOL.string) {
console.log("请确保您的路径下存在tool_string.js文件");
var toolStringScript = document.createElement("script");
toolStringScript.type = 'text/javascript';
toolStringScript.src = "tool_string.js";
document.getElementsByTagName("head")[0].appendChild(toolStringScript);
}
// cookie
TOOL.cookie = {
get: function (key) {
let cookie = document.cookie;
if (cookie) {
let strings = TOOL.string.replaceAll(cookie, " ", "").split(";");
for (let index in strings) {
let temp = strings[index].split("=");
if (temp[0] == key) {
return temp[1];
}
}
}
},
del: function (key, path) {
let date = new Date();
date.setTime(date.getTime() - 1);
document.cookie = key + "=" + TOOL.cookie.get(key) + "; expires="+ date.toGMTString() +" path=" + path;
}
};
window.TOOL = TOOL;
}());