Instagram Reels Auto Open Comment Section

Opens the comment section when you scroll on Instagram Reels

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Instagram Reels Auto Open Comment Section
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Opens the comment section when you scroll on Instagram Reels
// @match        https://www.instagram.com/reels/*
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function () {
    const reelTimers = new WeakMap();
    const DELAY_MS = 2000;

    const openComments = (reel) => {
        const button = reel.querySelector('svg[aria-label="Comment"]')?.closest('[role="button"]');
        if (button) button.click();
    };

    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            const reel = entry.target;
            if (entry.isIntersecting && !reelTimers.has(reel)) {
                const timer = setTimeout(() => {
                    openComments(reel);
                    reelTimers.delete(reel);
                }, DELAY_MS);
                reelTimers.set(reel, timer);
            } else if (!entry.isIntersecting && reelTimers.has(reel)) {
                clearTimeout(reelTimers.get(reel));
                reelTimers.delete(reel);
            }
        });
    }, { threshold: 0.6 });

    const observeReels = () => {
        const reels = Array.from(document.querySelectorAll('div')).filter(div => div.querySelector('video'));
        reels.forEach(reel => observer.observe(reel));
    };

    observeReels();

    const mutationObserver = new MutationObserver(observeReels);
    mutationObserver.observe(document.body, { childList: true, subtree: true });
})();