first commit
This commit is contained in:
commit
3e84da3dd1
24
js/ava_test_.js
Normal file
24
js/ava_test_.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
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();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
89
jstest.php
Normal file
89
jstest.php
Normal file
@ -0,0 +1,89 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Plugin Name: test
|
||||||
|
* Description: Rewrites the book-wrapper block using output buffering for Supapress pages.
|
||||||
|
* Version: 1.0
|
||||||
|
* Author: Kian
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_action('wp_enqueue_scripts','ava_test_init');
|
||||||
|
|
||||||
|
function ava_test_init() {
|
||||||
|
wp_enqueue_script( 'ava-test-js', plugins_url( '/js/ava_test_.js', __FILE__ ));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_action('template_redirect', function() {
|
||||||
|
if (is_singular()) {
|
||||||
|
ob_start('br_replace_book_wrapper');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return str_replace($book_block, $new_block, $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] ?? '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
var js_variable = '<?php echo $title;?>';
|
||||||
|
<script>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user