Hide Liked Posts on Instagram (With Periodic Scroll Fix)

Hides posts you've liked on instagram.com, scrolling automatically every 2 seconds to ensure the page loads correctly without black screens.

目前为 2025-03-31 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Hide Liked Posts on Instagram (With Periodic Scroll Fix)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.9
  5. // @description Hides posts you've liked on instagram.com, scrolling automatically every 2 seconds to ensure the page loads correctly without black screens.
  6. // @author luascfl
  7. // @match https://www.instagram.com/*
  8. // @home https://github.com/luascfl/hide-liked-posts-instagram
  9. // @supportURL https://github.com/luascfl/hide-liked-posts-instagram/issues
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Function to hide liked posts
  18. function hideLikedPosts() {
  19. const posts = document.querySelectorAll('article'); // Select posts
  20. posts.forEach(post => {
  21. // Check if the post has a "liked" icon with aria-label="Descurtir"
  22. const likeIcon = post.querySelector('svg[aria-label="Descurtir"]');
  23. if (likeIcon && post.style.display !== 'none') {
  24. post.style.display = 'none'; // Hide the liked post
  25. }
  26. });
  27. }
  28.  
  29. // Function to perform a page-down-like scroll and return to the original position
  30. function performScrollFix() {
  31. const scrollStep = window.innerHeight * 2; // Double the height of the viewport for 2-page scroll
  32. const currentScroll = window.scrollY; // Current scroll position
  33.  
  34. // Scroll down two "pages" and return
  35. window.scrollTo(0, currentScroll + scrollStep);
  36. setTimeout(() => {
  37. window.scrollTo(0, currentScroll);
  38. }, 30); // Reduced time to 30ms for faster, imperceptible return
  39. }
  40.  
  41. // Function to observe content dynamically
  42. function observeContent() {
  43. const feed = document.querySelector('main'); // Main container for posts
  44. if (feed) {
  45. // Observe changes in the main content area
  46. const observer = new MutationObserver(() => {
  47. hideLikedPosts();
  48. });
  49.  
  50. observer.observe(feed, { childList: true, subtree: true });
  51. // Initial run
  52. hideLikedPosts();
  53. }
  54. }
  55.  
  56. // Run the observer on page load
  57. observeContent();
  58.  
  59. // Periodic scroll every 2 seconds
  60. setInterval(() => {
  61. performScrollFix();
  62. }, 2000); // 2-second interval
  63. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址