From 8df43548d451a37a76441986b5620cf84609c59d Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Mon, 9 Dec 2024 01:15:00 +0100 Subject: Add script injector --- Api/coverscript.js | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 Api/coverscript.js (limited to 'Api/coverscript.js') diff --git a/Api/coverscript.js b/Api/coverscript.js new file mode 100644 index 0000000..24f3c34 --- /dev/null +++ b/Api/coverscript.js @@ -0,0 +1,64 @@ +(function () { + /** + * + * @param {HTMLElement} element + * @param {string} selector + * @returns {HTMLElement | null} + */ + function findParent(element, selector) { + let p = element + while (p) { + if (p.matches(selector)) return p + p = p.parentNode + } + return null + } + + const injectionMarker = "JCoverXtremePro-injection-marker"; + + /** + * + * @param {HTMLElement} cloneFrom + * @return {HTMLElement} + */ + function createDownloadSeriesButton(cloneFrom) { + /**/ + //import LayersIcon from '@mui/icons-material/Layers'; + //import CloudDownloadIcon from '@mui/icons-material/CloudDownload'; + const element = document.createElement("button") + element.classList.add(...cloneFrom.classList) + element.classList.add(injectionMarker) + element.title = "Download Series" + const icon = document.createElement("span") + icon.classList.add("material-icons", "burst_mode") + icon.setAttribute("aria-hidden", "true") + element.appendChild(icon) + element.addEventListener("click", ev => { + ev.preventDefault() + + alert("YOU HAVE JUST BEEN INTERDICTED BY THE JCOVERXTREMEPRO SERIES DOWNLOADIFICATOR") + }) + return element + } + + const observer = new MutationObserver(() => { + console.log("JCoverXtremePro observation was triggered!") + console.log("Listing all download buttons") + /** + * @type {NodeListOf} + */ + const buttons = document.querySelectorAll(".imageEditorCard .cardFooter .btnDownloadRemoteImage") + + buttons.forEach(element => { + const downloadRowContainer = findParent(element, ".cardText") + if (downloadRowContainer.querySelector(`.${injectionMarker}`)) return + // TODO: extract information about the series, and check if this is at all viable + downloadRowContainer.appendChild(createDownloadSeriesButton(element)) + }) + + }) + observer.observe(document.body, {// TODO: selectively observe the body if at all possible + subtree: true, + childList: true, + }); +})() \ No newline at end of file -- cgit