forked from junyiz/dature
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreload.js
39 lines (31 loc) · 1.1 KB
/
preload.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
const fetch = require('./lib/fetch')
const join = require('path').join
const { shell } = require('electron')
const { help } = require('yargs')
const $ = (selector) => document.getElementById(selector)
window.addEventListener('DOMContentLoaded', () => {
const btn = $('btn')
const out = $('out')
btn.addEventListener('click', () => {
const uid = $('uid').value
const cookie = ($('cookie').value || '')
.replace(/(NowDate|BLOG_TITLE|mblog_userinfo)[^;]*;/g, '')
const dir = join(process.cwd(), `./blog-${uid}`)
console.log = (log) => out.innerHTML += log.replace('\n', '<br>') + '<br>'
fetch(dir, uid, cookie).then(function() {
console.log(`\n备份完毕, 博客存储目录:<a href="${dir}/index.html">${dir}</a>\n`)
})
})
$('help').addEventListener('click', (event) => {
if (event.target.tagName === 'A') {
event.preventDefault()
shell.openExternal(event.target.href)
}
})
out.addEventListener('click', (event) => {
if (event.target.tagName === 'A') {
event.preventDefault()
shell.openExternal(event.target.href)
}
})
})