-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.js
More file actions
53 lines (44 loc) · 1.4 KB
/
main.js
File metadata and controls
53 lines (44 loc) · 1.4 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
const {app, BrowserWindow, session} = require('electron')
const path = require('path')
const filter = {
urls: ['https://*.jd.com/*']
}
const partition = String(new Date().getTime())
function createWindow() {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
webSecurity: false,
nodeIntegration: true,
partition: partition, // 加上时间戳,每次打开新页面
preload: path.join(__dirname, 'setCookieDom.js')
},
})
win.loadFile('index.html')
return win;
}
app.whenReady().then(() => {
const win = createWindow()
session.fromPartition(partition).webRequest.onBeforeSendHeaders(filter, (details, callback) => {
const cookieTxt = details.requestHeaders.Cookie;
if (cookieTxt) {
const cookieValue = getCookie(cookieTxt);
if (cookieValue) {
win.webContents.send('cookieValue', cookieValue)
}
}
callback({requestHeaders: details.requestHeaders})
})
app.on('activate', function () {
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
})
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
function getCookie(txt) {
var CV = txt;
var CookieValue = CV.match(/pt_pin=.+?;/) + CV.match(/pt_key=.+?;/);
return CookieValue
}