Created
September 23, 2022 17:30
-
-
Save klase/4842e4b72501528bb7503f56581f0d8b to your computer and use it in GitHub Desktop.
Embargo custom button
This file contains hidden or 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> | |
(function () { | |
const insertButtons = (containerNode) => { | |
containerNode | |
.querySelectorAll(".fixr-event-item__footer") | |
.forEach((node) => { | |
if (node.querySelector("[data-external-button]")) return; | |
const item = node.firstChild.cloneNode(true); | |
item.style.marginRight = "auto"; | |
item.style.marginLeft = "16px"; | |
item.addEventListener("click", () => { | |
$("#enquirePopupModal").modal("show"); | |
}); | |
item.setAttribute("data-external-button", true); | |
const buttonText = item.querySelector("button > div"); | |
buttonText.innerText = "Get Table"; | |
node.firstChild.insertAdjacentElement("afterend", item); | |
}); | |
}; | |
const observeTicketshop = () => { | |
const targetNode = document.querySelector(".fixr-events-widget"); | |
insertButtons(targetNode); | |
const config = { | |
attributes: false, | |
childList: true, | |
subtree: true, | |
}; | |
const callback = (mutationList, observer) => { | |
insertButtons(targetNode); | |
}; | |
const observer = new MutationObserver(callback); | |
observer.observe(targetNode, config); | |
}; | |
window.addEventListener("message", (e) => { | |
if (e.data && e.data.message === "fixr.widget:loaded") { | |
observeTicketshop(); | |
} | |
}); | |
})(); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment