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