修改网页字体和其他 CSS 属性值

修改网页字体,支持不同网站不同规则

  1. // ==UserScript==
  2. // @name 修改网页字体和其他 CSS 属性值
  3. // @namespace apee.top
  4. // @version 1.0
  5. // @description 修改网页字体,支持不同网站不同规则
  6. // @author github@oyps
  7. // @match *://flowus.cn/*
  8. // @match *://*.wolai.com/*
  9. // @match *://www.baidu.com/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=flowus.cn
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14. (function () {
  15. /** 默认字体 */
  16. var defaultFont = '仓耳渔阳体';
  17. /** 自定义字体设置规则,第一项是 `location` 对象的属性名,第二项是字符串或正则对象,第三项为 CSS `font-family` 值 */
  18. var rules = [
  19. ['host', 'flowus.cn', defaultFont],
  20. ['href', /^http.*?wolai.com/, '微软雅黑'],
  21. // ['host', 'www.baidu.com', {
  22. // color: 'red',
  23. // fontSize: '20px'
  24. // }]
  25. ];
  26. var dom = document.body;
  27. var changeCss = function (dom, data) {
  28. if (typeof data == 'object')
  29. for (var key in data)
  30. dom.style[key] = data[key];
  31. else
  32. dom.style.fontFamily = data;
  33. };
  34. for (var i = 0; i < rules.length; i++) {
  35. var rule = rules[i];
  36. var text = location[rule[0]];
  37. var pattern = rule[1];
  38. if (typeof pattern == 'string' && text == pattern)
  39. return changeCss(dom, rule[2]);
  40. else if (pattern instanceof RegExp && text.match(pattern))
  41. return changeCss(dom, rule[2]);
  42. }
  43. return changeCss(dom, defaultFont);
  44. })();

QingJ © 2025

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