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