阅读:5933回复:7
[已解决]能不能用不同的字体,分别显示常规和粗体的脚本?
油猴扩展。
网页只有一个字体,看腻了。 想要以不同的字体来显示粗体,比如常规用黑体,粗体用宋体。 或者按字号来选择不同字体,比如12号以下是黑体,12号以上是宋体。 |
|
1楼#
发布于:2021-10-18 17:42
分享一个我现在用的字体脚本,text-shadow 那里适当添加阴影,可以让 chromium 系浏览器的字体效果实现类似 firefox 和 mactype 的效果:
// ==UserScript== // @name Replace fonts // @name:zh-CN 替换网页字体 // @namespace https://* // @version 3.3 // @author zozovo // @description Replace fonts // @description:zh-CN 替换网页字体 // @include * // @supportURL https://* // @run-at document-start // @grant GM_addStyle // @license MIT // ==/UserScript== (function () { GM_addStyle(` :root body :not(:is(em,i)){font-family:"HarmonyOS Sans SC",system-ui,emoji} :root :is([lang$=HK],[lang$=MO]) :not(:is(em,i)){font-family:"HarmonyOS Sans SC",system-ui,emoji} :root :is([lang$=TW],[lang$=hant]) :not(:is(em,i)){font-family:"HarmonyOS Sans SC",system-ui,emoji} :root :lang(ja) :not(:is(em,i)){font-family:"HarmonyOS Sans SC",system-ui,emoji} :root :lang(ko) :not(:is(em,i)){font-family:"HarmonyOS Sans SC",system-ui,emoji} :root body :is(pre,code,samp,kbd,var){font-family:"HarmonyOS Sans SC"} :root body :is(pre,code,samp,kbd,var) span{font-family:"HarmonyOS Sans SC"} `); GM_addStyle('* {text-shadow : 0.01em 0.01em 0.01em #999999}'); })(); |
|
2楼#
发布于:2021-10-18 20:09
可以用@font-face语法实现,指定常规和粗体分别用不同字体。
原理就是利用font-face替换页面字体的功能来分别替换粗体和常规字体。 把local后面的sans-serif换成你想要替换的字体,有font-weight那行的就是替换粗体的。 效果如下图,可以看到常规体是点阵字体,粗体是矢量字体。 ![]() @-moz-document regexp("^(https?|ftp)://.*$") { /*英文字体替换*/ @font-face { font-family:'Arial'; src: local('sans-serif'); } @font-face { font-family:'Arial'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'helvetica'; src: local('sans-serif'); } @font-face { font-family:'helvetica'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'Verdana'; src: local('sans-serif'); } @font-face { font-family:'Verdana'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'Lucida Grande'; src: local('sans-serif'); } @font-face { font-family:'Lucida Grande'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'Tahoma'; src: local('sans-serif'); } @font-face { font-family:'Tahoma'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'Segoe UI'; src: local('sans-serif'); } @font-face { font-family:'Segoe UI'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'Montserrat'; src: local('sans-serif'); } @font-face { font-family:'Montserrat'; src: local('sans-serif'); font-weight:bold; } /*中文字体替换*/ @font-face { font-family:'Simsun'; src: local('sans-serif'); } @font-face { font-family:'Simsun'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'宋体'; src: local('sans-serif'); } @font-face { font-family:'宋体'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'\5B8B\4F53'; src: local('sans-serif'); } @font-face { font-family:'\5B8B\4F53'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'寰蒋闆呴粦'; src: local('sans-serif'); } @font-face { font-family:'寰蒋闆呴粦'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'Microsoft Yahei'; src: local('sans-serif'); } @font-face { font-family:'Microsoft Yahei'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'微软雅黑'; src: local('sans-serif'); } @font-face { font-family:'微软雅黑'; src: local('sans-serif'); font-weight:bold; } @font-face { font-family:'Simhei'; src: local('sans-serif'); } @font-face { font-family:'Simhei'; src: local('sans-serif'); font-weight:bold; } } |
|
3楼#
发布于:2021-10-19 17:59
|
|
4楼#
发布于:2022-01-08 15:34
alanfly:可以用@font-face语法实现,指定常规和粗体分别用不同字体。有一些页面指定粗体不生效,请问是什么原因?比如: https://wiki.archlinux.org/title/Arch_Linux https://www.archlinuxcn.org/ |
|
5楼#
发布于:2022-01-08 21:59
fire/fox:有一些页面指定粗体不生效,请问是什么原因?比如:因为需要有具体的字体才能替换,上述两个页面的css都没有指定页面字体,而是设置成了‘sans-serif’。 sans-serif字体选择归系统字体链接管理的。 sans-serif是无衬线字体族,不是具体的某一个字体,我试了下无法替换。 或者你可以单独给没指定具体字体族的网站设置字体,这样替换就生效了。 @-moz-document domain(archlinux.org),domain(archlinuxcn.org) { * { font-family:helvetica; } } |
|
6楼#
发布于:2022-01-08 22:44
|
|
7楼#
发布于:2022-02-05 12:07
嗯,中易宋体的12px以下不能看,黑体也只是差强人意,这样的情况感觉 font-weight 确实比较理想合适
|
|
|