first commit
This commit is contained in:
parent
df5072201b
commit
d4978a7122
BIN
assets/cart_add.png
Normal file
BIN
assets/cart_add.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
@ -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();
|
||||
});
|
||||
|
||||
|
||||
|
||||
22
js/main.js
Normal file
22
js/main.js
Normal file
@ -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
|
||||
})();
|
||||
23
js/search_shop_link.js
Normal file
23
js/search_shop_link.js
Normal file
@ -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 = `<a class="shop_link" href="https://cdcshoppingcart.uchicago.edu/Cart2/ChicagoBook?ISBN=${isbn}&PRESS=wvp" target="_blank">
|
||||
<img src="${imageUrl}" alt="Shop Link">
|
||||
</a>`;
|
||||
|
||||
wrapper.appendChild(shopLink);
|
||||
});
|
||||
|
||||
clearInterval(interval);
|
||||
}, 100);
|
||||
})(window.searchShopLinkImageUrl); // Pass URL dynamically
|
||||
57
jstest.php
57
jstest.php
@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: the_content
|
||||
* Description: test to see if the_content works
|
||||
* Version: 1.0
|
||||
* Author: Kian
|
||||
*/
|
||||
|
||||
|
||||
|
||||
add_filter('the_content', 'test_replace_tabs_on_book_wrapper', 30);
|
||||
|
||||
function test_replace_tabs_on_book_wrapper($content) {
|
||||
|
||||
if (strpos($content, 'book-wrapper') === false) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
libxml_use_internal_errors(true);
|
||||
$dom = new DOMDocument('1.0', 'UTF-8');
|
||||
$dom->loadHTML('<?xml encoding="utf-8" ?>' . $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), '<p>TEST AUTHOR CONTENT</p>');
|
||||
}
|
||||
|
||||
if ($panels->item(1)) {
|
||||
replace_panel_html($dom, $panels->item(1), '<p>TEST SUMMARY CONTENT</p>');
|
||||
}
|
||||
|
||||
if ($panels->item(2)) {
|
||||
replace_panel_html($dom, $panels->item(2), '<p>TEST REVIEWS CONTENT</p>');
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
151
plugin.php
Normal file
151
plugin.php
Normal file
@ -0,0 +1,151 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: Book Page Reformatter with tabs!
|
||||
* Description: Rewrites the book-wrapper block using output buffering for Supapress pages.
|
||||
* Version: 2.0
|
||||
* Author: Kian
|
||||
*/
|
||||
|
||||
|
||||
function enqueue_theme_assets(){
|
||||
|
||||
|
||||
wp_enqueue_script( 'main', plugins_url( '/js/main.js', __FILE__ ));
|
||||
}
|
||||
|
||||
|
||||
add_action( 'wp_enqueue_scripts', 'enqueue_theme_assets' );
|
||||
|
||||
add_action('template_redirect', function() {
|
||||
if (is_singular()) {
|
||||
|
||||
ob_start('br_replace_book_wrapper');
|
||||
ob_start('br_replace_book_link');
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
function enqueue_shop_links_script() {
|
||||
if (is_singular()) {
|
||||
wp_enqueue_script('search_shop_link',plugins_url('/js/search_shop_link.js', __FILE__));
|
||||
wp_add_inline_script( 'search_shop_link', 'window.searchShopLinkImageUrl = "' . plugins_url('assets/cart_add.png', __FILE__) . '";' );
|
||||
|
||||
}
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'enqueue_shop_links_script');
|
||||
|
||||
|
||||
|
||||
function br_replace_book_wrapper($html) {
|
||||
if (strpos($html, 'product-details') === false) {
|
||||
return $html;
|
||||
}
|
||||
|
||||
preg_match('/<div class="book-wrapper">(.*?)<\/div>\s*<\/div>/s', $html, $match);
|
||||
|
||||
if (!isset($match[0])) return $html;
|
||||
|
||||
$book_block = $match[0];
|
||||
|
||||
$cover = extract_attr($book_block, '/<img[^>]*src="([^"]+)"/');
|
||||
$title = extract_text($book_block, '/<div class="title-wrapper">\s*<h1>(.*?)<\/h1>/');
|
||||
$author = extract_text($book_block, '/<p class="sp__the-author">(.*?)<\/p>/');
|
||||
$publisher = extract_text($book_block, '/<p class="sp__the-publisher">(.*?)<\/p>/');
|
||||
$imprint = extract_text($book_block, '/<p class="sp__the-imprint">(.*?)<\/p>/');
|
||||
$series = extract_text($book_block, '/<p class="sp__the-series">(.*?)<\/p>/');
|
||||
$isbn13 = extract_text($book_block, '/<p class="sp__the-isbn13">(.*?)<\/p>/');
|
||||
$price = extract_text($book_block, '/<p class="sp__the-price">(.*?)<\/p>/');
|
||||
$format = extract_text($book_block, '/<p class="sp__the-format">(.*?)<\/p>/');
|
||||
$pubdate = extract_text($book_block, '/<p class="sp__the-publication-date">(.*?)<\/p>/');
|
||||
$pages = extract_text($book_block, '/<p class="sp__the-pages">(.*?)<\/p>/');
|
||||
$summary = extract_html($book_block, '/<div class="sp__the-summary">(.*?)<\/div>/s');
|
||||
$description= extract_html($book_block, '/<div class="sp__the-description">(.*?)<\/div>/s');
|
||||
$reviews = extract_html($book_block, '/<div class="sp__the-reviews">(.*?)<\/div>/s');
|
||||
|
||||
|
||||
|
||||
$html = preg_replace_callback(
|
||||
'/(<div role="tabpanel" class="wp-block-ub-tabbed-content-tab-content-wrap.*?"[^>]*>)(.*?)(<\/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 '<style>
|
||||
|
||||
.information-wrapper {
|
||||
display: none !important;
|
||||
}
|
||||
.sp__the-subtitle{
|
||||
display: none !important;
|
||||
|
||||
}
|
||||
|
||||
.sp__the-author{
|
||||
display: none !important;
|
||||
|
||||
}
|
||||
|
||||
.sp__the-author-bio{
|
||||
display: none !important;
|
||||
|
||||
}
|
||||
.sp__the-publisher{
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.sp__the-imprint{ display: none !important;
|
||||
}
|
||||
|
||||
.sp__the-isbn13{ display: none !important;
|
||||
}
|
||||
.sp__the-price{ display: none !important;
|
||||
}
|
||||
|
||||
.sp__the-format{ display: none !important;
|
||||
}
|
||||
|
||||
.sp__the-publication-date{ display: none !important;
|
||||
}
|
||||
|
||||
.sp__the-sales-date{ display: none !important;
|
||||
}
|
||||
|
||||
.sp__the-series{
|
||||
display: none !important;
|
||||
}
|
||||
</style>';
|
||||
});
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user