MeFi replace quote label

MetaFilter: replace the MefiQuote label with an arrow, or a custom label

当前为 2025-03-28 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MeFi replace quote label
  3. // @namespace https://github.com/klipspringr/mefi-userscripts
  4. // @version 2025-03-28-g
  5. // @description MetaFilter: replace the MefiQuote label with an arrow, or a custom label
  6. // @author Klipspringer
  7. // @supportURL https://github.com/klipspringr/mefi-userscripts
  8. // @license MIT
  9. // @match *://*.metafilter.com/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. const getSetting = (key, defaultValue) => {
  14. try {
  15. return localStorage.getItem(key) || defaultValue;
  16. } catch {
  17. return defaultValue;
  18. }
  19. };
  20.  
  21. (async () => {
  22. if (!/^\/(\d|comments\.mefi)/.test(window.location.pathname)) return;
  23.  
  24. const to = getSetting("mefi-replace-quote-label", "↩ "); // note space, for aesthetics
  25.  
  26. const replaceQuoteLabels = () => {
  27. const nodes = document.querySelectorAll('a[class="quotebutton"]');
  28. nodes.forEach((node) => (node.textContent = to));
  29. console.log(`mefi-replace-quote-label: replaced ${nodes.length} labels`);
  30. };
  31.  
  32. const newCommentsWrapper = document.getElementById("newcomments");
  33. if (newCommentsWrapper) {
  34. // MefiQuote listens for the "mefi-comments" event, but:
  35. // (a) my event listener wasn't picking that up, for some reason; and
  36. // (b) there would be timing issues as MefiQuote needs to complete its work first
  37. // hence using MutationObserver instead
  38. const observer = new MutationObserver(() => replaceQuoteLabels());
  39. // listen for "childList" mutations, but not subtree as *we* are mutating that
  40. observer.observe(newCommentsWrapper, { childList: true });
  41. }
  42.  
  43. replaceQuoteLabels();
  44. })();