Last active
February 2, 2021 07:50
-
-
Save tvlgiao/4a42072b758c9bb8386a0d2211403437 to your computer and use it in GitHub Desktop.
pharmacy.nu Display Reward Points below Product Price on PDP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/plain" id="custom_css_71651347e4777b82"> | |
.productView-price._rewardsLoaded { | |
width: 100%; | |
} | |
.pharmacynu__rewards { | |
clear: both; | |
display: flex; | |
align-items: center; | |
font-size: 14px; | |
font-weight: bold; | |
color: #ce8c15; | |
padding: .75rem 0; | |
} | |
.pharmacynu__rewards ._icon { | |
width: 30px; | |
height: 30px; | |
background-color: #ce8c15; | |
border-radius: 15px; | |
overflow: hidden; | |
padding: 5px; | |
margin-right: 10px; | |
} | |
.pharmacynu__rewards ._icon svg { | |
width: 100%; | |
height: 100%; | |
} | |
@media (min-width: 801px) { | |
.productView-price._rewardsLoaded { | |
position: relative; | |
padding-right: 180px; | |
} | |
.pharmacynu__rewards { | |
position: absolute; | |
top: 0; | |
right: 0; | |
} | |
} | |
</script> | |
<script type="text/plain" id="custom_html_71651347e4777b82"> | |
<div class="pharmacynu__rewards"> | |
<span class="_icon"> | |
<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 30 30"> | |
<path fill="rgb(255,255,255)" fill-rule="evenodd" d="M8 8V7a5 5 0 0 1 10 0v1h3.446a2 2 0 0 1 1.991 1.818l.42 4.597a1 1 0 0 1-1.992.182L21.445 10H18v2a1 1 0 0 1-2 0v-2h-6v2a1 1 0 0 1-2 0v-2H4.554a165320.029 165320.029 0 0 0-1.457 16H15a1 1 0 0 1 0 2H2.548a1.5 1.5 0 0 1-1.5-1.5c.008-.15.008-.15.027-.353l.071-.78.283-3.113L2.563 9.818A2 2 0 0 1 4.554 8H8zm2 0h6V7a3 3 0 0 0-6 0v1zm18.002 9.76a3.854 3.854 0 0 1-.13 5.535l-4.643 4.616a1 1 0 0 1-1.41 0l-4.646-4.613c-.041-.044-.085-.086-.127-.13a3.854 3.854 0 0 1 0-5.408c1.477-1.494 4.527-1.099 5.478 1.202.96-2.298 4-2.696 5.478-1.202z"/> | |
</svg> | |
</span> | |
<span class="_text">Earn <span class="_point"></span> Power Points</span> | |
</div> | |
</script> | |
<script> | |
(function() { | |
function debounce(n,t,u){var e;return function(){var i=this,o=arguments,a=u&&!e;clearTimeout(e),e=setTimeout(function(){e=null,u||n.apply(i,o)},t),a&&n.apply(i,o)}} | |
function css() { | |
var style = document.createElement('style'); | |
style.innerHTML = document.getElementById('custom_css_71651347e4777b82').innerHTML; | |
document.head.appendChild(style); | |
} | |
function jqueryReady($) { | |
function onDOMChanged() { | |
$('.productView-price').not('._rewardsLoaded').each(function(i, el) { | |
var $el = $(el) | |
.addClass('_rewardsLoaded') | |
.append($('#custom_html_71651347e4777b82').html()); | |
var $rewards = $el.find('.pharmacynu__rewards').hide(); | |
$el.find('[data-product-price-with-tax]').each(function(j, priceEl) { | |
var $priceEl = $(priceEl); | |
var priceChanged = function() { | |
var num = Math.floor(Number(String($priceEl.text().split('-')[0]).replace(/[^0-9,.]/g, ''))); | |
if (!isNaN(num)) { | |
$rewards.find('._point').text(num); | |
$rewards.show(); | |
} else { | |
$rewards.hide(); | |
} | |
}; | |
(new MutationObserver(priceChanged)).observe(priceEl, { childList: true, subtree: true }); | |
priceChanged(); | |
}); | |
}); | |
} | |
var mo = new MutationObserver(debounce(onDOMChanged, 300)); | |
mo.observe(document.body, { childList: true, subtree: true }); | |
onDOMChanged(); | |
} | |
window.addEventListener('DOMContentLoaded', function() { | |
css(); | |
jqueryReady(window.jQuerySupermarket || window.jQuery); | |
}); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment