📚 Articolele mele salvate
const articles=JSON.parse(localStorage.getItem("myArticles")||"[]");
const container=document.getElementById("myList");const clearBtn=document.getElementById("clearList");
function drawList(){
const articles=JSON.parse(localStorage.getItem("myArticles")||"[]");
if(!articles.length){
container.innerHTML="
Nu ai salvat încă niciun articol.
";clearBtn.style.display="none";return;
}
clearBtn.style.display="inline-block";
let html="
- ";
-
articles.forEach((article,index)=>{
html+=`
`;
});
html+="
";
container.innerHTML=html;
}
function removeArticle(index){
let articles=JSON.parse(localStorage.getItem("myArticles")||"[]");
articles.splice(index,1);
localStorage.setItem("myArticles",JSON.stringify(articles));
drawList();
}
clearBtn.onclick=function(){
if(confirm("Ștergi toate articolele salvate?")){
localStorage.removeItem("myArticles");
drawList();
}
}
drawList();
