Skip to content

Instantly share code, notes, and snippets.

@enomoto
Created April 26, 2024 10:39
Show Gist options
  • Save enomoto/fea27008e00fadfb2d916cd2c1046d78 to your computer and use it in GitHub Desktop.
Save enomoto/fea27008e00fadfb2d916cd2c1046d78 to your computer and use it in GitHub Desktop.
const hideHeaderAndFooter = (document) => {
const noneDisplayQuerySelectors = [
"#shopify-section-announcement-bar",
"#shopify-section-announcement",
"#shopify-section-header",
"#shopify-section-footer",
"shop-login-button"
]
noneDisplayQuerySelectors.forEach((querySelector) => {
const element = document.querySelector(querySelector)
if (element !== null) {
element.style.display = "none"
}
})
}
const trimHeaderSpace = (document) => {
const element = document.querySelector(".bodyWrap")
if (element !== null) {
element.style.paddingTop = "0"
}
}
const target = document
const observer = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
const document = mutation.target
hideHeaderAndFooter(document)
trimHeaderSpace(document)
})
})
const config = {
subtree: true,
characterData: true,
childList: true
}
observer.observe(target, config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment