/* Web-achievements by PossiblyAxolotl :3 www.possiblyaxolotl.com */ // All achievements on page const allPageItems = []; // prefix for achievements, feel free to change let achievementsPrefix = "achievement_"; let achievementsCollectedOpacity = "70%"; // Once the page is loaded, search for all items with the achievement class window.addEventListener('load', () => { const items = document.querySelectorAll(".achievement"); items.forEach((item) => { const collected = localStorage.getItem(achievementsPrefix + item.id); allPageItems.push(item.id); if (!item.classList.contains("trophy")) { if (collected == true) { item.style.opacity = achievementsCollectedOpacity; item.title = "You've already found this item..."; } else { item.style.cursor = "pointer"; item.addEventListener("click", (event) => { event.target.style.opacity = achievementsCollectedOpacity; event.target.style.cursor = "auto"; localStorage.setItem(achievementsPrefix + event.target.id, 1); item.title = "good job, you found me!"; //createNotification(); }); } } else { if (collected != true) { item.style.opacity = achievementsCollectedOpacity; item.title = "You haven't found this yet. Keep looking!"; } else { item.title = "good job, you found me!"; } } }); }) function hasAchievement(item) { const collected = localStorage.getItem(achievementsPrefix + item); if (collected == true) { return true; } return false; } // Reset all achievements (really just removes a bunch of localstorage items) function resetAchievements(items = allPageItems) { items.forEach((item) => { localStorage.removeItem(achievementsPrefix + item); }); window.location.reload(); }