master
Drake 2 years ago
parent a764653342
commit 60c017360a

@ -1,4 +1,4 @@
{
"deno.enable": true,
"deno.unstable": true
"deno.unstable": true,
}

@ -0,0 +1,7 @@
{
"fmt": {
"options": {
"indentWidth": 4
}
}
}

@ -2,7 +2,7 @@ import Work from "./Work.ts";
import { ID } from "../types.d.ts";
import {
DOMParser,
} from "https://denopkg.dev/gh/Ruthenic/deno-dom@master/deno-dom-wasm.ts";
} from "https://denopkg.dev/gh/Ruthenic/deno-dom@master/deno-dom-native.ts";
export default class AO3 {
session: {

@ -82,7 +82,8 @@ export default class Chapter {
}
populateMetadata() {
this.#name = this.#document.querySelector("h3.title")?.innerText.replace(
this.#name = this.#document.querySelector("h3.title")?.innerText
.replace(
/Chapter \d+: /,
"",
).trim() as string;
@ -96,18 +97,20 @@ export default class Chapter {
populateNotes() {
const notesList = Array.from(
this.#document.querySelectorAll(".notes > .userstuff"),
).map((n) =>
(n as Element).innerHTML
);
this.#startNote = notesList[0]?.trim()?.replace(/<\/{0,1}p>/g, "\n")?.trim();
this.#endNote = notesList[1]?.trim()?.replace(/<\/{0,1}p>/g, "\n")?.trim();
).map((n) => (n as Element).innerHTML);
this.#startNote = notesList[0]?.trim()?.replace(/<\/{0,1}p>/g, "\n")
?.trim();
this.#endNote = notesList[1]?.trim()?.replace(/<\/{0,1}p>/g, "\n")
?.trim();
}
populateText() {
/*this.text = this.#document.querySelector("div.userstuff[role='article']")?.innerText.trim().replace(/Chapter Text\s+/, "") as string*/
//"div.userstuff[role='article'] > p"
Array.from(
this.#document.querySelectorAll("div.userstuff[role='article'] > p"),
this.#document.querySelectorAll(
"div.userstuff[role='article'] > p",
),
).forEach(
(t) => this.#text += (t as Element).innerText + "\n",
);

@ -9,7 +9,6 @@ import type {
HTMLDocument,
} from "https://denopkg.dev/gh/Ruthenic/deno-dom@master/src/dom/document.ts";
import { ID } from "../types.d.ts";
import asyncForEach from "../utils/asyncForeach.ts";
export default class Work {
#session: {
@ -76,13 +75,17 @@ export default class Work {
(t) => this.tags.push(t.children[0].innerText),
);
Array.from(
(this.#document.querySelector("dd.relationship > ul.commas") as Element)
(this.#document.querySelector(
"dd.relationship > ul.commas",
) as Element)
.children,
).map(
(t) => this.tags.push(t.children[0].innerText),
);
Array.from(
(this.#document.querySelector("dd.character > ul.commas") as Element)
(this.#document.querySelector(
"dd.character > ul.commas",
) as Element)
.children,
).map(
(t) => this.tags.push(t.children[0].innerText),
@ -107,7 +110,8 @@ export default class Work {
//CW: horrifying jank
async populateChapters() {
const firstChapterUrl =
(this.#document.querySelector("li.chapter > a") as Element).getAttribute(
(this.#document.querySelector("li.chapter > a") as Element)
.getAttribute(
"href",
) as string + "?view_adult=true";
const res = await this.#session.get(firstChapterUrl);
@ -116,8 +120,6 @@ export default class Work {
"text/html",
) as HTMLDocument;
const promises: Promise<void>[] = [];
Array.from((document.getElementById("selected_id") as Element).children)
.sort(
(a, b) => {
@ -125,20 +127,15 @@ export default class Work {
Number(b.getAttribute("value"));
},
).forEach((c) => {
promises.push((async (c: Element) => {
const newChapter = new Chapter(
this.id,
c.getAttribute("value") as string,
this.#session,
this.#DOMParser,
);
await 1; //shut up
this.chapters.push(
newChapter,
);
})(c));
});
await Promise.all(promises);
}
}

@ -24,6 +24,7 @@ assert(await work.chapters[0].workID == "37522864");
assert(await work.chapters[0].name == "Part I");
assert((await work.chapters[0].text).length > 0);
/*
work = await ao3.getWork("39612636");
await work.init();
@ -40,4 +41,4 @@ assert(
assert(
(await work.chapters[22].summary) ===
"Fizz tries to make the best out of his comeback",
);
);.*/

Loading…
Cancel
Save