Reddit CSS

New Design with new functionalities

当前为 2023-12-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Reddit CSS
  3. // @namespace https://www.reddit.com
  4. // @version 6.3
  5. // @description New Design with new functionalities
  6. // @author Agreasyforkuser
  7. // @match https://old.reddit.com/*
  8. // @match https://www.reddit.com/*
  9. // @match https://rapidsave.com/*
  10. // @exclude https://new.reddit.com/*
  11. // @icon https://www.redditstatic.com/desktop2x/img/favicon/android-icon-192x192.png
  12. // @license MIT
  13. // @grant GM_addStyle
  14. // ==/UserScript==
  15.  
  16.  
  17. /////////////////// sort by new ////////////////////////////////////////////////////////////////////////
  18.  
  19. 'use strict';
  20. const re = /https?:\/\/(?:www\.|old\.|new\.)?reddit\.com/i;
  21. for (var i=0, l=document.links.length; i<l; i++) {
  22. if (re.test(document.links[i].href)) {
  23. var path = document.links[i].pathname;
  24. if (path === '/' || path.startsWith('/r/')) {
  25. var pathlen = path.split('/').length - 1 - (path.endsWith('/') ? 1 : 0);
  26. if ((pathlen <= 2) && (document.links[i].closest('.tabmenu') === null)) {
  27. document.links[i].href += path.endsWith('/') ? 'new/' : '/new/';
  28. }
  29. }
  30. }
  31. }
  32. //////////////////////////////// over 18 button ///////////////////////////////////////////////////////
  33.  
  34. const button = document.querySelector('button.c-btn.c-btn-primary[type="submit"][name="over18"][value="yes"]');
  35. if (button) {button.click();}
  36.  
  37.  
  38. /////////////////////////////// auto-click download link after opening the rapidsave page ///////////////
  39. const dbutton = document.querySelector('.downloadbutton');
  40. if (dbutton) {
  41. dbutton.click();
  42. }
  43.  
  44. ///////////////////////////////////////////////////////////////////////////////////////////////////
  45. (function() {
  46. 'use strict';
  47.  
  48. // Define the CSS to enlarge the thumbnails and modify the styling
  49. var customCSS = `
  50.  
  51. /* search placeholder text */
  52. ::-moz-placeholder {color:transparent !important;}
  53.  
  54. /* View full thumbnails on search page */
  55. .search-result :link {display:inline-table !important}
  56.  
  57. .email-collection-banner, .email-verification-tooltip, #eu-cookie-policy {display:none !important}
  58.  
  59. .infobar.listingsignupbar, .infobar.commentsignupbar {display: none !important;}
  60. .infobar, .timeout-infobar {border:none}
  61. .help-hoverable {display:none}
  62. .reddit-infobar.with-icon {
  63. min-height: 35px !important;
  64. padding: 0 0 0 55px !important;
  65. height: 35px !important;
  66. }
  67. .reddit-infobar.with-icon:not(:hover) {
  68. min-height: 0 !important;
  69. padding: 0 0 0 55px !important;
  70. margin: 0 !important;
  71. height: 9px !important;
  72. opacity:0 !important
  73. }
  74.  
  75. /* Video Controls for Mobile */
  76. video::-webkit-media-controls-panel {background: none; opacity:.7}
  77. video::-webkit-media-controls-overlay-play-button {opacity: 0}
  78.  
  79. /* Flair Labels */
  80. .flairrichtext {border-radius: 0px;border:none}
  81. .linkflairlabel {border-radius: 0px;border:none}
  82. .stamp {background: white;border-radius: 0;padding:0}
  83.  
  84.  
  85.  
  86.  
  87. /* Buttons */
  88. button, .preftable select, input[type="submit"] {border-radius:0}
  89.  
  90. /* Subreddit Name */
  91. body.with-listing-chooser #header .pagename {position:inherit; color: white}
  92. .pagename a {color: black; margin-left:4px; margin-right:4px}
  93. .pagename {background-color:white; font-variant: normal; border-radius:0px; margin: 0;}
  94.  
  95.  
  96. /* Adjust the size of the thumbnails */
  97.  
  98. .thumbnail, .thumbnail img{
  99. width: 200px !important;
  100. height: auto !important;
  101. position: relative;
  102. margin-bottom: 0;
  103. }
  104.  
  105. /* Visibility of text posts */
  106. .expando-button.selftext {float:left}
  107. .expando-button.selftext {height:50px !important;width:200px !important; background-image:none !important;background-color: black !important}
  108.  
  109.  
  110. /* no margin left for expanded media */
  111. .entry {margin-left:0}
  112.  
  113. /* size videos correctly */
  114. .no-constraints-when-pinned {min-width:0 !important; min-height: 0 !important;}
  115.  
  116. /* Videoplayer Background */
  117. .reddit-video-player-root {background: #0000;}
  118.  
  119. /* Video Duration Info */
  120. .duration-overlay {font-size: 10pt; font-weight: bold;}
  121. .duration-overlay {border-top-left-radius: 10px; width:auto !important; padding:5px; right:0}
  122.  
  123.  
  124. /* OP indicator */
  125. .tagline .submitter, .search-result-meta .submitter {color: #228822}
  126.  
  127. /* sort menu*/
  128. .menuarea {border:none}
  129. .dropdown.lightdrop .selected {text-decoration: none}
  130.  
  131. /* Post */
  132. .thing .title {font-weight: normal;color: #000; ;margin-bottom: 15px;}
  133. .subreddit {font-weight: bold;font-size: larger;color: #000;}
  134. .link .flat-list {font-size:larger}
  135. .link.last-clicked {border: 3px dotted red;}
  136.  
  137. /* Text Posts Background*/
  138. .link .usertext-body .md {background: none; border: 1px solid gray; border-radius: 0}
  139.  
  140. /* Post Details */
  141. .entry .buttons li a {color:#000000c7; font-weight:normal}
  142.  
  143. .entry .buttons li {background: #0000000d}
  144. .entry .buttons li:hover {opacity:1 !important} //revert graying-out function on hover
  145.  
  146. .tagline {color: #8880; margin-bottom: 15px;}
  147. .tagline .live-timestamp {color: #369}
  148. .domain {display: none;}
  149. .reportbtn {display:none}
  150. .post-crosspost-button {display:none}
  151. .post-sharing-button {display:none}
  152. .buttons .give-gold.gold-give-gold {display: none}
  153. .hide-button {display:none !important}
  154. .expando-button {opacity: 0.1;float:right}
  155.  
  156.  
  157. /* Header Font Size and Icon */
  158. #header-bottom-left {font-size: large;}
  159. #header-img.default-header:not(:hover) {opacity: 0}
  160.  
  161. /* Upper Bars */
  162. #sr-header-area:not(:hover) {background: none !important; opacity:0.3 }
  163. #sr-header-area {border-bottom: none}
  164. #sr-header-area .redesign-beta-optin {display:none}
  165. #sr-more-link {background-color: #cee3f8 }
  166.  
  167. /* Hide Username */
  168. .user a:not(:hover) {opacity: 0;}
  169.  
  170.  
  171.  
  172. .pref-lang {font-weight: normal}
  173. #header-bottom-right:not(:hover) {background: none; border-radius:0}
  174. #header-bottom-right {background: white; border-radius:0}
  175. #header-bottom-right {font-size: larger;}
  176. #header {border:none}
  177.  
  178.  
  179. .separator {color: transparent;}
  180. #header-bottom-left {margin-top: -10px;}
  181. a[href="https://old.reddit.com/wiki/"].choice {display: none;}
  182. .tabmenu li a {background:none;opacity:0.6;font-weight: normal}
  183. .tabmenu li a:hover {background:white}
  184. .tabmenu li.selected a {opacity:1;font-weight: bold;font-size: x-large; background-color: white; border: none}
  185. .tabmenu li.selected a {text-transform: uppercase}
  186.  
  187.  
  188.  
  189.  
  190. /* Sidebar */
  191. .sidecontentbox .content {border: none; background: none}
  192. .sidebox .spacer {display: none}
  193. .premium-banner {display: none}
  194. .giftgold {display: none}
  195. .titlebox .bottom {border:none}
  196. #searchexpando, .linkinfo, .linkinfo .shortlink input {border: none}
  197. .morelink .nub {display: none}
  198. .morelink {border: none; background: #eff7ff;background-image:none}
  199. .toggle .option {border: none; border-radius:0}
  200. .c-btn-primary {border: none; border-radius: 0;}
  201. .subscription-box:not(:hover) {opacity: 0}
  202.  
  203.  
  204. /* Space between Posts */
  205. .link {margin-bottom: 0px;}
  206.  
  207. /* Expanded Post Margins */
  208. .expando {margin: 0}
  209.  
  210. /* Gallery Buttons */
  211. .media-gallery .gallery-nav-bar {font-size:large; display:grid}
  212. .media-gallery .gallery-nav-next {border:1px solid #336699;background:#eff7ff; float:right !important}
  213. .media-gallery .gallery-nav-prev {border:1px solid #336699;background:#eff7ff}
  214. .media-gallery .gallery-nav-back {border:1px solid #336699;background:#eff7ff}
  215. /*.gallery-navigation {padding: 0px}*/
  216. .gallery-navigation {border: none}
  217. .gallery-nav-disabled {opacity:0 !important}
  218.  
  219. /* Rank / Scores */
  220. .link .rank {display: none}
  221. .arrow.up {display: none}
  222. .arrow.down {display: none}
  223.  
  224. /* Comment Page */
  225. .panestack-title { padding-bottom: 0px; border-bottom: none;}
  226. .commentarea .menuarea {font-size: large;}
  227. .comment .author {font-size: larger;float:left}
  228. .comment .expand {font-size: large;float:left; opacity:1;margin: 0 !important;padding: 0 !important; opacity:0}
  229. .comment .expand {width:6px}
  230. .comment.collapsed .expand { opacity:1;width:auto}
  231. .comment .midcol {z-index:9999}
  232.  
  233. .commentarea > .usertext:not(:hover) {opacity:0.2; height: 18px}
  234.  
  235. .commentarea .entry .buttons:not(:hover) {opacity:0;}
  236. .comments-page #siteTable .thing {display: flex !important;border: none;}
  237. .comment .tagline {color: #00000069 ; margin-bottom: 15px; text-align:left}
  238. .comment .child {border-left: dotted 3px #000000}
  239. .comment .score {font-size: larger}
  240. .comments-page .arrow.up {display:block}
  241. .comments-page .arrow.down {display:block}
  242. .pinnable-content.pinned {background-color: #FFFFFFF7 !important;box-shadow: none !important}
  243. .reddiquette {display: none}
  244.  
  245. /* Bottom Page */
  246. .footer {display:none}
  247. .footer-parent {opacity:0}
  248. .debuginfo {display:none}
  249. .bottommenu {opacity:0}
  250.  
  251. /* promoted posts/ads */
  252. .link.promotedlink.promoted, .link.promotedlink.external {display:none !important}
  253.  
  254. /* submissions */
  255. .formtabs-content .infobar {border:none}
  256. .content.submit .info-notice {display: none;}
  257. #items-required {display: none;}
  258.  
  259.  
  260.  
  261. /* Navbar */
  262. .nav-buttons {
  263. display:table;
  264. bottom: 0 !important;
  265. right: 0 !important;
  266. text-align: center !important;
  267. border: 3px solid;
  268. border-color: #cee3f8;
  269. border-top-left-radius: 15px;
  270. background-color: #cee3f8;
  271. font-size: larger;
  272. z-index: 9998 !important;
  273. }
  274. .nextprev a {background:none !important}
  275.  
  276. /* Crossposts */
  277. .crosspost-preview {border-radius: 0 !important}
  278.  
  279. `;
  280.  
  281. // Add the custom CSS to the page
  282. GM_addStyle(customCSS);
  283.  
  284. ////////////////////// Remove thumbnails from posts without thumbnails////////////////////////
  285.  
  286. function removePostsWithoutImages() {
  287. var posts = document.querySelectorAll('.thumbnail');
  288. for (var i = 0; i < posts.length; i++) {
  289. if (!posts[i].querySelector('img')) {
  290. posts[i].parentNode.removeChild(posts[i]);
  291. }
  292. }
  293. }
  294. setInterval(removePostsWithoutImages, 1000);
  295. })();
  296.  
  297.  
  298. ////////////////////////////////////// comments page //////////////////////////////////
  299.  
  300. var commentpage = /https:\/\/.*\.reddit\.com\/.*\/comments\/.*/;
  301. if (commentpage.test(window.location.href)) {
  302. GM_addStyle(`.reportbtn {display:block}
  303. .post-crosspost-button {display:block}
  304. a.comments {display:none}
  305. /* .buttons .give-gold.gold-give-gold {display:block} */
  306. .expando-button {opacity: 1 }
  307. .hide-button {display:block !important}
  308.  
  309. a.embed-comment {display: none}
  310. /* a.bylink {display: none} */
  311.  
  312.  
  313. .thumbnail,.thumbnail img {width: 100px !important;height: 100px !important;}
  314. #sr-header-area {display:none}
  315.  
  316. /* without this voting comments on mobile is impossible */
  317. .entry {margin-left:4px}
  318.  
  319. `
  320. );
  321.  
  322. ////////////////////////////////// Download Button ////////////////////////////////////
  323.  
  324.  
  325. 'use strict';
  326.  
  327. function downloadVideo() {
  328. var postUrl = window.location.href;
  329. var baseUrl = 'https://rapidsave.com/info?url=';
  330. var downloadUrl = baseUrl + encodeURIComponent(postUrl);
  331. window.open(downloadUrl, '_blank');
  332. }
  333.  
  334. function createDownloadButton() {
  335. var listItem = document.createElement('li');
  336. listItem.classList.add('reddit-video-download-button');
  337.  
  338. var button = document.createElement('button');
  339. button.innerHTML = 'Download';
  340. button.style.color = '#000000c7'; //same as .entry .buttons li a
  341. button.style.background = 'none';
  342. button.style.border = 'none';
  343. button.style.fontSize = 'inherit';
  344. // button.style.borderRadius = '10px';
  345. // button.style.fontWeight = 'bold';
  346. button.onclick = downloadVideo;
  347.  
  348. listItem.appendChild(button);
  349.  
  350. var buttonsList = document.querySelector('ul.buttons');
  351. if (buttonsList) {
  352. buttonsList.appendChild(listItem);
  353. }
  354. }
  355.  
  356. createDownloadButton();
  357.  
  358.  
  359. /////////////////////add profile pictures next to comments ///////////////////////
  360.  
  361. const addAvatars = async (root = document) => {
  362. Array.from(root.querySelectorAll('.thing:not(.morechildren)')).forEach(async (thing) => {
  363. if (!thing) return;
  364. if (thing.hasAttribute('data-reddit-profile-picture')) return;
  365. const img = document.createElement('img');
  366. img.classList.add('reddit-profile-picture');
  367. img.style.height = '22px';
  368. img.style.width = '22px';
  369. img.style.float = 'left';
  370. img.style.margin = '0px';
  371. thing.insertBefore(img, thing.querySelector('.entry'));
  372. thing.setAttribute('data-reddit-profile-picture', 1);
  373. if (!thing.id) return;
  374. const authorElement = thing.querySelector('.author');
  375. if (authorElement && authorElement.href) {
  376. const xhr = new XMLHttpRequest();
  377. xhr.open('GET', `${authorElement.href}/about.json`);
  378. xhr.addEventListener('load', async () => {
  379. if (xhr.status === 200) {
  380. try {
  381. const profile = JSON.parse(xhr.responseText).data;
  382. const ta = document.createElement('textarea');
  383. ta.innerHTML = profile.icon_img;
  384. img.src = ta.value;
  385. } catch (error) {
  386. // Error parsing JSON or extracting URL
  387. console.error('Error parsing JSON or extracting URL:', error);
  388. removeAvatar(img);
  389. }
  390. } else {
  391. // Non-200 status, handle error
  392. console.error('Error fetching user data:', xhr.status, xhr.statusText);
  393. removeAvatar(img);
  394. }
  395. });
  396. xhr.addEventListener('error', () => {
  397. // Network error
  398. console.error('Network error while fetching user data.');
  399. removeAvatar(img);
  400. });
  401. xhr.send();
  402. }
  403. });
  404. };
  405.  
  406. const removeAvatar = (imgElement) => {
  407. if (imgElement && imgElement.parentNode) {
  408. imgElement.parentNode.removeChild(imgElement);
  409. }
  410. };
  411.  
  412. addAvatars();
  413.  
  414. const mo = new MutationObserver((muts) => {
  415. muts.forEach((mut) => {
  416. Array.from(mut.addedNodes).forEach((node) => {
  417. if (node instanceof HTMLElement) {
  418. addAvatars();
  419. }
  420. });
  421. });
  422. });
  423. mo.observe(document.body, { childList: true, subtree: true });
  424. };
  425.  
  426. ////////////////////////////// userpage ///////////////////////////////////////////////////////////////////
  427.  
  428. var userpage = /https:\/\/.*\.reddit\.com\/user\/.*/;
  429. if (userpage.test(window.location.href)) {
  430.  
  431. GM_addStyle(`.comment, .content .details {border-bottom: 2px solid #5f99cf !important}`);
  432.  
  433. const addProfilePictures = async (root = document) => {
  434. Array.from(root.querySelectorAll('.pagename')).forEach(async (pagename) => {
  435. if (!pagename) return;
  436. if (pagename.hasAttribute('data-reddit-profile-picture')) return;
  437.  
  438. const username = pagename.textContent.trim();
  439. if (!username) return;
  440.  
  441. const img = document.createElement('img');
  442. img.classList.add('reddit-profile-picture');
  443. img.style.height = '35px';
  444. img.style.width = '35px';
  445. img.style.verticalAlign = 'middle';
  446.  
  447.  
  448. pagename.parentNode.insertBefore(img, pagename.nextSibling);
  449.  
  450. pagename.setAttribute('data-reddit-profile-picture', 1);
  451.  
  452. const xhr = new XMLHttpRequest();
  453. xhr.open('GET', `https://www.reddit.com/user/${username}/about.json`);
  454. xhr.addEventListener('load', async () => {
  455. const profile = JSON.parse(xhr.responseText).data;
  456. const ta = document.createElement('textarea');
  457. ta.innerHTML = profile.icon_img;
  458. img.src = ta.value;
  459. });
  460. xhr.send();
  461. });
  462. };
  463.  
  464. addProfilePictures();
  465.  
  466. const mo = new MutationObserver((muts) => {
  467. muts.forEach((mut) => {
  468. Array.from(mut.addedNodes).forEach((node) => {
  469. if (node instanceof HTMLElement) {
  470. addProfilePictures(node);
  471. }
  472. });
  473. });
  474. });
  475.  
  476. mo.observe(document.body, { childList: true, subtree: true });
  477. };
  478.  
  479.  
  480. //////////////////////////////////////////// red numbers if score is less than one //////////////////////////////////////
  481.  
  482. if (userpage.test(window.location.href) || commentpage.test(window.location.href)) {
  483. (function() {
  484. 'use strict';
  485.  
  486. // Function to check if the text starts with a "-" or "0"
  487. function startsWithNegativeSymbolOrZero(text) {
  488. return text.trim().startsWith('-') || text.trim().startsWith('0');
  489. }
  490.  
  491. // Get all elements with class "score likes"
  492. var scoreElements = document.querySelectorAll('.score');
  493.  
  494. // Iterate over each score element using forEach
  495. scoreElements.forEach(function(scoreElement) {
  496. var scoreText = scoreElement.textContent.trim();
  497.  
  498. // Check if the score starts with a "-" or "0"
  499. if (startsWithNegativeSymbolOrZero(scoreText)) {
  500. // Change the color to red
  501. scoreElement.style.color = 'red';
  502. scoreElement.style.fontWeight = 'bold';
  503. } else if (parseFloat(scoreText) > 1) {
  504. // Change the color to green
  505. scoreElement.style.color = 'green';
  506. scoreElement.style.fontWeight = 'bold';
  507. }
  508. });
  509. })();
  510. }
  511.  
  512. /////////////////////////grey out comment-buttons if no comments were written /////////////////////////////////
  513.  
  514.  
  515. if (!commentpage.test(window.location.href)) {
  516.  
  517. 'use strict';
  518.  
  519. const removeCommentsCount = element => {
  520. const text = element.textContent.trim();
  521. if (!isNaN(parseInt(text.charAt(0), 10))) return;
  522. element.closest('.entry .buttons li').style.opacity = '0.2';
  523. };
  524.  
  525. const commentElements = document.querySelectorAll('a.comments');
  526. commentElements.forEach(removeCommentsCount);
  527.  
  528. const observer = new MutationObserver(mutationsList => {
  529. for (const mutation of mutationsList) {
  530. if (mutation.type === 'childList') {
  531. const newCommentElements = mutation.addedNodes;
  532. newCommentElements.forEach(node => {
  533. if (node instanceof HTMLElement) {
  534. const element = node.querySelector('a.comments');
  535. if (element) removeCommentsCount(element);
  536. }
  537. });
  538. }
  539. }
  540.  
  541. });
  542.  
  543. observer.observe(document.body, { childList: true, subtree: true });
  544. };
  545.  
  546. /////////////////////////////////////////////////Thumbnail Click Functionality //////////////////
  547.  
  548. // Custom CSS for the clicked thumbnail
  549. const customCSS = `
  550. /* Makes Clicking Easier */
  551. .thumbnail {z-index:99}
  552.  
  553. .thumbnail.clicked {
  554. width: 80px !important;
  555. height: 80px !important;
  556. border-radius: 15px;
  557. opacity:0.5;
  558. }
  559.  
  560. .thumbnail.clicked img {
  561. width: 80px !important;
  562. height: 80px !important;
  563. }
  564.  
  565. .thing.clicked .arrow.up {display: block}
  566. .thing.clicked .arrow.down {display:block}
  567. `;
  568.  
  569. function expandPostOnElementClick(element) {
  570. const expandoButton = element.closest('.thing').querySelector('.expando-button');
  571.  
  572. if (expandoButton) {
  573. expandoButton.click();
  574. }
  575. }
  576.  
  577. function handleElementClick(event) {
  578. event.stopPropagation();
  579. event.preventDefault();
  580.  
  581. const element = event.currentTarget;
  582. const thumbnail = element.closest('.thumbnail');
  583. const thing = element.closest('.thing');
  584.  
  585. // Check if the thumbnail has the 'clicked' class
  586. const isClicked = thumbnail.classList.contains('clicked');
  587.  
  588. if (isClicked) {
  589. // Remove the 'clicked' class to revert the changes
  590. thumbnail.classList.remove('clicked');
  591. thing.classList.remove('clicked');
  592. } else {
  593. // Add 'clicked' class to the thumbnail
  594. thumbnail.classList.add('clicked');
  595. thing.classList.add('clicked');
  596. }
  597.  
  598. expandPostOnElementClick(element);
  599. }
  600.  
  601. function attachClickListenersToElements() {
  602. const elements = document.querySelectorAll('.thumbnail, img[src*="external-preview.redd.it"]');
  603.  
  604. elements.forEach((element) => {
  605. element.addEventListener('click', handleElementClick);
  606. });
  607. }
  608.  
  609. // Add custom CSS styles
  610. GM_addStyle(customCSS);
  611.  
  612. // Attach click listeners to elements initially
  613. attachClickListenersToElements();
  614.  
  615. // Create a MutationObserver to monitor the page for changes
  616. const observer = new MutationObserver(() => {
  617. // Attach click listeners to elements whenever new content is added to the page
  618. attachClickListenersToElements();
  619. });
  620.  
  621. // Start observing the document for changes
  622. observer.observe(document, { childList: true, subtree: true });
  623.  
  624. /////////////////////Toggle Nav-Bar On Scroll /////////////////////////////////////////////////////////////
  625.  
  626.  
  627. 'use strict';
  628.  
  629. var navButtons = document.getElementsByClassName('nav-buttons');
  630. if (navButtons.length > 0) {
  631. var nav = navButtons[0];
  632. nav.style.position = 'fixed';
  633. }
  634.  
  635. //var headerHeight = header.offsetHeight;
  636. var lastScrollTop = 0;
  637.  
  638.  
  639. window.addEventListener('scroll', function() {
  640. var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
  641. var windowHeight = window.innerHeight;
  642. var documentHeight = document.documentElement.scrollHeight;
  643.  
  644. if (scrollTop === 0) {
  645. // Reached the top of the page
  646. nav.style.opacity = '1';
  647. nav.style.pointerEvents = 'auto';
  648. } else {
  649. // Scrolling up
  650. nav.style.opacity = '.8';
  651. nav.style.pointerEvents = 'auto';
  652. }
  653.  
  654. if (scrollTop + windowHeight + 10 >= documentHeight) {
  655. // Reached the end of the page
  656. nav.style.opacity = '1';
  657. nav.style.pointerEvents = 'auto';
  658. } else {
  659. if (scrollTop > lastScrollTop) {
  660. // Scrolling down
  661. nav.style.opacity = '0';
  662. nav.style.pointerEvents = 'none';
  663. }
  664. }
  665.  
  666. lastScrollTop = scrollTop;
  667. });
  668.  
  669.  
  670. /////////////////////////////////////// remove some tabs /////////////////////////////////////////////////
  671.  
  672. (function() {
  673. 'use strict';
  674.  
  675. // Function to remove the elements containing the text "gilded" or "best" from .tabmenu
  676. function removeGildedAndBestTabs() {
  677. const tabmenu = document.querySelector('.tabmenu');
  678. if (!tabmenu) return;
  679.  
  680. const tabs = tabmenu.querySelectorAll('a');
  681. for (let i = 0; i < tabs.length; i++) {
  682. const tab = tabs[i];
  683. const tabText = tab.textContent.toLowerCase();
  684. if (tabText.includes('gilded') || tabText.includes('best')) {
  685. tab.remove();
  686. }
  687. }
  688. }
  689.  
  690. // Call the function to remove the "gilded" and "best" tabs after the page has loaded
  691. window.addEventListener('load', removeGildedAndBestTabs);
  692. })();
  693.  
  694. ////////////////////////////////////// Subreddit Icon next to Subreddit name /////////////////////////
  695.  
  696. (function() {
  697. 'use strict';
  698.  
  699. function setSubredditIcon() {
  700. const pagenameLink = document.querySelector('.pagename');
  701. const subredditIcon = document.createElement('img');
  702. subredditIcon.style.verticalAlign = 'middle';
  703. subredditIcon.style.width = 'auto';
  704. subredditIcon.style.height = '35px';
  705.  
  706. const srName = getSrName();
  707.  
  708.  
  709. const srDataUrl = `https://www.reddit.com/r/${srName}/about.json`;
  710. fetch(srDataUrl)
  711. .then(response => response.json())
  712. .then(data => {
  713. const communityIcon = cleanUpCommunityIcon(data.data.community_icon);
  714. const iconUrl = communityIcon || data.data.icon_img || data.data.header_img;
  715. if (!iconUrl || iconUrl.length === 0)
  716. {
  717. return;
  718. }
  719. subredditIcon.src = iconUrl;
  720. pagenameLink.parentNode.insertBefore(subredditIcon, pagenameLink.nextSibling);
  721. })
  722.  
  723. }
  724.  
  725. function getSrName() {
  726. const srNameRegex = /https:[/][/](www|old|new)[.]reddit[.]com[/]r[/](\w+)/g;
  727. const match = srNameRegex.exec(document.location.href);
  728.  
  729. return match[2];
  730. }
  731.  
  732. function cleanUpCommunityIcon(url) {
  733. if (!url || url.length === 0) {
  734. return url;
  735. }
  736. function htmlDecode(input) {
  737. const doc = new DOMParser().parseFromString(input, 'text/html');
  738. return doc.documentElement.textContent;
  739. }
  740. const decodedUrl = htmlDecode(url);
  741. return decodedUrl;
  742. }
  743.  
  744. setSubredditIcon();
  745. })();
  746.  
  747.