YouTube Anti-Shorts

Remove all shorts

  1. // ==UserScript==
  2. // @name YouTube Anti-Shorts
  3. // @version 1.0.5
  4. // @author sapondanaisriwan
  5. // @namespace https://github.com/sapondanaisriwan/youtube-anti-shorts
  6. // @description Remove all shorts
  7. // @match https://www.youtube.com/*
  8. // @grant none
  9. // @license MIT
  10. // @homepageURL https://github.com/sapondanaisriwan/youtube-anti-shorts
  11. // @supportURL https://github.com/sapondanaisriwan/youtube-anti-shorts/issues
  12. // @icon https://i.imgur.com/I9uDrsq.png
  13. // ==/UserScript==
  14.  
  15. /*
  16. If you want to submit a bug or request a feature please report via github issue. Since I receive so many emails, I can't reply to them all.
  17. Contact: sapondanaisriwan@gmail.com
  18. Support me: https://ko-fi.com/sapondanaisriwan
  19. Support me: https://ko-fi.com/sapondanaisriwan
  20. Support me: https://ko-fi.com/sapondanaisriwan
  21. Support me: https://ko-fi.com/sapondanaisriwan
  22. Support me: https://ko-fi.com/sapondanaisriwan
  23. */
  24.  
  25. "use strict";
  26.  
  27. // Customize the way you like :)
  28. const settings = {
  29. Hide_Tab: true, // Hide Tabs that named "SHORT"
  30. Home_Page: true,
  31. Channel_Page: true,
  32. Watch_Page: true,
  33. Search_Page: true,
  34. Hashtag_Page: true,
  35. Subscription_Page: {
  36. Videos_Per_Row: 6,
  37. Hide_Shorts: true,
  38. Hide_Channel_Profile: true,
  39. },
  40. };
  41.  
  42. const config = { childList: true, subtree: true, attributes: true };
  43. const selectors = {
  44. tabs: {
  45. parent: "tp-yt-paper-tab",
  46. element: "tp-yt-paper-tab .tab-title",
  47. },
  48. navbar: {
  49. collapse: 'a.ytd-mini-guide-entry-renderer[title="Shorts"]',
  50. expanded: `
  51. #endpoint.yt-simple-endpoint.ytd-guide-entry-renderer[title="Shorts"],
  52. a.ytd-mini-guide-entry-renderer[title="Shorts"]
  53. `,
  54. },
  55. filterBar: {
  56. parent: "yt-chip-cloud-chip-renderer",
  57. element: "yt-chip-cloud-chip-renderer #text[title='Shorts']",
  58. },
  59. searchPage: {
  60. reel: "ytd-search ytd-reel-shelf-renderer",
  61. videos: {
  62. parent: "ytd-video-renderer[is-search]",
  63. element: "ytd-search #thumbnail[href^='/shorts/']",
  64. },
  65. },
  66. homePage: {
  67. reel: {
  68. parent: "ytd-rich-section-renderer",
  69. element: "[page-subtype='home'] ytd-rich-shelf-renderer[is-shorts]",
  70. },
  71. },
  72. subscriptionPage: {
  73. reel: {
  74. parent: "ytd-rich-section-renderer",
  75. element:
  76. "[page-subtype='subscriptions'] ytd-rich-shelf-renderer[is-shorts], ytd-reel-shelf-renderer",
  77. },
  78. reelList: {
  79. parent: "ytd-item-section-renderer[page-subtype='subscriptions']",
  80. element: "ytd-reel-shelf-renderer",
  81. },
  82. videos: {
  83. parent:
  84. "ytd-grid-video-renderer, ytd-rich-item-renderer, ytd-item-section-renderer",
  85. element: "[page-subtype='subscriptions'] #thumbnail[href^='/shorts/']",
  86. },
  87. },
  88. channelPage: {
  89. reel: {
  90. parent: "ytd-item-section-renderer",
  91. element: '[page-subtype="channels"] ytd-reel-shelf-renderer',
  92. },
  93. feed: {
  94. element:
  95. "[page-subtype='channels'] ytd-rich-grid-renderer[is-shorts-grid]",
  96. },
  97. },
  98. watchPage: {
  99. reel: "ytd-watch-flexy ytd-reel-shelf-renderer",
  100. },
  101. hashtagPage: {
  102. video: {
  103. parent: "ytd-rich-item-renderer",
  104. element:
  105. "[page-subtype='hashtag-landing-page'] #thumbnail[href^='/shorts/']",
  106. },
  107. },
  108. };
  109.  
  110. // Stolen from AdashimaaTube
  111. const styles = {
  112. subscriptionPage: {
  113. layoutFix: `
  114. [page-subtype="subscriptions"] ytd-rich-grid-renderer #contents ytd-rich-grid-row,
  115. [page-subtype="subscriptions"] ytd-rich-grid-renderer #contents ytd-rich-grid-row #contents {
  116. display: contents;
  117. }
  118.  
  119. [page-subtype="subscriptions"] ytd-rich-item-renderer:not([is-reel-item-style-avatar-circle]) {
  120. width: calc(100%/${settings.Subscription_Page.Videos_Per_Row} - 4px - 0.01px)
  121. }
  122.  
  123. [page-subtype="subscriptions"] ytd-rich-grid-renderer #contents #contents > ytd-rich-item-renderer:not([is-reel-item-style-avatar-circle]) {
  124. margin-left: 0;
  125. margin-right: calc(var(--ytd-rich-grid-item-margin) / 4);
  126. margin-bottom: 24px;
  127. }
  128.  
  129. [page-subtype="subscriptions"] #contents.ytd-rich-grid-renderer {
  130. padding-top: 0;
  131. }
  132. [page-subtype="subscriptions"] #content.ytd-rich-section-renderer {
  133. margin: 0;
  134. max-width: 100%;
  135. }
  136.  
  137. [page-subtype="subscriptions"][mini-guide-visible] ytd-two-column-browse-results-renderer.grid.grid-disabled {
  138. max-width: var(--ytd-grid-max-width);
  139. }
  140. @media screen and (max-width: 1170px) {
  141. [page-subtype="subscriptions"][mini-guide-visible] ytd-two-column-browse-results-renderer.grid.grid-disabled {
  142. width: var(--ytd-grid-4-columns-width);
  143. }
  144. }
  145. @media screen and (min-width: 1171px) {
  146. [page-subtype="subscriptions"][mini-guide-visible] ytd-two-column-browse-results-renderer.grid.grid-disabled,
  147. [page-subtype="subscriptions"]:not([mini-guide-visible]) ytd-two-column-browse-results-renderer.grid.grid-disabled {
  148. width: var(--ytd-grid-5-columns-width);
  149. }
  150. }
  151. @media screen and (min-width: 1440px) {
  152. [page-subtype="subscriptions"][mini-guide-visible] ytd-two-column-browse-results-renderer.grid.grid-disabled {
  153. width: var(--ytd-grid-6-columns-width);
  154. }
  155. }
  156. @media screen and (min-width: 1553px) {
  157. [page-subtype="subscriptions"]:not([mini-guide-visible]) ytd-two-column-browse-results-renderer.grid.grid-disabled {
  158. width: var(--ytd-grid-6-columns-width);
  159. }
  160. }
  161. `,
  162. hideChannelProfile: `
  163. [page-subtype="subscriptions"] #avatar-link.ytd-rich-grid-media {
  164. display: none;
  165. }
  166. `,
  167. },
  168. };
  169.  
  170. function checkDisplay(ele) {
  171. return ele.style.display === "none";
  172. }
  173.  
  174. function setHide(ele) {
  175. ele.style.display = "none";
  176. }
  177.  
  178. function hideEle(ele) {
  179. const isEleHide = checkDisplay(ele);
  180. !isEleHide && setHide(ele);
  181. }
  182.  
  183. function hideParentEle(ele, parent) {
  184. const parentEle = ele.closest(parent);
  185. if (parentEle) {
  186. const isParentHide = checkDisplay(parentEle);
  187. !isParentHide && setHide(parentEle);
  188. }
  189. }
  190.  
  191. function hideShorts(selector, parent = "") {
  192. [...document.querySelectorAll(selector)].forEach((ele) =>
  193. parent ? hideParentEle(ele, parent) : hideEle(ele)
  194. );
  195. }
  196.  
  197. function hideShortsText(selector, parent = "") {
  198. [...document.querySelectorAll(selector)].forEach(
  199. (ele) =>
  200. ele.textContent.toLowerCase() === "shorts" && hideParentEle(ele, parent)
  201. );
  202. }
  203.  
  204. // Function to remove DOM element
  205. const removeEle = (id) => {
  206. const ele = document.getElementById(id);
  207. ele && ele.remove();
  208. };
  209.  
  210. // Function to inject a style into the webpage
  211. const injectStyle = (id, css) => {
  212. // Remove before adding
  213. removeEle(id);
  214.  
  215. const style = document.createElement("style");
  216. style.type = "text/css";
  217. style.id = id;
  218. style.textContent = css;
  219. document.documentElement.appendChild(style);
  220. };
  221.  
  222. function run() {
  223. // Home Page
  224. if (settings.Home_Page) {
  225. hideShorts(selectors.homePage.reel.element, selectors.homePage.reel.parent);
  226. }
  227.  
  228. // Channel Page
  229. if (settings.Channel_Page) {
  230. hideShorts(selectors.channelPage.feed.element);
  231. hideShorts(
  232. selectors.channelPage.reel.element,
  233. selectors.channelPage.reel.parent
  234. );
  235. }
  236.  
  237. // Watch Page
  238. if (settings.Watch_Page) {
  239. hideShorts(selectors.watchPage.reel);
  240. }
  241.  
  242. // Search Page
  243. if (settings.Search_Page) {
  244. hideShorts(selectors.searchPage.reel);
  245. hideShorts(
  246. selectors.searchPage.videos.element,
  247. selectors.searchPage.videos.parent
  248. );
  249. }
  250.  
  251. // Subscription Page
  252. if (settings.Subscription_Page.Hide_Shorts) {
  253. hideShorts(
  254. selectors.subscriptionPage.videos.element,
  255. selectors.subscriptionPage.videos.parent
  256. );
  257. hideShorts(
  258. selectors.subscriptionPage.reel.element,
  259. selectors.subscriptionPage.reel.parent
  260. );
  261. hideShorts(
  262. selectors.subscriptionPage.reelList.element,
  263. selectors.subscriptionPage.reelList.parent
  264. );
  265. }
  266.  
  267. // Hashtag Page
  268. if (settings.Hashtag_Page) {
  269. hideShorts(
  270. selectors.hashtagPage.video.element,
  271. selectors.hashtagPage.video.parent
  272. );
  273. }
  274.  
  275. if (settings.Hide_Tab) {
  276. // Tabs
  277. hideShortsText(selectors.tabs.element, selectors.tabs.parent);
  278. hideShorts(selectors.navbar.expanded);
  279. hideShorts(selectors.navbar.collapse);
  280.  
  281. // Hashtag Page
  282. hideShorts(selectors.filterBar.element, selectors.filterBar.parent);
  283. }
  284. }
  285.  
  286. settings.Subscription_Page.Hide_Shorts &&
  287. injectStyle("Stolen-from-AdashimaaTube", styles.subscriptionPage.layoutFix);
  288. settings.Subscription_Page.Hide_Channel_Profile &&
  289. injectStyle(
  290. "hide-channel-profile",
  291. styles.subscriptionPage.hideChannelProfile
  292. );
  293. const observer = new MutationObserver(run);
  294. observer.observe(document.documentElement, config);

QingJ © 2025

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