Font Substitution v3

Substitutes arbitrary fonts on webpages

当前为 2015-08-26 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Font Substitution v3
  3. // @description Substitutes arbitrary fonts on webpages
  4. // @author Alan Davies
  5. // @copyright 2015, Alan Davies
  6. // @version 3.0.0
  7. // @date 2015-08-26
  8. // @namespace FontSub3
  9. // @include *
  10. // @grant GM_addStyle
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. var globalDebug = false;
  15.  
  16. if (globalDebug) console.log("Font substitution start");
  17.  
  18. var fontMap = new Map([
  19. [ "arial", "Verdana" ],
  20. [ "helvetica", "Verdana" ],
  21. [ "courier", "Consolas" ],
  22. [ "courier new", "Consolas" ]
  23. ]);
  24.  
  25. function OverrideFontFaces()
  26. {
  27. for (let fontSub of fontMap)
  28. {
  29. let style = "@font-face { font-family: \"" + fontSub[0] + "\"; src: local(\"" + fontSub[1] + "\") !important }";
  30.  
  31. if (globalDebug) console.log("Adding style: " + style);
  32.  
  33. GM_addStyle(style);
  34. }
  35. }
  36.  
  37. var done = false;
  38.  
  39. // create an observer instance
  40. var observer = new MutationObserver(function(mutations) {
  41. if (globalDebug) console.log("Mutation event");
  42. // Add the font face overrides once we have a body element
  43. if (!done && (null != document.body))
  44. {
  45. observer.disconnect();
  46. OverrideFontFaces();
  47. done = true;
  48. }
  49. });
  50.  
  51. observer.observe(document, { childList: true, attributes: false, characterData: false, subtree: true });

QingJ © 2025

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