Reddit CSS

New Design with new functionalities

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

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