master
Drake 2 years ago
parent a764653342
commit 60c017360a

@ -1,4 +1,4 @@
{ {
"deno.enable": true, "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 { ID } from "../types.d.ts";
import { import {
DOMParser, 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 { export default class AO3 {
session: { session: {

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

@ -9,7 +9,6 @@ import type {
HTMLDocument, HTMLDocument,
} from "https://denopkg.dev/gh/Ruthenic/deno-dom@master/src/dom/document.ts"; } from "https://denopkg.dev/gh/Ruthenic/deno-dom@master/src/dom/document.ts";
import { ID } from "../types.d.ts"; import { ID } from "../types.d.ts";
import asyncForEach from "../utils/asyncForeach.ts";
export default class Work { export default class Work {
#session: { #session: {
@ -76,13 +75,17 @@ export default class Work {
(t) => this.tags.push(t.children[0].innerText), (t) => this.tags.push(t.children[0].innerText),
); );
Array.from( Array.from(
(this.#document.querySelector("dd.relationship > ul.commas") as Element) (this.#document.querySelector(
"dd.relationship > ul.commas",
) as Element)
.children, .children,
).map( ).map(
(t) => this.tags.push(t.children[0].innerText), (t) => this.tags.push(t.children[0].innerText),
); );
Array.from( Array.from(
(this.#document.querySelector("dd.character > ul.commas") as Element) (this.#document.querySelector(
"dd.character > ul.commas",
) as Element)
.children, .children,
).map( ).map(
(t) => this.tags.push(t.children[0].innerText), (t) => this.tags.push(t.children[0].innerText),
@ -107,7 +110,8 @@ export default class Work {
//CW: horrifying jank //CW: horrifying jank
async populateChapters() { async populateChapters() {
const firstChapterUrl = const firstChapterUrl =
(this.#document.querySelector("li.chapter > a") as Element).getAttribute( (this.#document.querySelector("li.chapter > a") as Element)
.getAttribute(
"href", "href",
) as string + "?view_adult=true"; ) as string + "?view_adult=true";
const res = await this.#session.get(firstChapterUrl); const res = await this.#session.get(firstChapterUrl);
@ -116,8 +120,6 @@ export default class Work {
"text/html", "text/html",
) as HTMLDocument; ) as HTMLDocument;
const promises: Promise<void>[] = [];
Array.from((document.getElementById("selected_id") as Element).children) Array.from((document.getElementById("selected_id") as Element).children)
.sort( .sort(
(a, b) => { (a, b) => {
@ -125,20 +127,15 @@ export default class Work {
Number(b.getAttribute("value")); Number(b.getAttribute("value"));
}, },
).forEach((c) => { ).forEach((c) => {
promises.push((async (c: Element) => {
const newChapter = new Chapter( const newChapter = new Chapter(
this.id, this.id,
c.getAttribute("value") as string, c.getAttribute("value") as string,
this.#session, this.#session,
this.#DOMParser, this.#DOMParser,
); );
await 1; //shut up
this.chapters.push( this.chapters.push(
newChapter, 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].name == "Part I");
assert((await work.chapters[0].text).length > 0); assert((await work.chapters[0].text).length > 0);
/*
work = await ao3.getWork("39612636"); work = await ao3.getWork("39612636");
await work.init(); await work.init();
@ -40,4 +41,4 @@ assert(
assert( assert(
(await work.chapters[22].summary) === (await work.chapters[22].summary) ===
"Fizz tries to make the best out of his comeback", "Fizz tries to make the best out of his comeback",
); );.*/

Loading…
Cancel
Save