字体替换 (Font replacer)

替换网站硬编码在 CSS 中的字体

  1. // ==UserScript==
  2. // @name Font replacer
  3. // @name:zh-CN 字体替换 (Font replacer)
  4. // @name:zh-TW 字型替換 (Font replacer)
  5. // @namespace font-replacer
  6. // @grant GM_addStyle
  7. // @version 1.0
  8. // @author Coxxs
  9. // @description Replace fonts hard coded by websites
  10. // @description:zh-cn 替换网站硬编码在 CSS 中的字体
  11. // @description:zh-tw 替換網站寫死在 CSS 中的字型
  12. // @include *
  13. // @license MIT
  14. // @run-at document-start
  15. // ==/UserScript==
  16. class Replacer {
  17. constructor() {
  18. this.css = []
  19. }
  20. add(from, to) {
  21. for (const font of to) {
  22. let extra = ''
  23. if (font.weight) {
  24. extra += `font-weight:${font.weight};`
  25. }
  26. this.css.push(`@font-face{font-family:"${from}";${extra}src:local("${font.name}")}`)}
  27. }
  28. toString() {
  29. return this.css.join('')
  30. }
  31. }
  32. let replacer = new Replacer()
  33. /**** Replace rules START *****/
  34.  
  35. const SourceHanSansSC = [{ name: 'Source Han Sans SC' }]
  36. const SourceHanSansTC = [{ name: 'Source Han Sans TC' }]
  37.  
  38. const HarmonyOSSansSC = [{ name: 'HarmonyOS Sans SC' }]
  39. const HarmonyOSSansTC = [{ name: 'HarmonyOS Sans TC' }]
  40.  
  41. const MiSans = [
  42. { name: 'MiSans Thin', weight: 100 },
  43. { name: 'MiSans ExtraLight', weight: 200 },
  44. { name: 'MiSans Light', weight: 300 },
  45. { name: 'MiSans Regular', weight: 400 },
  46. { name: 'MiSans Medium', weight: 500 },
  47. { name: 'MiSans Demibold', weight: 600 },
  48. { name: 'MiSans Bold', weight: 700 },
  49. { name: 'MiSans Heavy', weight: 900 },
  50. ]
  51.  
  52. // Simpified Chinese
  53. const FontSC = SourceHanSansSC
  54. replacer.add("宋体", FontSC)
  55. replacer.add("SimSun", FontSC)
  56. replacer.add("新宋体", FontSC)
  57. replacer.add("NSimSun", FontSC)
  58. replacer.add("微软雅黑", FontSC)
  59. replacer.add("Microsoft YaHei", FontSC)
  60. replacer.add("Microsoft YaHei UI", FontSC)
  61. replacer.add("黑体", FontSC)
  62. replacer.add("SimHei", FontSC)
  63. // replacer.add("华文中宋", FontSC)
  64. // replacer.add("STZhongsong", FontSC)
  65. // replacer.add("华文细黑", FontSC)
  66. // replacer.add("STXihei", FontSC)
  67. // replacer.add("STHeiTi", FontSC)
  68. // replacer.add("幼圆", FontSC)
  69.  
  70. // Traditional Chinese
  71. const FontTC = SourceHanSansTC
  72. replacer.add("微軟正黑體", FontTC)
  73. replacer.add("Microsoft JhengHei", FontTC)
  74. replacer.add("Microsoft JhengHei UI", FontTC)
  75. replacer.add("新細明體", FontTC)
  76. replacer.add("PMingLiU", FontTC)
  77. replacer.add("細明體", FontTC)
  78. replacer.add("MingLiU", FontTC)
  79.  
  80.  
  81. /**** Replace rules END *****/
  82. GM_addStyle(replacer.toString())

QingJ © 2025

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