Skip to content

Instantly share code, notes, and snippets.

@klase
Created September 23, 2022 17:30
Show Gist options
  • Save klase/4842e4b72501528bb7503f56581f0d8b to your computer and use it in GitHub Desktop.
Save klase/4842e4b72501528bb7503f56581f0d8b to your computer and use it in GitHub Desktop.
Embargo custom button
<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