Instagram Mobile Home Feed Suggested Video Prevention

Simple script to prevent scrolling beyond "You've completely caught up" element

当前为 2024-10-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Instagram Mobile Home Feed Suggested Video Prevention
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Simple script to prevent scrolling beyond "You've completely caught up" element
  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 to hide elements based on a selector
  17. function hideElement(selector) {
  18. const elements = document.querySelectorAll(selector);
  19. elements.forEach(element => {
  20. element.style.display = 'none';
  21. });
  22. }
  23.  
  24. // Function to hide specific elements
  25. function hideSpecificElements() {
  26. hideElement(".xh8yej3.x1iyjqo2 > div:nth-of-type(3)");
  27. hideElement("div:nth-of-type(4) > .x1qrby5j.x7ja8zs.x1t2pt76.x1lytzrv.xedcshv.xarpa2k.x3igimt.x12ejxvf.xaigb6o.x1beo9mf.xv2umb2.x1jfb8zj.x1h9r5lt.x1h91t0o.x4k7w5x > .x1n2onr6 > ._a6hd.x1a2a7pz.xggy1nq.x1hl2dhg.x16tdsg8.xkhd6sd.x18d9i69.x4uap5.xexx8yu.x1mh8g0r.xat24cr.x11i5rnm.xdj266r.xe8uvvx.xt0psk2.x1ypdohk.x9f619.xm0m39n.x1qhh985.xcfux6l.x972fbf.x17r0tee.x1sy0etr.xd10rxx.x1ejq31n.xjbqb8w.x1i10hfl > .x9jhf4c.x30kzoy.xgqcy7u.x1lq5wgf.x1wj20lx.x12ldp4w.x11hdxyr.xs3sg5q.x9k3k5o.x1dejxi8.xdoji71.xzauu7c.x1lhsz42.x10djquj.x172qv1o.xif99yt.x1dn74xm.x159b3zp.x80pfx3.x1ye3gou.xsag5q8.xn6708d.xz9dl7a.x12dmmrz.x7nr27j.x6pnmvc.xo237n4.xjpr12u.xr9ek0c.x3nfvp2.x9f619");
  28. }
  29.  
  30. // Function to find "You've completely caught up" element
  31. function findSuggested() {
  32. const suggestedChild = document.querySelector('.xh8yej3.x1ye3gou.x1gan7if.xn6708d.x1miatn0.xdt5ytf.x78zum5.x9f619.xjbqb8w.x6s0dn4');
  33.  
  34. if (suggestedChild) {
  35. const suggested = suggestedChild.parentElement;
  36. stopAtElement(suggested);
  37. } else {
  38. enableScroll();
  39. }
  40. }
  41.  
  42. function disableScroll(suggested) {
  43. // Set the margin before disabling scroll
  44. suggested.style.marginBottom = '900px';
  45.  
  46. window.onscroll = function () {
  47. const elementRect = suggested.getBoundingClientRect();
  48. if (elementRect.bottom < window.innerHeight) {
  49. const bodyRect = document.body.getBoundingClientRect();
  50. window.scrollTo(0, elementRect.bottom - bodyRect.bottom);
  51. }
  52. };
  53. }
  54.  
  55. function enableScroll() {
  56. window.onscroll = function () { };
  57. }
  58.  
  59. function stopAtElement(element) {
  60. // Disable scrolling when the element is reached
  61. disableScroll(element);
  62. }
  63.  
  64. // Use MutationObserver to monitor DOM changes
  65. const observer = new MutationObserver(() => {
  66. findSuggested();
  67. hideSpecificElements(); // Call to hide elements on DOM changes
  68. });
  69. observer.observe(document.body, { childList: true, subtree: true });
  70.  
  71. // Initial calls
  72. findSuggested();
  73. hideSpecificElements(); // Ensure elements are hidden on script load
  74. })();