evo99688 Posted April 7, 2022 Share Posted April 7, 2022 Hello All, I am trying to run a footer script to delete some elements from a Calendar block. For some reason querySelectorAll('item.item--ongoing') seems to be firing before the page fully loads even though I am checking for 'complete' ready state. When I run querySelectorAll in the browser console it picks them up so it's a loading issue. Is there a way to wait longer for the script to run? <script > (function () { if (window.NodeList && !NodeList.prototype.forEach) { NodeList.prototype.forEach = Array.prototype.forEach; } document.addEventListener('readystatechange', event => { if (document.readyState === "complete") { init() } }); function init() { var monthlyEl = document.querySelectorAll('.item.item--ongoing'); console.log('item--ongoing',monthlyEl.length) new MutationObserver(function() { init(); // myFunction2(); , etc... }).observe(document.body, {attributes:true, attributeFilter:["class"]}); })(); </script> Link to comment
Beyondspace Posted April 10, 2022 Share Posted April 10, 2022 On 4/7/2022 at 10:32 AM, evo99688 said: Hello All, I am trying to run a footer script to delete some elements from a Calendar block. For some reason querySelectorAll('item.item--ongoing') seems to be firing before the page fully loads even though I am checking for 'complete' ready state. When I run querySelectorAll in the browser console it picks them up so it's a loading issue. Is there a way to wait longer for the script to run? <script > (function () { if (window.NodeList && !NodeList.prototype.forEach) { NodeList.prototype.forEach = Array.prototype.forEach; } document.addEventListener('readystatechange', event => { if (document.readyState === "complete") { init() } }); function init() { var monthlyEl = document.querySelectorAll('.item.item--ongoing'); console.log('item--ongoing',monthlyEl.length) new MutationObserver(function() { init(); // myFunction2(); , etc... }).observe(document.body, {attributes:true, attributeFilter:["class"]}); })(); </script> Can you share your site with the protected password so I can take a look? BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox - Lightbox captions only mode) 🗓️ Delivery Date Picker (Squarespace Date picker form field) 💫 Gallery block 7.1 workaround 🥳 No-code customisations for Squarespace 🚀 Learn how to rank new pages on Google in 48 hours! If you find my answer useful, let's leave a like or upvote so others with the same issue can find their solution. Thank you! Link to comment
creedon Posted April 10, 2022 Share Posted April 10, 2022 I think calendar block use some form of lazy/just in time loading. You'll need to use a MutationObserver. MO's are designed to watch for things that change after the document ready state. Although the following code is not specific to your need you may be able to adapt it to your needs or use it as a guide. calendar block end time remove.html Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment