Skip to content

Commit

Permalink
MagicWizardsParser v0.7. Minor changes as requested
Browse files Browse the repository at this point in the history
  • Loading branch information
Darthagnon committed Sep 22, 2024
1 parent 1e81d43 commit 3f5df32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ eslint/packed.js
eslint/index.csv
node_modules
!plugin/**/*.*
!plugin/jszip/dist/jszip.min.js
plugin/jszip/dist/jszip.min.js
package-lock.json
23 changes: 7 additions & 16 deletions plugin/js/parsers/MagicWizardsParser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*
parser for mtgstory.com (redirect)
*/
"use strict";

// Register the parser for magic.wizards.com (archive.org is implicit) TODO: mtglore.com
Expand Down Expand Up @@ -65,23 +68,11 @@ class MagicWizardsParser extends Parser {
return dom.querySelector("#article-body article, #primary-area section, section article, section");
}
}

findCoverImageUrl(dom) {
// Try to find an image inside the '.swiper-slide' or inside an 'article'
let imgElement = dom.querySelector(".swiper-slide img, article img");

// If an image is found, return its 'src' attribute
if (imgElement) {
return imgElement.getAttribute("src");
// Check if the URL starts with '//' (protocol-relative URL)
if (imgSrc && imgSrc.startsWith("//")) {
// Add 'https:' to the start of the URL
imgSrc = "https:" + imgSrc;
}

// Grab cover image
findCoverImageUrl(dom) {
return util.getFirstImgSrc(dom, ".swiper-slide img, article img");
}
// Fallback if no image was found
return null;
}


}

0 comments on commit 3f5df32

Please sign in to comment.