replace js button with a FH button and item link
Thu Nov 14 2024 15:58:38 GMT+0000 (Coordinated Universal Time)
Saved by @Shira
<script>
jQuery(document).ready(function($){
// Define the HTML structure of the fhButton
const fhButtonTemplate = `
<div class="fhButton">
<a href="" style="font-size:1.15em !important; font-family: news_bold, sans-serif !important; font-weight:bold !important; letter-spacing: .7px !important; border: 2px solid #FFFFFF !important; box-shadow:none !important; padding: .2em 3.5em !important;" class="fh-lang-1 fh-button-true-flat-color">RESERVA ARA</a>
</div>`;
// Define hrefs and target elements for each button
const buttonMappings = [
{
target: 'body > div.contenidor_centrat > div > div:nth-child(2) > div.botons_curs > a',
href: 'https://fareharbor.com/embeds/book/unisub/?full-items=yes&flow=1283248'
},
{
target: 'body > div.contenidor_centrat > div > div:nth-child(4) > div.botons_curs > a',
href: 'https://fareharbor.com/embeds/book/unisub/items/588279/?full-items=yes&flow=1284556'
},
{
target: 'body > div.contenidor_centrat > div > div:nth-child(5) > div.botons_curs > a',
href: 'https://fareharbor.com/embeds/book/unisub/items/588275/?full-items=yes&flow=1284567'
},
{
target: 'body > div.contenidor_centrat > div > div:nth-child(6) > div.botons_curs > a',
href: 'https://fareharbor.com/embeds/book/unisub/items/588289/?full-items=yes&flow=1284557'
},
{
target: 'body > div.contenidor_centrat > div > div:nth-child(7) > div.botons_curs > a',
href: 'https://fareharbor.com/embeds/book/unisub/items/588292/?full-items=yes&flow=1284557'
},
{
target: 'body > div.contenidor_centrat > div > div:nth-child(8) > div.botons_curs > a',
href: 'https://fareharbor.com/embeds/book/unisub/items/588288/?full-items=yes&flow=1284558'
},
{
target: 'body > div.contenidor_centrat > div > div:nth-child(9) > div.botons_curs > a',
href: 'https://fareharbor.com/embeds/book/unisub/items/588344/?full-items=yes'
}
];
// Loop through button mappings to replace each target with customized fhButton
buttonMappings.forEach(function(mapping) {
// Create a jQuery object from the button template
const fhButton = $(fhButtonTemplate);
// Set the href attribute for the button's anchor tag
fhButton.find('a').attr('href', mapping.href);
// Replace the target element with the customized button
$(mapping.target).replaceWith(fhButton);
});
// Language-based text translation for buttons
const path = window.location.pathname;
const translations = {
'/ca/': 'RESERVA ARA',
'/it/': 'PRENOTA ORA',
'/pt/': 'RESERVE AGORA',
'/es/': 'RESERVA AHORA',
'/de/': 'JETZT BUCHEN',
'/nl/': 'BOEK NU',
'/fr/': 'RÉSERVEZ MAINTENANT',
'/en/': 'BOOK NOW'
};
// Find the correct translation based on the path
for (const [langPath, text] of Object.entries(translations)) {
if (path.includes(langPath)) {
$('a.fh-lang-1').text(text);
break;
}
}
});
</script>



Comments