document.addEventListener("DOMContentLoaded",(()=>{const e=document.querySelector(".wp-block-gallery.load-more-gallery");if(!e)return;const t=document.createElement("div");t.className="wp-block-buttons is-content-justification-center is-layout-flex wp-block-buttons-is-layout-flex my-4";const l=document.createElement("button");l.className="ucla-btn ucla-btn--primary",l.id="load-more",l.textContent="Load More",t.insertAdjacentElement("beforeend",l),e.insertAdjacentElement("afterend",t),function(e){const t=Array.from(e.querySelectorAll("figure.wp-block-image"));if(0===t.length)return Promise.resolve();const l=t.map(((e,t)=>(t>4&&(e.style.display="none"),new Promise((t=>{const l=new Image;l.onload=()=>t(),l.onerror=()=>t(),l.src=e.querySelector("img").src})))));return Promise.all(l)}(e).then((()=>{e.querySelectorAll('figure.wp-block-image[style*="display: none"]').length<1&&(l.style.display="none"),l.addEventListener("click",(t=>{t.preventDefault();const n=e.querySelectorAll('figure.wp-block-image[style*="display: none"]');let o=0;for(let e=0;e<n.length&&o<4;e++)n[e].style.display="",o++;0===e.querySelectorAll('figure.wp-block-image[style*="display: none"]').length&&(l.style.display="none")}))}))}));