-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathlist-favorites.js
More file actions
36 lines (36 loc) · 1.37 KB
/
list-favorites.js
File metadata and controls
36 lines (36 loc) · 1.37 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
document.addEventListener('DOMContentLoaded', function() {
var STORAGE_KEY = 'qumulo-favorites';
var list = document.getElementById('fav-list');
var empty = document.getElementById('fav-empty');
if (!list || !empty) return;
function getFavorites() {
try { return JSON.parse(localStorage.getItem(STORAGE_KEY)) || []; }
catch(e) { return []; }
}
var favs = getFavorites();
if (favs.length === 0) return;
empty.style.display = 'none';
document.getElementById('fav-intro').style.display = 'block';
favs.forEach(function(f) {
var li = document.createElement('li');
var a = document.createElement('a');
a.href = f.path;
a.textContent = f.title || f.path;
var removeBtn = document.createElement('span');
removeBtn.style.userSelect = 'none';
removeBtn.innerHTML = ' <span class="fav-remove">✕</span>';
removeBtn.title = 'Remove from favorites';
removeBtn.addEventListener('click', function() {
var updated = getFavorites().filter(function(x) { return x.path !== f.path; });
localStorage.setItem(STORAGE_KEY, JSON.stringify(updated));
li.remove();
if (document.querySelectorAll('#fav-list li').length === 0) {
empty.style.display = '';
document.getElementById('fav-intro').style.display = 'none';
}
});
li.appendChild(a);
li.appendChild(removeBtn);
list.appendChild(li);
});
});