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.8
  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. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to hide liked posts
  16. function hideLikedPosts() {
  17. const posts = document.querySelectorAll('article'); // Select posts
  18. posts.forEach(post => {
  19. // Check if the post has a "liked" icon with aria-label="Descurtir"
  20. const likeIcon = post.querySelector('svg[aria-label="Descurtir"]');
  21. if (likeIcon && post.style.display !== 'none') {
  22. post.style.display = 'none'; // Hide the liked post
  23. }
  24. });
  25. }
  26.  
  27. // Function to perform a page-down-like scroll and return to the original position
  28. function performScrollFix() {
  29. const scrollStep = window.innerHeight * 2; // Double the height of the viewport for 2-page scroll
  30. const currentScroll = window.scrollY; // Current scroll position
  31.  
  32. // Scroll down two "pages" and return
  33. window.scrollTo(0, currentScroll + scrollStep);
  34. setTimeout(() => {
  35. window.scrollTo(0, currentScroll);
  36. }, 30); // Reduced time to 30ms for faster, imperceptible return
  37. }
  38.  
  39. // Function to observe content dynamically
  40. function observeContent() {
  41. const feed = document.querySelector('main'); // Main container for posts
  42. if (feed) {
  43. // Observe changes in the main content area
  44. const observer = new MutationObserver(() => {
  45. hideLikedPosts();
  46. });
  47.  
  48. observer.observe(feed, { childList: true, subtree: true });
  49. // Initial run
  50. hideLikedPosts();
  51. }
  52. }
  53.  
  54. // Run the observer on page load
  55. observeContent();
  56.  
  57. // Periodic scroll every 2 seconds
  58. setInterval(() => {
  59. performScrollFix();
  60. }, 2000); // 2-second interval
  61. })();

QingJ © 2025

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