Reddit CSS

New Design with new functionalities

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

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