-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathspacebattles.js
More file actions
82 lines (62 loc) · 2.3 KB
/
spacebattles.js
File metadata and controls
82 lines (62 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { addContributor, cleanText, collectObject, getFormattedText, remapKeys } from "../shared/utils.js";
import { Extractor } from "./AbstractExtractor.js"
class spacebattlesScraper extends Extractor {
get _name() { return "Spacebattles Extractor"; }
needsReload = false;
_sitePatterns = [
/https:\/\/forums\.spacebattles\.com\/+threads\/.*?\.(\d+)\/(?!page)/
];
async getDetails() {
return collectObject([
{
"Publisher": "Spacebattles",
"Reading Format": "Ebook",
"Edition Format": "Web Novel",
},
getTitle(),
getDescription(),
getMetadata(),
]);
}
}
function getTitle() {
const title = cleanText(document.querySelector(`.p-title`)?.textContent ?? "");
if (!title) return {};
return { "Title": title }
}
function getDescription() {
let description = document.querySelector(`.threadmarkListingHeader-extraInfo article`);
if (!description) return {};
return { "Description": getFormattedText(description) }
}
function getMetadata() {
let details = {};
const contributors = details["Contributors"] ?? [];
val = document.querySelector(`.p-description .username`)?.textContent;
if (val) addContributor(contributors, val, "Author");
details["Contributors"] = contributors;
val = document.querySelector(`.tabPanes .collapseTrigger span`)?.textContent?.match(/(\d+) threadmark/)?.[1];
if (val) details["Chapters"] = val;
val = document.querySelectorAll(`.threadmarkListingHeader-stats dl`);
if (val && val.length > 0) for (const header of val) {
const titleEl = header.querySelector(`dt`);
const valueEl = header.querySelector(`dd`);
if (!titleEl || !valueEl) continue;
let title = cleanText(titleEl.textContent);
let value = cleanText(valueEl.textContent);
if (title === "Created") {
value = new Date(valueEl.querySelector(`time`)?.attributes["datetime"]?.value ?? value).toUTCString();
title = "Publication date";
}
details[title] = value;
}
details = remapKeys({
"Watchers": undefined,
"Recent readers": undefined,
"Threadmarks": undefined,
}, details);
// const tags = [...document.querySelectorAll(`.tagList dd a`)].map(i => cleanText(i.textContent));
// if (tags && tags.length > 0) details["Tags"] = tags;
return details;
}
export { spacebattlesScraper };