Feat: Fav channel in localstorage
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// ── FAVORITES ─────────────────────────────────────────────────────────────────
|
||||
let favorites = new Set(JSON.parse(localStorage.getItem('gridtv-favorites') || '[]'));
|
||||
|
||||
function saveFavorites() {
|
||||
localStorage.setItem('gridtv-favorites', JSON.stringify([...favorites]));
|
||||
}
|
||||
|
||||
function toggleFavorite(chId, btn) {
|
||||
if (favorites.has(chId)) {
|
||||
favorites.delete(chId);
|
||||
btn.classList.remove('is-fav');
|
||||
btn.title = L.fav_add;
|
||||
} else {
|
||||
favorites.add(chId);
|
||||
btn.classList.add('is-fav');
|
||||
btn.title = L.fav_remove;
|
||||
}
|
||||
saveFavorites();
|
||||
renderAll();
|
||||
}
|
||||
|
||||
function makeFavBtn(chId) {
|
||||
const btn = document.createElement('button');
|
||||
btn.className = 'fav-btn' + (favorites.has(chId) ? ' is-fav' : '');
|
||||
btn.title = favorites.has(chId) ? L.fav_remove : L.fav_add;
|
||||
btn.textContent = '★';
|
||||
btn.addEventListener('click', e => { e.stopPropagation(); toggleFavorite(chId, btn); });
|
||||
return btn;
|
||||
}
|
||||
|
||||
function sortedChannels(list) {
|
||||
const favs = list.filter(ch => favorites.has(ch.id));
|
||||
const rest = list.filter(ch => !favorites.has(ch.id));
|
||||
return { favs, rest };
|
||||
}
|
||||
Reference in New Issue
Block a user