-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
59 lines (49 loc) · 2.25 KB
/
scripts.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
55
56
57
58
59
document.addEventListener('DOMContentLoaded', () => {
function updateHighlightLists() {
chrome.storage.local.get({ highlights: [] }, (data) => {
const highlights = data.highlights
const highlightLists = document.querySelector('.highlights-list')
highlightLists.innerHTML = ''
console.log(highlightLists)
if (highlights.length) {
highlights.forEach((highlight) => {
const el = document.createElement('li')
el.className = 'highlight'
const p = document.createElement('p')
p.textContent = highlight.highlight
p.onclick = () => window.open(highlight.source, '_blank')
el.appendChild(p)
const src = document.createElement('p')
src.className = 'source'
src.textContent = highlight.source
src.onclick = () => window.open(highlight.source, '_blank')
el.appendChild(src)
const img = document.createElement('img')
img.src = "/assets/icon-delete.png"
img.onclick = () => chrome.runtime.sendMessage({ action: 'deleteHighlight', id: highlight.id })
el.appendChild(img)
highlightLists.appendChild(el)
})
} else {
const el = document.createElement('li')
el.className = 'info'
const p = document.createElement('p')
p.textContent = "Highlight any text on the web page and right-click to start adding highlights."
el.appendChild(p)
highlightLists.appendChild(el)
}
})
}
updateHighlightLists()
const deleteButton = document.querySelector('.delete-all-btn')
deleteButton.addEventListener('click', () => {
chrome.runtime.sendMessage({ action: 'deleteAllHighlights' }, (res) => {
updateHighlightLists()
})
})
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'highlightsUpdated') {
updateHighlightLists()
}
})
})