diff --git a/assets/cart_add.png b/assets/cart_add.png new file mode 100644 index 0000000..0eb83e4 Binary files /dev/null and b/assets/cart_add.png differ diff --git a/js/ava_test_.js b/js/ava_test_.js deleted file mode 100644 index 3a610b3..0000000 --- a/js/ava_test_.js +++ /dev/null @@ -1,24 +0,0 @@ -function popup(){ - - -alert('hello there this is a test popup'); -console.log("hellooooo"); - -} - - -function replace_text(){ - - var x= document.getElementById("ub-tabbed-content-f5da2756-8434-41cd-aa83-ec95a71a9c26-panel-0"); - x.innerHTML=js_variable; - -} - -document.addEventListener("DOMContentLoaded", function () { - popup(); - - replace_text(); -}); - - - diff --git a/js/main.js b/js/main.js new file mode 100644 index 0000000..e28db78 --- /dev/null +++ b/js/main.js @@ -0,0 +1,22 @@ +var counter=0; + +(function waitForISBN() { + const interval = setInterval(() => { + const isbnEl = document.querySelector(".sp__the-isbn13"); + + if (!isbnEl){ + +return; + } // keep waiting + + const isbn = isbnEl.textContent.trim(); + const link = document.querySelector(".wp-block-image.size-full a"); + + if (link) { + link.href = `https://cdcshoppingcart.uchicago.edu/Cart2/ChicagoBook?ISBN=${isbn}&PRESS=wvp`; + console.log("Cart link updated:", isbn); + } + + clearInterval(interval); // stop checking once done + }, 100); // check every 100ms +})(); diff --git a/js/search_shop_link.js b/js/search_shop_link.js new file mode 100644 index 0000000..13dd97c --- /dev/null +++ b/js/search_shop_link.js @@ -0,0 +1,23 @@ +(function waitForBookWrappers(imageUrl) { + const interval = setInterval(() => { + const bookWrappers = document.querySelectorAll(".book-wrapper"); + if (bookWrappers.length === 0) return; + + bookWrappers.forEach(wrapper => { + const coverLink = wrapper.querySelector(".sp__the-cover a"); + if (!coverLink || wrapper.querySelector(".shop_link")) return; + + const hrefParts = coverLink.getAttribute("href").split("/"); + const isbn = hrefParts[1]; + + const shopLink = document.createElement("p"); + shopLink.innerHTML = ` + Shop Link + `; + + wrapper.appendChild(shopLink); + }); + + clearInterval(interval); + }, 100); +})(window.searchShopLinkImageUrl); // Pass URL dynamically diff --git a/jstest.php b/jstest.php deleted file mode 100644 index 104eaa2..0000000 --- a/jstest.php +++ /dev/null @@ -1,57 +0,0 @@ -loadHTML('' . $content); - $xpath = new DOMXPath($dom); - - $panels = $xpath->query( - "//*[contains(@class,'wp-block-ub-tabbed-content-tab-content-wrap')]" - ); - - if ($panels->length === 0) { - return $content; - } - - if ($panels->item(0)) { - replace_panel_html($dom, $panels->item(0), '

TEST AUTHOR CONTENT

'); - } - - if ($panels->item(1)) { - replace_panel_html($dom, $panels->item(1), '

TEST SUMMARY CONTENT

'); - } - - if ($panels->item(2)) { - replace_panel_html($dom, $panels->item(2), '

TEST REVIEWS CONTENT

'); - } - - return $dom->saveHTML(); -} - - - -function replace_panel_html($dom, $panel, $html) { - while ($panel->firstChild) { - $panel->removeChild($panel->firstChild); - } - - $fragment = $dom->createDocumentFragment(); - $fragment->appendXML($html); - $panel->appendChild($fragment); -} diff --git a/plugin.php b/plugin.php new file mode 100644 index 0000000..c3271df --- /dev/null +++ b/plugin.php @@ -0,0 +1,151 @@ +(.*?)<\/div>\s*<\/div>/s', $html, $match); + + if (!isset($match[0])) return $html; + + $book_block = $match[0]; + + $cover = extract_attr($book_block, '/]*src="([^"]+)"/'); + $title = extract_text($book_block, '/
\s*

(.*?)<\/h1>/'); + $author = extract_text($book_block, '/

(.*?)<\/p>/'); + $publisher = extract_text($book_block, '/

(.*?)<\/p>/'); + $imprint = extract_text($book_block, '/

(.*?)<\/p>/'); + $series = extract_text($book_block, '/

(.*?)<\/p>/'); + $isbn13 = extract_text($book_block, '/

(.*?)<\/p>/'); + $price = extract_text($book_block, '/

(.*?)<\/p>/'); + $format = extract_text($book_block, '/

(.*?)<\/p>/'); + $pubdate = extract_text($book_block, '/

(.*?)<\/p>/'); + $pages = extract_text($book_block, '/

(.*?)<\/p>/'); + $summary = extract_html($book_block, '/

(.*?)<\/div>/s'); + $description= extract_html($book_block, '/
(.*?)<\/div>/s'); + $reviews = extract_html($book_block, '/
(.*?)<\/div>/s'); + + + +$html = preg_replace_callback( + '/(
]*>)(.*?)(<\/div>)/s', + function($matches) use ($description, $author, $reviews) { + static $i = 0; + $replacement = ''; + if ($i === 0) $replacement = $description; + elseif ($i === 1) $replacement = 'Hello World!'; + elseif ($i === 2) $replacement = $author; + elseif ($i === 3) $replacement = $reviews; + $i++; + return $matches[1] . $replacement . $matches[3]; + }, + $html + ); + + return $html; +} + +function extract_text($html, $pattern) { + preg_match($pattern, $html, $m); + return $m[1] ?? ''; +} + +function extract_attr($html, $pattern) { + preg_match($pattern, $html, $m); + return $m[1] ?? ''; +} + +function extract_html($html, $pattern) { + preg_match($pattern, $html, $m); + return $m[1] ?? ''; +} + + +//gets rid of information and image wrapper +add_action('wp_head', function() { + echo ''; +}); + +