Reddit CSS

New Design with new functionalities

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

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