-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
export.js
54 lines (43 loc) · 1.35 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;(() => {
const exportJs = () => {
const init = async () => {
const $textarea = document.querySelector('#export-content')
const $copyBtn = document.querySelector('#copy-button')
const $saveBtn = document.querySelector('#save-button')
const data = await window.utils.loadPreference()
const notes = data.list
.map(note => `${note.content}\n\n<<${note.time}>>\n\n`)
.filter(c => c)
.join('')
$textarea.value = notes
$copyBtn.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText($textarea.value);
console.log('Notes copied to clipboard');
} catch (err) {
alert('Failed to copy: ', err);
}
})
$saveBtn.addEventListener('click', async () => {
var userInput = $textarea.value;
var blob = new Blob([userInput], { type: "text/plain;charset=utf-8" });
let newLink = document.createElement("a");
newLink.download = "export.txt";
if (window.webkitURL != null) {
newLink.href = window.webkitURL.createObjectURL(blob);
} else {
newLink.href = window.URL.createObjectURL(blob);
newLink.style.display = "none";
document.body.appendChild(newLink);
}
newLink.click();
})
}
return {
init
}
}
window.addEventListener('load', () => {
exportJs().init()
})
})()