Crazy-level search

master
Drake 1 year ago
parent 1a565d7901
commit 0e8a2faf68

@ -170,11 +170,20 @@
"https://deno.land/x/wattpad@v0.0.4/src/classes/Wattpad.ts": "ce67ad71a4250232818473807da6a687f71772c9d142154a431b46b73201a11e",
"https://deno.land/x/wattpad@v0.0.4/src/types.d.ts": "fe933b610694544ffd9ade8a94aa555c82abaedf293faf5aa61f6ab6d1ee44f8",
"https://deno.land/x/wattpad@v0.0.4/src/utils/http.ts": "50e18486856ec16878f780af0a4cfe9850a69590de62d48f7ec5e74d602d20e7",
"https://deno.land/x/wattpad@v0.1.0/mod.ts": "98fd4ccfcc2ac6d24539d005d3a0dff4023c48d0717ae10bc9795dbaa4a2ec2d",
"https://deno.land/x/wattpad@v0.1.0/src/classes/Chapter.ts": "00b6097f5ffce2b44a24432fc62be324bf11a80327e2975eb115bc2e7410369c",
"https://deno.land/x/wattpad@v0.1.0/src/classes/Search.ts": "fc290bd9819ce65e3efe6473c4ed3594b07d16569e4a566f06cb04cad274214d",
"https://deno.land/x/wattpad@v0.1.0/src/classes/Story.ts": "e9c679f2201cf63a5f061cd535176d6c50569d3637c99cb2a3560e98ee923bbf",
"https://deno.land/x/wattpad@v0.1.0/src/classes/Wattpad.ts": "f9b1762e1244207835e6258271690d2c8e0dcf9d69c8513de3f313c97174f249",
"https://deno.land/x/wattpad@v0.1.0/src/types.d.ts": "fe933b610694544ffd9ade8a94aa555c82abaedf293faf5aa61f6ab6d1ee44f8",
"https://deno.land/x/wattpad@v0.1.0/src/utils/http.ts": "a072d8964b1fbd67d18f8a0233031d04fa4d9fc3d9b5961012f4e949b0cf8fbe",
"https://raw.githubusercontent.com/kt3k/callsites/v1.0.0/mod.ts": "a5fdfa7916d03459fd4830ca526d493d5f4ce0ea91619905d524c9a3a5c3cd15",
"https://raw.githubusercontent.com/nomyTx/gas/bef3e8b8b51a9929b915b3e13df07290a37832ba/jsx.ts": "adf05a2478b48bc0c1e4e18db87c7c03d0894e3751be99571c3e63375471d5d3"
},
"npm": {
"specifiers": { "@connorskees/grass": "@connorskees/grass@0.12.0" },
"specifiers": {
"@connorskees/grass": "@connorskees/grass@0.12.0"
},
"packages": {
"@connorskees/grass@0.12.0": {
"integrity": "sha512-nDICkb3SxivBAteLuUsosUk0EsB0qQW2hBtnkhFP0dP/yAV1zcrq4p38O12/Mw+Yt1DKTqQSyCZAoliaK/kw4g==",
@ -182,4 +191,4 @@
}
}
}
}
}

@ -12,13 +12,14 @@ function search() {
export default async (params: URLSearchParams) => {
const res = [];
if (params.get("query") && params.get("type")) {
const search = originalWatt[
params.get("type") === "tag" ? "tagSearch" : "search"
]({
tags: (params.get("query") as string).split(","),
query: params.get("query") as string,
isTitle: params.get("type") === "title",
limit: 20
const search = originalWatt.search({
query:
params.get("type") === "tag"
? (params.get("query") as string).split(",")
: (params.get("query") as string),
type: params.get("type") as "text" | "title" | "tag", //cannot go wrong, will not go wrong, has never gone wrong
limit: 20,
sort: (params.get("sort") as string) ?? "hot" // migration trol
});
await search.update(Number(params.get("page") ?? 0));
for (let i = 0; i < search.results.length; i++) {
@ -82,6 +83,20 @@ export default async (params: URLSearchParams) => {
checked={params.get("type") === "tag"}
/>
<label for="tag">Tag search</label>
<select name="sort" id="sort">
<option
value="hot"
selected={params.get("sort") === "hot"}
>
Hot
</option>
<option
value="new"
selected={params.get("sort") === "new"}
>
New
</option>
</select>
</div>
</div>
<div style="flex-direction: row !important;">

@ -1,6 +1,7 @@
interface SavedSearch {
query: string;
type: "text" | "title" | "tag";
sort: "hot" | "new";
}
export default () => {
@ -26,6 +27,9 @@ export default () => {
type: (new URL(document.URL)).searchParams.get(
"type",
) as "text" | "title" | "tag",
sort: (new URL(document.URL)).searchParams.get(
"sort",
) as "hot" | "new",
});
button.textContent = "Unfavorite";
} else if (button?.textContent === "Unfavorite") {
@ -33,7 +37,9 @@ export default () => {
search.query !==
(new URL(document.URL)).searchParams.get("query") &&
search.type !==
(new URL(document.URL)).searchParams.get("type")
(new URL(document.URL)).searchParams.get("type") &&
search.type !==
(new URL(document.URL)).searchParams.get("sort")
);
button.textContent = "Favorite";
}
@ -48,7 +54,9 @@ export default () => {
search.query ===
(new URL(document.URL)).searchParams.get("query") &&
search.type ===
(new URL(document.URL)).searchParams.get("type")
(new URL(document.URL)).searchParams.get("type") &&
search.sort ===
(new URL(document.URL)).searchParams.get("sort")
).length > 0
) {
button.textContent = "Unfavorite";

@ -1,6 +1,7 @@
interface SavedSearch {
query: string;
type: "text" | "title" | "tag";
sort: "hot" | "new";
}
interface SavedStory {
@ -28,8 +29,9 @@ export default () => {
savedSearches.forEach((search) => {
const searchEle = document.createElement("a");
searchEle.href =
`/search?query=${search.query}&type=${search.type}`;
searchEle.textContent = `${search.query} (${search.type} search)`;
`/search?query=${search.query}&type=${search.type}&sort=${search.sort}`;
searchEle.textContent =
`${search.query} (${search.type} search, sorted by ${search.sort})`;
searchEle.className = "saved-search";
savedSearchesDiv?.appendChild(searchEle);
});

@ -1,5 +1,5 @@
export * from "https://deno.land/x/wattpad@v0.0.4/mod.ts";
import Wattpad, { Story } from "https://deno.land/x/wattpad@v0.0.4/mod.ts";
export * from "https://deno.land/x/wattpad@v0.1.0/mod.ts";
import Wattpad, { Story } from "https://deno.land/x/wattpad@v0.1.0/mod.ts";
import config from "./config.ts";
const watt = new Wattpad();
@ -31,7 +31,6 @@ export { watt };
export default {
search: watt.search,
tagSearch: watt.tagSearch,
async getStory(id: string, initChapters = true): Promise<Story> {
if (!cache[id]) {
cache[id] = {

Loading…
Cancel
Save