-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathall_notes.js
More file actions
60 lines (52 loc) · 2.12 KB
/
Copy pathall_notes.js
File metadata and controls
60 lines (52 loc) · 2.12 KB
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
60
document.addEventListener('DOMContentLoaded', async () => {
const allNotes = await chrome.storage.local.get();
const notesList = document.getElementById('allNotesList');
const groupedNotes = {};
Object.entries(allNotes).forEach(([url, notes]) => {
const domain = new URL(url).hostname;
if (!groupedNotes[domain]) groupedNotes[domain] = {};
groupedNotes[domain][url] = notes;
});
notesList.innerHTML = Object.entries(groupedNotes)
.map(([domain, urls]) => `
<div class="domain-group">
<h3>${domain}</h3>
${Object.entries(urls).map(([url, notes]) => `
<div class="url-group">
<div class="url">${url}</div>
${notes.map((note, index) => `
<div class="note-item">
<div class="note-content">
<div class="note-text">${note.text}</div>
<div class="note-date">${new Date(note.date).toLocaleString()}</div>
</div>
<button class="delete-btn" data-url="${url}" data-index="${index}">×</button>
</div>
`).join('')}
</div>
`).join('')}
</div>
`).join('');
document.querySelectorAll('.delete-btn').forEach(btn => {
btn.addEventListener('click', async () => {
const url = btn.dataset.url;
const index = parseInt(btn.dataset.index);
const {[url]: notes} = await chrome.storage.local.get(url);
if (!notes || index >= notes.length) return;
const updatedNotes = notes.filter((_, i) => i !== index);
if (updatedNotes.length === 0) {
await chrome.storage.local.remove(url);
const urlGroup = btn.closest('.url-group');
const domainGroup = urlGroup.closest('.domain-group');
urlGroup.remove();
// Удаляем домен-группу если не осталось URL
if (domainGroup.querySelectorAll('.url-group').length === 0) {
domainGroup.remove();
}
} else {
await chrome.storage.local.set({[url]: updatedNotes});
btn.closest('.note-item').remove();
}
});
});
});