From 3f5df32e90a91c27067c8aa1e71f8919804d00f8 Mon Sep 17 00:00:00 2001 From: "Darren J. de Lima" Date: Sun, 22 Sep 2024 17:10:15 +0100 Subject: [PATCH] MagicWizardsParser v0.7. Minor changes as requested --- .gitignore | 3 ++- plugin/js/parsers/MagicWizardsParser.js | 23 +++++++---------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index ab992ea0..7ec7350c 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/plugin/js/parsers/MagicWizardsParser.js b/plugin/js/parsers/MagicWizardsParser.js index 72ee3ce3..bbb97c4c 100644 --- a/plugin/js/parsers/MagicWizardsParser.js +++ b/plugin/js/parsers/MagicWizardsParser.js @@ -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 @@ -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; -} }