# post-carousel/4.0.3/src/blocks/explore-blocks.js

Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog &amp; News, version 4.0.3. 84 lines.

- Page: https://pluginprobe.com/plugins/post-carousel/4.0.3/code/src/blocks/explore-blocks.js
- Raw: https://pluginprobe.com/plugins/post-carousel/4.0.3/raw/src/blocks/explore-blocks.js
- Modified: 2026-06-09T12:18:02+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/post-carousel/4.0.3/code/src/blocks/explore-blocks.js#L10-L20`.

```javascript
window.addEventListener("load", function () {
    const url = new URL(window.location.href);

    // ====================
    // Pattern Library Handler
    // ====================

    if (url.searchParams.has("sp_pcp_pattern_library")) {
        function tryClickPatternButton() {
            const patternButton = document.querySelector(
                "#smart-post-library-modal-button"
            );
            if (patternButton) {
                patternButton.click();
                url.searchParams.delete("sp_pcp_pattern_library");
                history.replaceState(null, "", url.toString());
                return true;
            }
            return false;
        }

        // Try every 100ms for up to 2 seconds
        let patternAttempts = 0;
        const patternInterval = setInterval(() => {
            patternAttempts++;
            if (tryClickPatternButton() || patternAttempts > 20) {
                clearInterval(patternInterval);
            }
        }, 100);
    }

    // ====================
    // Block Inserter Handler
    // ====================

    if (!url.searchParams.has("spblock_inserter")) return;

    function tryScroll() {
        const headings = document.querySelectorAll(".block-editor-inserter__panel-title");
        const smartPostHeading = Array.from(headings).find(
            (h) => h.textContent.trim() === "SMART POST"
        );
        if (smartPostHeading) {
            smartPostHeading.scrollIntoView({
                behavior: "smooth",
                block: "start",
                inline: "nearest",
            });
            return true;
        }
        return false;
    }

    function tryClick() {
        const btn = document.querySelector(".editor-document-tools__inserter-toggle");
        if (btn) {
            btn.click();
            url.searchParams.delete("spblock_inserter");
            history.replaceState(null, "", url.toString());

            // Try to scroll every 100ms for up to 3 seconds
            let scrollAttempts = 0;
            const scrollInterval = setInterval(() => {
                scrollAttempts++;
                if (tryScroll() || scrollAttempts > 30) {
                    clearInterval(scrollInterval);
                }
            }, 100);

            return true;
        }
        return false;
    }

    // Try every 100ms for up to 2 seconds
    let attempts = 0;
    const interval = setInterval(() => {
        attempts++;
        if (tryClick() || attempts > 20) {
            clearInterval(interval);
        }
    }, 100);
});

```
