Stop Scrolling Instagram

Simple script to prevent scrolling beyond "You've completely caught up" element and hide suggested posts reliably.

  1. // ==UserScript==
  2. // @name Stop Scrolling Instagram
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Simple script to prevent scrolling beyond "You've completely caught up" element and hide suggested posts reliably.
  6. // @author Ulysses
  7. // @match https://www.instagram.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=instagram.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. function hideElement(selector) {
  17. const elements = document.querySelectorAll(selector);
  18. elements.forEach(el => el.style.display = 'none');
  19. }
  20.  
  21. function hideSpecificElements() {
  22. // Mobile selectors
  23. hideElement("div:nth-of-type(3) > .x1qrby5j.x7ja8zs ..."); // Keep your original selectors
  24. hideElement("div.x1nhvcw1.x1oa3qoh.x1qjc9v5...");
  25. hideElement(".xl56j7k.x1oa3qoh.x6s0dn4...");
  26. // Desktop selectors
  27. hideElement("div:nth-of-type(4) > .x1qrby5j.x7ja8zs ...");
  28. hideElement("div:nth-of-type(4) > .x1qrby5j.x7ja8zs ... > .x1n2onr6");
  29. }
  30.  
  31. // --- Updated method: Find "You've completely caught up" by text ---
  32. function findCaughtUpElement() {
  33. const textMatch = "You've completely caught up";
  34. const spans = document.querySelectorAll('span');
  35. for (const span of spans) {
  36. if (span.textContent.trim().includes(textMatch)) {
  37. return span.closest('div.xvbhtw8') || span.parentElement;
  38. }
  39. }
  40. return null;
  41. }
  42.  
  43. function disableScroll(target) {
  44. target.style.marginBottom = '900px';
  45.  
  46. window.onscroll = function () {
  47. const rect = target.getBoundingClientRect();
  48. if (rect.bottom < window.innerHeight) {
  49. const scrollTop = window.scrollY;
  50. const limit = rect.bottom + scrollTop - window.innerHeight;
  51. window.scrollTo(0, limit);
  52. }
  53. };
  54. }
  55.  
  56. function enableScroll() {
  57. window.onscroll = function () {};
  58. }
  59.  
  60. function stopAtCaughtUp() {
  61. const element = findCaughtUpElement();
  62. if (element) {
  63. disableScroll(element);
  64. } else {
  65. enableScroll();
  66. }
  67. }
  68.  
  69. // Observe DOM changes for dynamic loading
  70. const observer = new MutationObserver(() => {
  71. stopAtCaughtUp();
  72. hideSpecificElements();
  73. });
  74.  
  75. observer.observe(document.body, { childList: true, subtree: true });
  76.  
  77. // Initial run
  78. stopAtCaughtUp();
  79. hideSpecificElements();
  80. })();