You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
2.1 KiB
56 lines
2.1 KiB
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);
|
|
});
|
|
};
|
|
};
|