-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
38 lines (35 loc) · 889 Bytes
/
index.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
const { clipboard } = require('electron')
let cbText;
const pane = document.getElementById('styled')
pane.addEventListener('input', saveState)
grabAndAppendText()
window.onfocus = () => {
grabAndAppendText()
}
window.onload = () => {
grabAndAppendText()
}
function grabAndAppendText() {
let newpane = pane;
const text = window.localStorage.getItem('text')
const lastChar = text[text.length - 1] === '\n'
if (text && lastChar) {
newpane.innerText = `${text}`
} else if (text) {
newpane.innerText = `${text}
`
}
if (cbText !== undefined) {
newpane.innerText = `${text}
${cbText}
`
newpane.dispatchEvent(new Event('input'))
clipboard.clear()
}
newpane.focus()
document.execCommand('selectAll', false, null);
document.getSelection().collapseToEnd();
}
function saveState(e) {
window.localStorage.setItem('text', e.target.innerText)
}