interface SavedSearch { query: string; type: "text" | "title" | "tag"; } interface SavedStory { id: string; // in *theory* we could fetch these from the cache, but if it's not there you'd have to wait years to open the homepage lol name: string; coverURL: string; } export default () => { // deno-lint-ignore ban-types const oldOnloadHandler: Function = window.onload ?? (() => {}); window.onload = () => { oldOnloadHandler(); const savedSearchesDiv = document.getElementById("saved-searches"); const savedStoriesDiv = document.getElementById("saved-stories"); const savedSearches: SavedSearch[] = JSON.parse( localStorage.getItem("savedSearches") ?? "[]", ); const savedStories: SavedStory[] = JSON.parse( localStorage.getItem("savedStories") ?? "[]", ); savedSearches.forEach((search) => { const searchEle = document.createElement("a"); searchEle.href = `/search?query=${search.query}&type=${search.type}`; searchEle.textContent = `${search.query} (${search.type} search)`; searchEle.className = "saved-search"; savedSearchesDiv?.appendChild(searchEle); }); savedStories.forEach((story) => { const searchEle = document.createElement("a"); searchEle.className = "story"; searchEle.href = "/story?id=" + story.id + (localStorage.getItem(`${story.id}_progress`) ? `&chapter=${localStorage.getItem(`${story.id}_progress`)}` : ""); const coverEle = document.createElement("img"); coverEle.src = story.coverURL; const div = document.createElement("div"); const titleEle = document.createElement("h3"); titleEle.textContent = story.name; div.appendChild(titleEle); searchEle.appendChild(coverEle); searchEle.appendChild(div); savedStoriesDiv?.appendChild(searchEle); }); }; };