Reddit Mobile App Nag Remover

Stops Reddit from pushing you to use the mobile app.

  1. // ==UserScript==
  2. // @name Reddit Mobile App Nag Remover
  3. // @description Stops Reddit from pushing you to use the mobile app.
  4. // @namespace Violentmonkey Scripts
  5. // @match https://*reddit.com/*
  6. // @grant none
  7. // @version 1.2.2
  8. // @author Jupiter Liar
  9. // @description 2023-05-25 6:52 PM
  10. // @license Attribution CC BY
  11. // ==/UserScript==
  12.  
  13. // Function to remove the nag popup element or XPromoPopupRpl element
  14. function removeNagPopup() {
  15. const nagPopup = document.querySelector('shreddit-experience-tree, .XPromoPopupRpl, .XPromoBlockingModalRpl, [class*="XPromo"]');
  16.  
  17. if (nagPopup) {
  18. nagPopup.style.display = 'none';
  19. document.body.style.overflow = 'unset';
  20. document.body.style.position = 'unset';
  21. }
  22. }
  23.  
  24. // Function to remove the nag bottom element or XPromoBottomBar element
  25. function removeNagBottom() {
  26. const navFrame = document.querySelector('.NavFrame');
  27. if (navFrame) {
  28. const nagBottoms = navFrame.querySelectorAll('[bundlename="bottom_bar_xpromo"], .XPromoBottomBar');
  29.  
  30. nagBottoms.forEach(nagBottom => {
  31. nagBottom.style.display = 'none';
  32. });
  33.  
  34. document.body.style.overflow = 'unset';
  35. document.body.style.position = 'unset';
  36. }
  37. }
  38.  
  39. // Remove nag elements when the page has loaded
  40. window.addEventListener('load', function() {
  41. removeNagPopup();
  42. removeNagBottom();
  43. });
  44.  
  45. // Create a MutationObserver instance for nagPopup
  46. const popupObserver = new MutationObserver(function(mutationsList) {
  47. for (let mutation of mutationsList) {
  48. if (mutation.type === 'childList') {
  49. removeNagPopup();
  50. break;
  51. }
  52. }
  53. });
  54.  
  55. // Start observing the body for changes related to nagPopup
  56. popupObserver.observe(document.body, { childList: true, subtree: true });
  57.  
  58. // Create a MutationObserver instance for nagBottom
  59. const bottomObserver = new MutationObserver(function(mutationsList) {
  60. for (let mutation of mutationsList) {
  61. if (mutation.type === 'childList') {
  62. removeNagBottom();
  63. break;
  64. }
  65. }
  66. });
  67.  
  68. // Start observing the body for changes related to nagBottom
  69. bottomObserver.observe(document.body, { childList: true, subtree: true });
  70.  
  71. // Create a MutationObserver instance to monitor body's overflow property
  72. const overflowObserver = new MutationObserver(function(mutationsList) {
  73. for (let mutation of mutationsList) {
  74. if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
  75. const bodyOverflow = document.body.style.overflow;
  76. if (bodyOverflow === 'hidden') {
  77. document.body.style.overflow = 'unset';
  78. document.body.style.position = 'unset';
  79. }
  80. break;
  81. }
  82. }
  83. });
  84.  
  85. // Start observing the body for changes related to overflow property
  86. overflowObserver.observe(document.body, { attributes: true });
  87.  
  88. // Detect and hide the element with bundlename="bottom_bar_xpromo"
  89. const bottomBarXpromo = document.querySelector('[bundlename="bottom_bar_xpromo"]');
  90.  
  91. if (bottomBarXpromo) {
  92. bottomBarXpromo.style.display = 'none';
  93. }