Reddit CSS

New Design with new functionalities

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

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