Created
October 13, 2022 02:43
-
-
Save smashah/2b5552b53caede5c8fe602fef6f74b18 to your computer and use it in GitHub Desktop.
Prevent gumroad cart messing with docusaurus. Reposition cart button sensibly on docusaurus.
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
(new MutationObserver((mutationList, observer) => { | |
for (const mutation of mutationList) { | |
if(mutation.type === "childList" && mutation.addedNodes.find(node=>node.className==="gumroad")) { | |
console.log('Gattem', mutation); | |
const grNode = mutation.addedNodes.find(node=>node.className==="gumroad") | |
const cartbtn = grNode.getElementsByClassName('cart-button')[0] | |
grNode.style.position = cartbtn.style.position = '' | |
grNode.style.padding = '4px' | |
const isMobile = !!document.getElementsByClassName('menu__list').length | |
const addTo = document.getElementsByClassName('menu__list')[0] || document.getElementsByClassName("navbar__items navbar__items--right")[0] | |
if(isMobile) { | |
addTo.appendChild(grNode); | |
grNode.style.padding = '16px' | |
grNode.style.width = cartbtn.style.width = '-webkit-fill-available' | |
} | |
else addTo.insertBefore(grNode,document.getElementsByClassName('DocSearch DocSearch-Button')[0].parentElement) | |
} | |
} | |
})).observe(document.body, {childList: true, subtree: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment