Instagram Reels Auto Open Comment Section

Opens the comment section when you scroll on Instagram Reels

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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 });
})();