-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
import.js
34 lines (29 loc) · 936 Bytes
/
import.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
;(() => {
const importJs = () => {
const init = async () => {
const $textarea = document.querySelector('#import-content')
const $importBtn = document.querySelector('#import-button')
const data = await window.utils.loadPreference()
$importBtn.addEventListener('click', () => {
if (confirm("Are you sure you want to import these notes? All of your current notes will be replaced. This action cannot be undone.")) {
console.log("replacing")
var tmp = $textarea.value
.split(/\n\n<<([0-9]+)>>\n\n/g)
.slice(0, -1)
var newnotes = []
for (var i = 0; i < tmp.length; i += 2) {
newnotes.push({content: tmp[i], time: parseInt(tmp[i+1])})
}
data.list = newnotes
browser.storage.local.set({ list: data.list })
}
})
}
return {
init
}
}
window.addEventListener('load', () => {
importJs().init()
})
})()