Instagram Embed Loader

強制載入 Instagram 嵌入區塊 (embed)

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Instagram Embed Loader
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  強制載入 Instagram 嵌入區塊 (embed)
// @match        https://nishispo.nishinippon.co.jp/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 動態插入 Instagram embed.js
    function loadInstagramEmbed() {
        if (!document.querySelector('script[src*="instagram.com/embed.js"]')) {
            let s = document.createElement('script');
            s.src = "https://www.instagram.com/embed.js";
            s.async = true;
            document.body.appendChild(s);
        } else {
            if (window.instgrm && window.instgrm.Embeds) {
                window.instgrm.Embeds.process();
            }
        }
    }

    // 頁面載入後執行
    window.addEventListener('load', () => {
        loadInstagramEmbed();

        // 監聽 DOM 變化,確保動態載入的區塊也能渲染
        const observer = new MutationObserver(() => {
            if (window.instgrm && window.instgrm.Embeds) {
                window.instgrm.Embeds.process();
            }
        });
        observer.observe(document.body, { childList: true, subtree: true });
    });
})();