forked from wildskyf/tab-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.js
41 lines (33 loc) · 1.02 KB
/
export.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
40
;(() => {
const exportJs = () => {
const init = async () => {
const $textarea = document.querySelector('#export-content')
const $switchBtn = document.querySelector('#switch-button')
const data = await window.utils.loadPreference()
const notes = data.list
.map(note => note.content)
.filter(c => c)
.join('\n\n--------------------\n\n')
$textarea.value = notes
$switchBtn.addEventListener('click', () => {
const { currentAsk } = $switchBtn.dataset
if (currentAsk === 'json') {
$textarea.value = JSON.stringify(data, null, ' ')
$switchBtn.dataset.currentAsk = 'text'
$switchBtn.textContent = 'I need pure text.'
}
if (currentAsk === 'text') {
$textarea.value = notes
$switchBtn.dataset.currentAsk = 'json'
$switchBtn.textContent = 'I need json file.'
}
})
}
return {
init
}
}
window.addEventListener('load', () => {
exportJs().init()
})
})()