Created
March 13, 2021 06:19
-
-
Save husseyexplores/5848ad1a87e71d4397fa573277c6121b to your computer and use it in GitHub Desktop.
[Shopify Prevent Preview Bar] Prevents loading Shopify preview bar scripts #shopify #previewbar
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> | |
| let removeCount = 0; | |
| window.mobserver = new MutationObserver(function(mutations) { | |
| mutations.forEach(function(mutation) { | |
| mutation.addedNodes.forEach((node) => { | |
| var nodeName = node.nodeName | |
| if (nodeName === 'SCRIPT') { | |
| const script = mutation.addedNodes[0]; | |
| if(script.src.includes('/storefront/bars')) { | |
| script.src = ''; | |
| script.remove(); | |
| console.log('%cAdmin bars js removed', 'padding: 4px 8px; background: darkgreen; font-family: monospace;'); | |
| removeCount++; | |
| if (removeCount == 2) { | |
| window.mobserver.disconnect(); | |
| } | |
| } | |
| } else if (nodeName === 'LINK') { | |
| var el = mutation.addedNodes[0]; | |
| if (el.href.includes('assets/admin/style')) { | |
| el.href = ''; | |
| el.remove(); | |
| console.log('%cAdmin css removed', 'padding: 4px 8px; background: darkgreen; font-family: monospace;'); | |
| removeCount++; | |
| if (removeCount == 2) { | |
| window.mobserver.disconnect(); | |
| } | |
| } | |
| } | |
| }); | |
| }); | |
| }); | |
| window.mobserver.observe(document.documentElement, { | |
| attributes: true, | |
| characterData: true, | |
| childList: true, | |
| subtree: true, | |
| attributeOldValue: true, | |
| characterDataOldValue: true | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment