change favorites to use localStorage instead

This commit is contained in:
Wirlaburla 2023-01-08 23:40:38 -06:00
parent 8c5bfff839
commit c1e3f8845c

View File

@ -294,10 +294,7 @@ function favoriteTrack(track_station, track) {
track_favorites[track_station].unshift(track); track_favorites[track_station].unshift(track);
result = true; result = true;
} }
const d = new Date(); localStorage.setItem('favorites', JSON.stringify(track_favorites));
d.setTime(d.getTime() + (99983090*24*60*60*1000));
let expires = "expires=" + d.toUTCString();
document.cookie = "favorites="+JSON.stringify(track_favorites)+";"+expires+";SameSite=None;secure=1;";
populateFavorites(); populateFavorites();
return result; return result;
@ -765,8 +762,8 @@ window.addEventListener('DOMContentLoaded', (event) => {
tuner.station_container = document.querySelector('stations'); tuner.station_container = document.querySelector('stations');
tuner.favorites_container = document.querySelector('favorites'); tuner.favorites_container = document.querySelector('favorites');
var fav_cookie = getCookie('favorites'); var favStorage = localStorage.getItem('favorites');
if (fav_cookie != null && fav_cookie.length > 0) track_favorites = JSON.parse(getCookie('favorites')); if (favStorage != null && favStorage.length > 0) track_favorites = JSON.parse(favStorage);
populateFavorites(); populateFavorites();
var visModeChanger = document.querySelector('select[name="visModes"]'); var visModeChanger = document.querySelector('select[name="visModes"]');
@ -858,14 +855,3 @@ window.addEventListener('DOMContentLoaded', (event) => {
updateXHR(); updateXHR();
}); });
function getCookie(cName) {
const name = cName + "=";
const cDecoded = decodeURIComponent(document.cookie); //to be careful
const cArr = cDecoded .split('; ');
let res;
cArr.forEach(val => {
if (val.indexOf(name) === 0) res = val.substring(name.length);
})
return res;
}