QOL on the Mobile Web

Just some general quality of (my) life changes. Reddit: Hide auto-mod comments. YouTube: disable end cards.

  1. // ==UserScript==
  2. // @name QOL on the Mobile Web
  3. // @namespace Pogmog
  4. // @description Just some general quality of (my) life changes. Reddit: Hide auto-mod comments. YouTube: disable end cards.
  5. // @version 2.0.2
  6. // @include https://old.reddit.com/*
  7. // @include https://www.reddit.com/*
  8. // @include https://www.youtube.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. // Options
  13. var reddit_hide_automod_post = true;
  14. var reddit_fit_image = true;
  15. var reddit_remove_updatesbox = true;
  16. var reddit_pad_bottom = true;
  17. var youtube_disable_endcards = true;
  18. var reddit_subPost_blocker = ["Genshin_Impact"];
  19.  
  20. var urlCheck = document.URL;
  21. /*
  22. If a tweak needs to use the scroll or onLoad events, call them with the following:
  23. setup_onLoad()
  24. setup_onScroll()
  25. ...rather than have everything fire the onScroll event, etc.
  26. */
  27. if (urlCheck.includes("reddit.com/") && reddit_hide_automod_post)
  28. {
  29. setup_onLoad();
  30. }
  31.  
  32. function afterLoad()
  33. {
  34. console.log("US: after load");
  35. // If anything needs to happen after page load (did for Reddit stuff before I found a better way).
  36. if (urlCheck.includes("reddit.com/"))
  37. {
  38. if (urlCheck.includes("reddit.com/r/all/")) {
  39. var ticker = 0;
  40. while (true) {
  41. var main_content_elm = document.getElementsByClassName("PostsFromSubredditPage");
  42. if (main_content_elm.length > 0 || ticker > 3000) {
  43. console.log("should be load");
  44. break;
  45. }
  46. else {
  47. console.log("waiting for load");
  48. }
  49. ticker += 1;
  50. }
  51. if (reddit_subPost_blocker.length > 0) {
  52. var all_posts = document.getElementsByClassName("PostHeader__subreddit-link");
  53. //var kill_list = [];
  54. for (var i=0;i<all_posts.length;i++) {
  55. for (var j=0;j<all_posts.length;j++) {
  56. if(all_posts[i].href == "/r/" + reddit_subPost_blocker[j]) {
  57. //kill_list.push(all_posts[i]);
  58. var kill_node = all_posts[i].parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
  59. kill_node.parentNode.removeChild(kill_node);
  60. }
  61. }
  62. }
  63. }
  64. if (reddit_pad_bottom) {
  65. var sheet = document.createElement('style')
  66. sheet.innerHTML = ".PaginationButtons {margin-bottom: 400px;}";
  67. document.body.appendChild(sheet);
  68. }
  69. }
  70. else if (urlCheck.includes("reddit.com/r/")) {
  71. if (reddit_hide_automod_post)
  72. {
  73. var first_comment = document.getElementsByClassName("comment")[0];
  74. var element_to_use = first_comment.getElementsByClassName("tagline")[0];
  75. var author = element_to_use.getElementsByClassName("author")[0];
  76. if (author.innerHTML == "AutoModerator")
  77. {
  78. console.log("First comment is Automod.");
  79. element_to_use.getElementsByClassName("expand")[0].onclick();
  80. }
  81. }
  82. }
  83. }
  84. }
  85. function onPageScroll()
  86. {
  87. // If anything needs to happen on page scroll (did for Reddit stuff before I found a better way).
  88. }
  89.  
  90. if (urlCheck.includes("reddit.com/"))
  91. {
  92. var addition_sheet = document.createElement('style');
  93. addition_sheet.innerHTML = ".TopNav__promoButton{display: none !important;}";
  94. if (reddit_fit_image)
  95. {
  96. addition_sheet.innerHTML = addition_sheet.innerHTML + ".Post.size-compact.m-redesign div:nth-of-type(3) img {object-fit: contain !important;}";
  97. }
  98. if (reddit_remove_updatesbox)
  99. {
  100. addition_sheet.innerHTML = addition_sheet.innerHTML + "._3VqiDbufgl9_EiV_tk9L6u {display: none !important;}";
  101. }
  102. document.body.appendChild(addition_sheet);
  103. }
  104. else if (urlCheck.includes("youtube.com/watch"))
  105. {
  106. if (youtube_disable_endcards)
  107. {
  108. // Get rid of YouTube's annoying ENDCARDS
  109. var sheet = document.createElement('style')
  110. sheet.innerHTML = ".ytp-ce-element {display: none;}";
  111. document.body.appendChild(sheet);
  112. }
  113. }
  114. // Setup Function
  115. function setup_onLoad()
  116. {
  117. // For code that needs to happen post-pageload
  118. if (window.attachEvent) {window.attachEvent('onload', afterLoad);}
  119. else if (window.addEventListener) {window.addEventListener('load', afterLoad, false);}
  120. else {document.addEventListener('load', afterLoad, false);}
  121. }
  122. function setup_onScroll()
  123. {
  124. // For code that needs to happen on scroll event
  125. window.addEventListener("scroll", onPageScroll);
  126. }
  127.