Reddit CSS

New Design with new functionalities

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

  1. // ==UserScript==
  2. // @name Reddit CSS
  3. // @namespace https://www.reddit.com
  4. // @version 5.1
  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. .nsfw-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: 170px !important;
  70. height: 170px !important;
  71. }
  72.  
  73. /* Adjust the size of the thumbnail container */
  74. .thumbnail {
  75. width: 170px !important;
  76. height: 170px !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.  
  159.  
  160.  
  161. /* Videoplayer Background */
  162. .reddit-video-player-root {background: #0000;}
  163.  
  164. /* Video Duration Info */
  165. .duration-overlay {font-size: 10pt; font-weight: bold;}
  166. .duration-overlay {border-top-left-radius: 50px;border-top-right-radius: 50px;}
  167.  
  168. /* Space between Posts */
  169. .link {margin-bottom: 0px;}
  170.  
  171. /* Expanded Post Margins */
  172. .expando {margin: 0}
  173.  
  174. /* Gallery Buttons */
  175. .media-gallery .gallery-nav-bar {font-size:large}
  176.  
  177.  
  178. /* Rank / Scores */
  179. .link .rank {display: none}
  180. .arrow.up {display: none}
  181. .arrow.down {display: none}
  182.  
  183. /* Comment Page */
  184. .panestack-title { padding-bottom: 0px; border-bottom: none;}
  185. .commentarea .menuarea {font-size: large;}
  186. .comment .author {font-size: larger;float:left}
  187. .comment .expand {font-size: large;float:left; opacity:1;margin: 0 !important;padding: 0 !important; opacity:0}
  188. .comment .expand {width:6px}
  189. .comment.collapsed .expand { opacity:1;width:auto}
  190. .comment .midcol {z-index:9999}
  191.  
  192. .commentarea > .usertext:not(:hover) {opacity:0.2; height: 18px}
  193. .commentarea .entry .buttons:not(:hover) {opacity:0;}
  194. .comments-page #siteTable .thing {display: flex !important;border: none;}
  195. .comment .tagline {color: #00000069 ; margin-bottom: 15px; text-align:left}
  196. .comment .child {border-left: dotted 3px #000000}
  197. .comment .score {font-size: larger}
  198. .comments-page .arrow.up {display:block}
  199. .comments-page .arrow.down {display:block}
  200. .pinnable-content.pinned {background-color: #FFFFFFF7 !important;box-shadow: none !important}
  201.  
  202. /* Bottom Page */
  203. .footer {display:none}
  204. .footer-parent {opacity:0}
  205. .debuginfo {display:none}
  206. .bottommenu {opacity:0}
  207.  
  208. /* promoted posts/ads */
  209. .link.promotedlink.promoted, .link.promotedlink.external {display:none !important}
  210.  
  211. /* submissions */
  212. .formtabs-content .infobar {border:none}
  213. .content.submit .info-notice {display: none;}
  214. #items-required {display: none;}
  215.  
  216.  
  217.  
  218. /* Navbar */
  219. .nav-buttons {
  220. display:table;
  221. bottom: 0 !important;
  222. right: 0 !important;
  223. text-align: center !important;
  224. border: 3px solid;
  225. border-color: #cee3f8;
  226. border-top-left-radius: 15px;
  227. background-color: #cee3f8;
  228. font-size: larger;
  229. z-index: 9998 !important;
  230. }
  231. .nextprev a {background:none !important}
  232.  
  233.  
  234.  
  235. `;
  236.  
  237. // Add the custom CSS to the page
  238. GM_addStyle(customCSS);
  239.  
  240. ////////////////////// Remove thumbnails from posts without thumbnails////////////////////////
  241.  
  242. function removePostsWithoutImages() {
  243. var posts = document.querySelectorAll('.thumbnail');
  244. for (var i = 0; i < posts.length; i++) {
  245. if (!posts[i].querySelector('img')) {
  246. posts[i].parentNode.removeChild(posts[i]);
  247. }
  248. }
  249. }
  250. setInterval(removePostsWithoutImages, 1000);
  251. })();
  252.  
  253.  
  254. ////////////////////////////////////// comments page //////////////////////////////////
  255.  
  256. var commentpage = /https:\/\/.*\.reddit\.com\/.*\/comments\/.*/;
  257. if (commentpage.test(window.location.href)) {
  258. GM_addStyle(`.reportbtn {display:block}
  259. .post-crosspost-button {display:block}
  260. a.comments {display:none}
  261. /* .buttons .give-gold.gold-give-gold {display:block} */
  262. .expando-button {opacity: 1 }
  263. .hide-button {display:block !important}
  264.  
  265. a.embed-comment {display: none}
  266. /* a.bylink {display: none} */
  267.  
  268.  
  269. .thumbnail,.thumbnail img {width: 100px !important;height: 100px !important;}
  270. #sr-header-area {display:none}`
  271. );
  272.  
  273. ////////////////////////////////// Download Button ////////////////////////////////////
  274.  
  275.  
  276. 'use strict';
  277.  
  278. function downloadVideo() {
  279. var postUrl = window.location.href;
  280. var baseUrl = 'https://rapidsave.com/info?url=';
  281. var downloadUrl = baseUrl + encodeURIComponent(postUrl);
  282. window.open(downloadUrl, '_blank');
  283. }
  284.  
  285. function createDownloadButton() {
  286. var listItem = document.createElement('li');
  287. listItem.classList.add('reddit-video-download-button');
  288.  
  289. var button = document.createElement('button');
  290. button.innerHTML = 'Download';
  291. // button.style.color = 'white';
  292. button.style.background = 'none';
  293. button.style.border = 'none';
  294. button.style.fontSize = 'inherit';
  295. // button.style.borderRadius = '10px';
  296. // button.style.fontWeight = 'bold';
  297. button.onclick = downloadVideo;
  298.  
  299. listItem.appendChild(button);
  300.  
  301. var buttonsList = document.querySelector('ul.buttons');
  302. if (buttonsList) {
  303. buttonsList.appendChild(listItem);
  304. }
  305. }
  306.  
  307. createDownloadButton();
  308.  
  309.  
  310.  
  311. /////////////////////add profile pictures next to comments ///////////////////////
  312.  
  313. const addAvatars = async (root = document) => {
  314. Array.from(root.querySelectorAll('.thing:not(.morechildren)')).forEach(async (thing) => {
  315. if (!thing) return;
  316. if (thing.hasAttribute('data-reddit-profile-picture')) return;
  317. const img = document.createElement('img');
  318. img.classList.add('reddit-profile-picture');
  319. img.style.height = '22px';
  320. img.style.width = '22px';
  321. img.style.float = 'left';
  322. img.style.margin = '0px';
  323. thing.insertBefore(img, thing.querySelector('.entry'));
  324. thing.setAttribute('data-reddit-profile-picture', 1);
  325. if (!thing.id) return;
  326. const authorElement = thing.querySelector('.author');
  327. if (authorElement && authorElement.href) {
  328. const xhr = new XMLHttpRequest();
  329. xhr.open('GET', `${authorElement.href}/about.json`);
  330. xhr.addEventListener('load', async () => {
  331. if (xhr.status === 200) {
  332. try {
  333. const profile = JSON.parse(xhr.responseText).data;
  334. const ta = document.createElement('textarea');
  335. ta.innerHTML = profile.icon_img;
  336. img.src = ta.value;
  337. } catch (error) {
  338. // Error parsing JSON or extracting URL
  339. console.error('Error parsing JSON or extracting URL:', error);
  340. removeAvatar(img);
  341. }
  342. } else {
  343. // Non-200 status, handle error
  344. console.error('Error fetching user data:', xhr.status, xhr.statusText);
  345. removeAvatar(img);
  346. }
  347. });
  348. xhr.addEventListener('error', () => {
  349. // Network error
  350. console.error('Network error while fetching user data.');
  351. removeAvatar(img);
  352. });
  353. xhr.send();
  354. }
  355. });
  356. };
  357.  
  358. const removeAvatar = (imgElement) => {
  359. if (imgElement && imgElement.parentNode) {
  360. imgElement.parentNode.removeChild(imgElement);
  361. }
  362. };
  363.  
  364. addAvatars();
  365.  
  366. const mo = new MutationObserver((muts) => {
  367. muts.forEach((mut) => {
  368. Array.from(mut.addedNodes).forEach((node) => {
  369. if (node instanceof HTMLElement) {
  370. addAvatars();
  371. }
  372. });
  373. });
  374. });
  375. mo.observe(document.body, { childList: true, subtree: true });
  376. };
  377.  
  378. ////////////////////////////// userpage ///////////////////////////////////////////////////////////////////
  379.  
  380. var userpage = /https:\/\/.*\.reddit\.com\/user\/.*/;
  381. if (userpage.test(window.location.href)) {
  382.  
  383. GM_addStyle(`.comment, .content .details {border-bottom: 2px solid #5f99cf !important}`);
  384.  
  385. const addProfilePictures = async (root = document) => {
  386. Array.from(root.querySelectorAll('.pagename')).forEach(async (pagename) => {
  387. if (!pagename) return;
  388. if (pagename.hasAttribute('data-reddit-profile-picture')) return;
  389.  
  390. const username = pagename.textContent.trim();
  391. if (!username) return;
  392.  
  393. const img = document.createElement('img');
  394. img.classList.add('reddit-profile-picture');
  395. img.style.height = '35px';
  396. img.style.width = '35px';
  397. img.style.verticalAlign = 'middle';
  398.  
  399.  
  400. pagename.parentNode.insertBefore(img, pagename.nextSibling);
  401.  
  402. pagename.setAttribute('data-reddit-profile-picture', 1);
  403.  
  404. const xhr = new XMLHttpRequest();
  405. xhr.open('GET', `https://www.reddit.com/user/${username}/about.json`);
  406. xhr.addEventListener('load', async () => {
  407. const profile = JSON.parse(xhr.responseText).data;
  408. const ta = document.createElement('textarea');
  409. ta.innerHTML = profile.icon_img;
  410. img.src = ta.value;
  411. });
  412. xhr.send();
  413. });
  414. };
  415.  
  416. addProfilePictures();
  417.  
  418. const mo = new MutationObserver((muts) => {
  419. muts.forEach((mut) => {
  420. Array.from(mut.addedNodes).forEach((node) => {
  421. if (node instanceof HTMLElement) {
  422. addProfilePictures(node);
  423. }
  424. });
  425. });
  426. });
  427.  
  428. mo.observe(document.body, { childList: true, subtree: true });
  429. };
  430.  
  431.  
  432. //////////////////////////////////////////// red numbers if score is less than one //////////////////////////////////////
  433.  
  434. if (userpage.test(window.location.href) || commentpage.test(window.location.href)) {
  435. (function() {
  436. 'use strict';
  437.  
  438. // Function to check if the text starts with a "-" or "0"
  439. function startsWithNegativeSymbolOrZero(text) {
  440. return text.trim().startsWith('-') || text.trim().startsWith('0');
  441. }
  442.  
  443. // Get all elements with class "score likes"
  444. var scoreElements = document.querySelectorAll('.score');
  445.  
  446. // Iterate over each score element using forEach
  447. scoreElements.forEach(function(scoreElement) {
  448. var scoreText = scoreElement.textContent.trim();
  449.  
  450. // Check if the score starts with a "-" or "0"
  451. if (startsWithNegativeSymbolOrZero(scoreText)) {
  452. // Change the color to red
  453. scoreElement.style.color = 'red';
  454. scoreElement.style.fontWeight = 'bold';
  455. } else if (parseFloat(scoreText) > 1) {
  456. // Change the color to green
  457. scoreElement.style.color = 'green';
  458. scoreElement.style.fontWeight = 'bold';
  459. }
  460. });
  461. })();
  462. }
  463.  
  464. /////////////////////////grey out comment-buttons if no comments were written /////////////////////////////////
  465.  
  466.  
  467. if (!commentpage.test(window.location.href)) {
  468.  
  469. 'use strict';
  470.  
  471. const removeCommentsCount = element => {
  472. const text = element.textContent.trim();
  473. if (!isNaN(parseInt(text.charAt(0), 10))) return;
  474. element.closest('.entry .buttons li').style.opacity = '0.2';
  475. };
  476.  
  477. const commentElements = document.querySelectorAll('a.comments');
  478. commentElements.forEach(removeCommentsCount);
  479.  
  480. const observer = new MutationObserver(mutationsList => {
  481. for (const mutation of mutationsList) {
  482. if (mutation.type === 'childList') {
  483. const newCommentElements = mutation.addedNodes;
  484. newCommentElements.forEach(node => {
  485. if (node instanceof HTMLElement) {
  486. const element = node.querySelector('a.comments');
  487. if (element) removeCommentsCount(element);
  488. }
  489. });
  490. }
  491. }
  492.  
  493. });
  494.  
  495. observer.observe(document.body, { childList: true, subtree: true });
  496. };
  497.  
  498. /////////////////////////////////////////////////Thumbnail Click Functionality //////////////////
  499.  
  500. // Custom CSS for the clicked thumbnail
  501. const customCSS = `
  502. /* Makes Clicking Easier */
  503. .thumbnail {z-index:99}
  504.  
  505. .thumbnail.clicked {
  506. width: 80px !important;
  507. height: 80px !important;
  508. border-radius: 15px;
  509. }
  510.  
  511. .thumbnail.clicked img {
  512. width: 80px !important;
  513. height: 80px !important;
  514. }
  515.  
  516. .thing.clicked .arrow.up {display: block}
  517. .thing.clicked .arrow.down {display:block}
  518. `;
  519.  
  520. function expandPostOnElementClick(element) {
  521. const expandoButton = element.closest('.thing').querySelector('.expando-button');
  522.  
  523. if (expandoButton) {
  524. expandoButton.click();
  525. }
  526. }
  527.  
  528. function handleElementClick(event) {
  529. event.stopPropagation();
  530. event.preventDefault();
  531.  
  532. const element = event.currentTarget;
  533. const thumbnail = element.closest('.thumbnail');
  534. const thing = element.closest('.thing');
  535.  
  536. // Check if the thumbnail has the 'clicked' class
  537. const isClicked = thumbnail.classList.contains('clicked');
  538.  
  539. if (isClicked) {
  540. // Remove the 'clicked' class to revert the changes
  541. thumbnail.classList.remove('clicked');
  542. thing.classList.remove('clicked');
  543. } else {
  544. // Add 'clicked' class to the thumbnail
  545. thumbnail.classList.add('clicked');
  546. thing.classList.add('clicked');
  547. }
  548.  
  549. expandPostOnElementClick(element);
  550. }
  551.  
  552. function attachClickListenersToElements() {
  553. const elements = document.querySelectorAll('.thumbnail, img[src*="external-preview.redd.it"]');
  554.  
  555. elements.forEach((element) => {
  556. element.addEventListener('click', handleElementClick);
  557. });
  558. }
  559.  
  560. // Add custom CSS styles
  561. GM_addStyle(customCSS);
  562.  
  563. // Attach click listeners to elements initially
  564. attachClickListenersToElements();
  565.  
  566. // Create a MutationObserver to monitor the page for changes
  567. const observer = new MutationObserver(() => {
  568. // Attach click listeners to elements whenever new content is added to the page
  569. attachClickListenersToElements();
  570. });
  571.  
  572. // Start observing the document for changes
  573. observer.observe(document, { childList: true, subtree: true });
  574.  
  575. /////////////////////Toggle Nav-Bar On Scroll /////////////////////////////////////////////////////////////
  576.  
  577.  
  578. 'use strict';
  579.  
  580. var navButtons = document.getElementsByClassName('nav-buttons');
  581. if (navButtons.length > 0) {
  582. var nav = navButtons[0];
  583. nav.style.position = 'fixed';
  584. }
  585.  
  586. //var headerHeight = header.offsetHeight;
  587. var lastScrollTop = 0;
  588.  
  589.  
  590. window.addEventListener('scroll', function() {
  591. var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
  592. var windowHeight = window.innerHeight;
  593. var documentHeight = document.documentElement.scrollHeight;
  594.  
  595. if (scrollTop === 0) {
  596. // Reached the top of the page
  597. nav.style.opacity = '1';
  598. nav.style.pointerEvents = 'auto';
  599. } else {
  600. // Scrolling up
  601. nav.style.opacity = '.8';
  602. nav.style.pointerEvents = 'auto';
  603. }
  604.  
  605. if (scrollTop + windowHeight + 10 >= documentHeight) {
  606. // Reached the end of the page
  607. nav.style.opacity = '1';
  608. nav.style.pointerEvents = 'auto';
  609. } else {
  610. if (scrollTop > lastScrollTop) {
  611. // Scrolling down
  612. nav.style.opacity = '0';
  613. nav.style.pointerEvents = 'none';
  614. }
  615. }
  616.  
  617. lastScrollTop = scrollTop;
  618. });
  619.  
  620.  
  621. /////////////////////////////////////// remove some tabs /////////////////////////////////////////////////
  622.  
  623. (function() {
  624. 'use strict';
  625.  
  626. // Function to remove the elements containing the text "gilded" or "best" from .tabmenu
  627. function removeGildedAndBestTabs() {
  628. const tabmenu = document.querySelector('.tabmenu');
  629. if (!tabmenu) return;
  630.  
  631. const tabs = tabmenu.querySelectorAll('a');
  632. for (let i = 0; i < tabs.length; i++) {
  633. const tab = tabs[i];
  634. const tabText = tab.textContent.toLowerCase();
  635. if (tabText.includes('gilded') || tabText.includes('best')) {
  636. tab.remove();
  637. }
  638. }
  639. }
  640.  
  641. // Call the function to remove the "gilded" and "best" tabs after the page has loaded
  642. window.addEventListener('load', removeGildedAndBestTabs);
  643. })();
  644.  
  645. ////////////////////////////////////// Subreddit Icon next to Subreddit name /////////////////////////
  646.  
  647. (function() {
  648. 'use strict';
  649.  
  650. function setSubredditIcon() {
  651. const pagenameLink = document.querySelector('.pagename');
  652. const subredditIcon = document.createElement('img');
  653. subredditIcon.style.verticalAlign = 'middle';
  654. subredditIcon.style.width = 'auto';
  655. subredditIcon.style.height = '35px';
  656.  
  657. const srName = getSrName();
  658.  
  659.  
  660. const srDataUrl = `https://www.reddit.com/r/${srName}/about.json`;
  661. fetch(srDataUrl)
  662. .then(response => response.json())
  663. .then(data => {
  664. const communityIcon = cleanUpCommunityIcon(data.data.community_icon);
  665. const iconUrl = communityIcon || data.data.icon_img || data.data.header_img;
  666. if (!iconUrl || iconUrl.length === 0)
  667. {
  668. return;
  669. }
  670. subredditIcon.src = iconUrl;
  671. pagenameLink.parentNode.insertBefore(subredditIcon, pagenameLink.nextSibling);
  672. })
  673.  
  674. }
  675.  
  676. function getSrName() {
  677. const srNameRegex = /https:[/][/](www|old|new)[.]reddit[.]com[/]r[/](\w+)/g;
  678. const match = srNameRegex.exec(document.location.href);
  679.  
  680. return match[2];
  681. }
  682.  
  683. function cleanUpCommunityIcon(url) {
  684. if (!url || url.length === 0) {
  685. return url;
  686. }
  687. function htmlDecode(input) {
  688. const doc = new DOMParser().parseFromString(input, 'text/html');
  689. return doc.documentElement.textContent;
  690. }
  691. const decodedUrl = htmlDecode(url);
  692. return decodedUrl;
  693. }
  694.  
  695. setSubredditIcon();
  696. })();
  697.  
  698.  
  699.  
  700.