Instagram Embed Loader

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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 });
    });
})();