stuff
parent
d2a905b67f
commit
b7151ff9ad
@ -0,0 +1,8 @@
|
||||
{
|
||||
"[javascript]": {
|
||||
"editor.tabSize": 4,
|
||||
"editor.detectIndentation": false,
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
||||
"editor.formatOnSave": true
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
Copyright Ruthenic
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
@ -0,0 +1,28 @@
|
||||
window.onload = () => {
|
||||
let favoriteSearches = document.getElementById("favorite-searches");
|
||||
let favoriteStories = document.getElementById("favorite-stories");
|
||||
|
||||
let savedSearches = JSON.parse(
|
||||
localStorage.getItem("savedSearches") ?? "[]"
|
||||
);
|
||||
let savedStories = JSON.parse(localStorage.getItem("savedStories") ?? "[]");
|
||||
|
||||
// Broke: JSX
|
||||
// Woke:
|
||||
for (const search of savedSearches) {
|
||||
favoriteSearches.innerHTML += `<a class="favorite-search" href="/search?${new URLSearchParams(
|
||||
search
|
||||
)}">${search.query} (${search.type} search, sorted by ${
|
||||
search.sort
|
||||
})</a>`;
|
||||
}
|
||||
|
||||
for (const story of savedStories) {
|
||||
// prettier-ignore
|
||||
favoriteStories.innerHTML +=
|
||||
`<a class="favorite-story" href="/story?id=${story.id}">
|
||||
<img src=${story.coverURL}/>
|
||||
<h3>${story.name}</h3>
|
||||
</a>`
|
||||
}
|
||||
};
|
@ -0,0 +1,49 @@
|
||||
window.onload = () => {
|
||||
console.log("haiiiiiiiii :3");
|
||||
const button = document.getElementById("favorite");
|
||||
|
||||
if (!button) throw "how did your button not init what";
|
||||
|
||||
let savedSearches = JSON.parse(
|
||||
localStorage.getItem("savedSearches") ?? "[]"
|
||||
);
|
||||
if (
|
||||
savedSearches.filter(
|
||||
(search) =>
|
||||
search.query ===
|
||||
new URL(document.URL).searchParams.get("query") &&
|
||||
search.type ===
|
||||
new URL(document.URL).searchParams.get("type") &&
|
||||
search.sort === new URL(document.URL).searchParams.get("sort")
|
||||
).length > 0
|
||||
) {
|
||||
button.value = "Unfavorite";
|
||||
}
|
||||
|
||||
function handler() {
|
||||
console.log("haiiiiiiiii :3");
|
||||
console.log(button);
|
||||
if (button?.value === "Favorite") {
|
||||
savedSearches.push({
|
||||
query: new URL(document.URL).searchParams.get("query"),
|
||||
type: new URL(document.URL).searchParams.get("type") ?? "text",
|
||||
sort: new URL(document.URL).searchParams.get("sort") ?? "hot"
|
||||
});
|
||||
button.value = "Unfavorite";
|
||||
} else if (button?.value === "Unfavorite") {
|
||||
savedSearches = savedSearches.filter(
|
||||
(search) =>
|
||||
search.query !==
|
||||
new URL(document.URL).searchParams.get("query") &&
|
||||
search.type !==
|
||||
new URL(document.URL).searchParams.get("type") &&
|
||||
search.type !==
|
||||
new URL(document.URL).searchParams.get("sort")
|
||||
);
|
||||
button.value = "Favorite";
|
||||
}
|
||||
localStorage.setItem("savedSearches", JSON.stringify(savedSearches));
|
||||
}
|
||||
|
||||
button.onclick = handler;
|
||||
};
|
Loading…
Reference in new issue