Skip to content

Commit

Permalink
MagicWizardsParser.js v.71
Browse files Browse the repository at this point in the history
Improves compatibility with 2016 version of site
  • Loading branch information
Darthagnon committed Sep 22, 2024
1 parent 3f5df32 commit bfda6d9
Showing 1 changed file with 11 additions and 20 deletions.
31 changes: 11 additions & 20 deletions plugin/js/parsers/MagicWizardsParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@ class MagicWizardsParser extends Parser {
// Extract the list of chapter URLs
async getChapterUrls(dom) {
let chapterLinks = [];
if (window.location.hostname.includes("web.archive.org")) {
// For archived versions, select the correct container within #content
chapterLinks = [...dom.querySelectorAll("#content article a, #content .article-content a")];
} else {
// For live pages
chapterLinks = [...dom.querySelectorAll("article a, .article-content a, window.location.hostname")];
}

// Filter out author links using their URL pattern
chapterLinks = chapterLinks.filter(link => !this.isAuthorLink(link));

return chapterLinks.map(this.linkToChapter);
chapterLinks = [...dom.querySelectorAll("article a, .article-content a, window.location.hostname, #content article a, #content .article-content a, .articles-listing .article-item a, .articles-bloc .article .details a")];
// Filter out author links using their URL pattern
chapterLinks = chapterLinks.filter(link => !this.isAuthorLink(link));
return chapterLinks.map(this.linkToChapter);
}

// Helper function to detect if a link is an author link
Expand All @@ -47,7 +39,12 @@ class MagicWizardsParser extends Parser {
let titleElement;

// Try to find the <h3> tag inside the parent of the link (assuming link is inside <article>)
titleElement = link.closest("article").querySelector("h3");
titleElement = link.closest("article")?.querySelector("h3");

// Fallback to the <p class="title"> if no <h3> is found
if (!titleElement) {
titleElement = link.closest(".article-item")?.querySelector(".title");
}

// Fallback to the link text itself if no titleElement found (this handles simpler cases)
let title = titleElement ? titleElement.textContent.trim() : link.textContent.trim();
Expand All @@ -60,13 +57,7 @@ class MagicWizardsParser extends Parser {

// Extract the content of the chapter
findContent(dom) {
if (window.location.hostname.includes("web.archive.org")) {
// For archived pages, the content is often inside #content
return dom.querySelector("#content article");
} else {
// For live pages
return dom.querySelector("#article-body article, #primary-area section, section article, section");
}
return dom.querySelector("#content article, .article_detail #main-content article, #article-body article, #primary-area section, section article, section, .article_detail #main-content");
}

// Grab cover image
Expand Down

0 comments on commit bfda6d9

Please sign in to comment.