forked from mrwill84/DOClever
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookie.js
More file actions
executable file
·64 lines (64 loc) · 2.07 KB
/
cookie.js
File metadata and controls
executable file
·64 lines (64 loc) · 2.07 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
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
62
63
64
var path=require("path");
var ipc=require("electron").ipcMain;
var fs=require("fs-extra");
function Cookie(electron) {
this.all=function (url) {
var _this=this;
return new Promise(function (resolve) {
electron.mainWindow.webContents.session.cookies.get({url:url?url:"http://localhost"},function (err,cookies) {
let str="";
for(let o of cookies)
{
str+=o.name+"="+o.value+";"
}
resolve(str);
})
})
}
this.get=function (key,url) {
var _this=this;
return new Promise(function (resolve) {
electron.mainWindow.webContents.session.cookies.get({url:url?url:"http://localhost"},function (err,cookies) {
for(let o of cookies)
{
if(o.name==key)
{
resolve(o.value);
return;
}
}
resolve();
})
})
}
this.set=function (key,value,remember,url) {
var _this=this;
return new Promise(function (resolve) {
let obj={
name:key,
value:value,
path:"/",
url:url?url:"http://localhost"
}
if(remember)
{
let Days = 10000;
let exp = new Date();
let date = Math.round(exp.getTime() / 1000) + Days * 24 * 60 * 60;
obj.expirationDate=date;
}
electron.mainWindow.webContents.session.cookies.set(obj,function (error) {
resolve();
})
})
}
this.remove=function (key,url) {
var _this=this;
return new Promise(function (resolve) {
electron.mainWindow.webContents.session.cookies.remove(url?url:"http://localhost","key",function (error) {
resolve();
})
})
}
}
module.exports=Cookie;