Hide Liked Posts on Instagram (Auto Scroll)

Hides posts you've liked on instagram.com and auto-scrolls to load all content

当前为 2025-07-07 提交的版本,查看 最新版本

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Hide Liked Posts on Instagram (Auto Scroll)
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Hides posts you've liked on instagram.com and auto-scrolls to load all content
// @author       luascfl (improved)
// @match        https://www.instagram.com/*
// @home         https://github.com/luascfl/hide-liked-posts-instagram
// @supportURL   https://github.com/luascfl/hide-liked-posts-instagram/issues
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    let isAutoScrolling = false;
    let loadingSpinnerLastSeen = null;
    let scrollInterval = null;
    let checkInterval = null;

    // Function to hide liked posts
    function hideLikedPosts() {
        const posts = document.querySelectorAll('article');
        posts.forEach(post => {
            const likeIcon = post.querySelector('svg[aria-label="Descurtir"]');
            if (likeIcon && post.style.display !== 'none') {
                post.style.display = 'none';
            }
        });
    }

    // Function to check if loading spinner exists
    function isLoadingSpinnerPresent() {
        // Procura o SVG de carregamento específico ou qualquer SVG com aria-label="Carregando..."
        const spinner = document.querySelector('svg[aria-label="Carregando..."]');
        return spinner !== null;
    }

    // Function to scroll to bottom
    function scrollToBottom() {
        window.scrollTo({
            top: document.documentElement.scrollHeight,
            behavior: 'smooth'
        });
    }

    // Function to start auto-scrolling
    function startAutoScroll() {
        if (isAutoScrolling) return;
        
        console.log('Iniciando auto-scroll...');
        isAutoScrolling = true;
        loadingSpinnerLastSeen = Date.now();

        // Scroll interval - desce a página a cada 1 segundo
        scrollInterval = setInterval(() => {
            scrollToBottom();
            hideLikedPosts(); // Esconde posts curtidos enquanto faz scroll
        }, 1000);

        // Check interval - verifica o spinner a cada 500ms
        checkInterval = setInterval(() => {
            if (isLoadingSpinnerPresent()) {
                loadingSpinnerLastSeen = Date.now();
                console.log('Spinner de carregamento detectado');
            } else {
                const timeSinceLastSpinner = Date.now() - loadingSpinnerLastSeen;
                
                if (timeSinceLastSpinner >= 5000) {
                    console.log('Spinner não detectado por 5 segundos. Parando auto-scroll.');
                    stopAutoScroll();
                }
            }
        }, 500);
    }

    // Function to stop auto-scrolling
    function stopAutoScroll() {
        if (!isAutoScrolling) return;

        console.log('Auto-scroll finalizado');
        isAutoScrolling = false;
        
        if (scrollInterval) {
            clearInterval(scrollInterval);
            scrollInterval = null;
        }
        
        if (checkInterval) {
            clearInterval(checkInterval);
            checkInterval = null;
        }

        // Faz uma última verificação para esconder posts curtidos
        hideLikedPosts();
    }

    // Function to observe content dynamically
    function observeContent() {
        const feed = document.querySelector('main');
        if (feed) {
            const observer = new MutationObserver(() => {
                hideLikedPosts();
            });

            observer.observe(feed, { childList: true, subtree: true });
            hideLikedPosts();
        }
    }

    // Adiciona botão para iniciar/parar auto-scroll manualmente
    function addControlButton() {
        const button = document.createElement('button');
        button.textContent = '▼ Auto Scroll';
        button.style.cssText = `
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 9999;
            background: #262626;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 20px;
            cursor: pointer;
            font-weight: bold;
            box-shadow: 0 2px 10px rgba(0,0,0,0.3);
        `;

        button.addEventListener('click', () => {
            if (isAutoScrolling) {
                stopAutoScroll();
                button.textContent = '▼ Auto Scroll';
                button.style.background = '#262626';
            } else {
                startAutoScroll();
                button.textContent = '■ Parar Scroll';
                button.style.background = '#e60023';
            }
        });

        document.body.appendChild(button);
    }

    // Aguarda a página carregar e inicia
    setTimeout(() => {
        observeContent();
        addControlButton();
        
        // Inicia auto-scroll automaticamente (remova esta linha se quiser controle manual)
        startAutoScroll();
    }, 2000);

})();