Reddit button to clean recents

Add button to clean recents

  1. // ==UserScript==
  2. // @name Reddit button to clean recents
  3. // @namespace https://gf.qytechs.cn/users/821661
  4. // @match https://www.reddit.com/*
  5. // @grant none
  6. // @version 1.1
  7. // @author hdyzen
  8. // @description Add button to clean recents
  9. // ==/UserScript==
  10.  
  11. const recentSvg = `
  12. <svg id="clear-recents" viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg" height="32" width="32">
  13. <rect x="20" y="18" width="6" height="2" transform="translate(46 38) rotate(-180)"></rect>
  14. <rect x="22" y="22" width="6" height="2" transform="translate(50 46) rotate(-180)"></rect><rect x="24" y="26" width="6" height="2" transform="translate(54 54) rotate(-180)"></rect>
  15. <path d="M17.0029,20a4.8952,4.8952,0,0,0-2.4044-4.1729L22,3,20.2691,2,12.6933,15.126A5.6988,5.6988,0,0,0,7.45,16.6289C3.7064,20.24,3.9963,28.6821,4.01,29.04a1,1,0,0,0,1,.96H20.0012a1,1,0,0,0,.6-1.8C17.0615,25.5439,17.0029,20.0537,17.0029,20ZM11.93,16.9971A3.11,3.11,0,0,1,15.0041,20c0,.0381.0019.208.0168.4688L9.1215,17.8452A3.8,3.8,0,0,1,11.93,16.9971ZM15.4494,28A5.2,5.2,0,0,1,14,25H12a6.4993,6.4993,0,0,0,.9684,3H10.7451A16.6166,16.6166,0,0,1,10,24H8a17.3424,17.3424,0,0,0,.6652,4H6c.031-1.8364.29-5.8921,1.8027-8.5527l7.533,3.35A13.0253,13.0253,0,0,0,17.5968,28Z"></path>
  16. <rect width="32" height="32" fill="none"></rect>
  17. </svg>
  18. `;
  19.  
  20. const style = `
  21. <style>
  22. #clear-recents {
  23. fill: var(--color-secondary);
  24. padding: 4px;
  25. border-radius: 8px;
  26. transition: 0.22s ease-in-out background-color;
  27. cursor: pointer;
  28. }
  29. #clear-recents:hover {
  30. background-color: var(--color-neutral-background-hover);
  31. }
  32. </style>
  33. `;
  34.  
  35. function mutationsHandler() {
  36. const recentsHeader = document.getElementsByTagName("reddit-recent-pages")?.[0];
  37. const recentsLi = recentsHeader?.shadowRoot?.querySelector("li");
  38.  
  39. if (recentsLi) {
  40. observer.disconnect();
  41.  
  42. const child = recentsLi.children[0];
  43. console.log(recentsLi);
  44.  
  45. recentsLi.style.display = "flex";
  46. recentsLi.style.gap = ".5rem";
  47. recentsLi.style.justifyContent = "center";
  48. recentsLi.style.alignItems = "center";
  49.  
  50. child.style.flexGrow = "1";
  51.  
  52. recentsLi.insertAdjacentHTML("beforeend", recentSvg + style);
  53.  
  54. const svg = recentsLi.children[1];
  55.  
  56. svg.addEventListener("click", (e) => {
  57. e.preventDefault();
  58.  
  59. localStorage.removeItem("recent-subreddits-store");
  60. recentsHeader.shadowRoot.innerHTML = "";
  61. });
  62. }
  63. }
  64.  
  65. const observer = new MutationObserver(mutationsHandler);
  66.  
  67. observer.observe(document.body, {
  68. childList: true,
  69. subtree: true,
  70. });

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址