font mono beta🔧

let english website display mono font

目前为 2023-10-04 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name font mono beta🔧
  3. // @description let english website display mono font
  4. // @namespace font_mono
  5. // @author Covenant
  6. // @version 0.9
  7. // @license MIT
  8. // @homepage
  9. // @match *://*/*
  10. // @exclude https://fonts.google.com/*
  11. // @exclude https://fonts.bunny.net/*
  12. // @exclude https://codepen.io/*
  13. // @exclude https://web.archive.org/*
  14. // @exclude https://www.programmingfonts.org/*
  15. // @exclude https://www.codingfont.com/*
  16. // @exclude https://fonts.adobe.com/*
  17. // @exclude file:///*
  18. // @icon data:image/svg+xml;base64,PHN2ZyB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBhcmlhLWhpZGRlbj0idHJ1ZSIgaGVpZ2h0PSIxNiIgdmlld0JveD0iMCAwIDE2IDE2IiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxNiIgZGF0YS12aWV3LWNvbXBvbmVudD0idHJ1ZSIgY2xhc3M9Im9jdGljb24gb2N0aWNvbi1pbmZvIj4KICAgIDxwYXRoIGQ9Ik0wIDhhOCA4IDAgMSAxIDE2IDBBOCA4IDAgMCAxIDAgOFptOC02LjVhNi41IDYuNSAwIDEgMCAwIDEzIDYuNSA2LjUgMCAwIDAgMC0xM1pNNi41IDcuNzVBLjc1Ljc1IDAgMCAxIDcuMjUgN2gxYS43NS43NSAwIDAgMSAuNzUuNzV2Mi43NWguMjVhLjc1Ljc1IDAgMCAxIDAgMS41aC0yYS43NS43NSAwIDAgMSAwLTEuNWguMjV2LTJoLS4yNWEuNzUuNzUgMCAwIDEtLjc1LS43NVpNOCA2YTEgMSAwIDEgMSAwLTIgMSAxIDAgMCAxIDAgMloiIGZpbGw9IiNGRkZGRkYiPjwvcGF0aD4KPC9zdmc+
  19. // @grant GM_setValue
  20. // @grant GM_getValue
  21. // @grant GM_registerMenuCommand
  22. // @connect
  23. // @run-at document-body
  24. // @noframes
  25. // ==/UserScript==
  26. const ary_os_font=[["","'Consolas',","'Cascadia Mono',","'Noto Mono',","'Noto Sans Mono',","'DroidSans_Mono',"],["'Cutive Mono',","'Courier Prime',","'M PLUS 1 Code',","'Xanh Mono',","'New Tegomin',"]];
  27. const ary_url=["https://fonts.googleapis.com/css2?family=Cutive+Mono&display=swap",
  28. "https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400;1,700&display=swap",
  29. "https://fonts.googleapis.com/css2?family=M+PLUS+1+Code:wght@100;200;300;400;500;600;700&display=swap",
  30. "https://fonts.googleapis.com/css2?family=Xanh+Mono:ital@0;1&display=swap",
  31. "https://fonts.googleapis.com/css2?family=New+Tegomin&display=swap"]
  32. var value=GM_getValue('value', [0,0]);
  33. var web_font_name=GM_getValue('web_font_name', ary_os_font[value[0]][value[1]]);
  34. var font_weight=GM_getValue('font_weight', 300);
  35. var letter_spacing=web_font_name=="'Cutive Mono',"?"letter-spacing: -0.05em;":"";
  36. var timeoutID_1;
  37. function create_style(textContent,id,class_name){
  38. let style=create_node("style",class_name,true,document.body);
  39. style.type='text/css';
  40. style.id=id;
  41. style.textContent=textContent;
  42. return style;
  43. }
  44. const font_family_code="font-family: "+web_font_name+"'Noto Sans Mono','Noto Mono','Cascadia Mono','Consolas','DroidSans_Mono','Courier New','Courier New','color_emoji','Noto Sans CJK JP','Meiryo','Yu Gothic','Microsoft JhengHei','Noto Sans Symbols','Noto Sans Symbols2','symbol_emoji','emoji_back',monospace;";
  45. const font_face_default=`
  46. @font-face{font-family: 'color_emoji';src: local('Twemoji Mozilla'),/*url('file:///C:/Program Files/Mozilla Firefox/fonts/TwemojiMozilla.ttf'),*/local('Noto Color Emoji'),local('Segoe UI Emoji'),local('Apple Color Emoji');}
  47. @font-face{font-family: 'symbol_emoji';src: local('Segoe UI Symbol'),local('NotoSansSymbols-Regular-Subsetted');}\n@font-face{font-family: 'emoji_back';src: local('Noto Color Emoji'),local('Toss Face Font Web'),local('Segoe UI Emoji');}
  48. @font-face{font-family: 'old_google';src: local('Noto Color Emoji'),local('NotoColorEmoji');}\n@font-face{font-family: 'old_samsung';src: local('SamsungColorEmoji');}
  49. @font-face{font-family: 'DroidSans_Mono';src: local('DroidSansMono');}\n@font-face{font-family: 'Cutive_Mono';src: local('Cutive Mono');}
  50. @font-face{font-family: 'Roboto_Regular';src: local('Roboto');}\n@font-face{font-family: 'Noto_Serif';src: local('NotoSerif');}
  51. @font-face{font-family: 'Dancing_Script';src: local('DancingScript');}\n@font-face{font-family: 'Coming_Soon';src: local('ComingSoon');}
  52. \n`;
  53. var style_font_face;
  54. var style_user_css;
  55. if(document.body!=null){
  56. style_font_face=create_style(font_face_default,"gm_font_face_font_monospace",["user_gm_font_face","css_font_monospace"]);
  57. style_user_css=create_style("","gm_user_css_font_monospace",["user_gm_css","css_font_monospace"]);
  58. style_user_css.textContent+=`
  59. html:lang(en),body:lang(en),body:not(.fake_class) p:lang(en):not(.fake_class),body:lang(en):not(.fake_class) a:not(.fake_class),body:lang(en) li,body:lang(en) div:not(.emoji),body:lang(en) section,body:lang(en) blockquote
  60. {`+font_family_code+`font-weight: `+font_weight+`;`+letter_spacing+`/*font-size: 0.99em;font-stretch: ultra-condensed;*/}
  61. body:not(.fake_class) p:lang(en):not(.fake_class){font-size: 1rem;}
  62. html:lang(en) a{font-stretch: ultra-condensed;}\n`
  63. }
  64. function create_link_stylesheet(url,class_name,is_appendChild,node,refNode){
  65. let link_stylesheet=create_node("link",class_name,is_appendChild,node,refNode);
  66. link_stylesheet.rel="stylesheet";
  67. link_stylesheet.href=url;
  68. return link_stylesheet;
  69. }
  70. function create_node(tagname,class_name,is_appendChild,node,refNode){
  71. let element=document.createElement(tagname);
  72. element.id="";
  73. if(Array.isArray(class_name)){
  74. for(let i=0; i<class_name.length; i++){element.classList.add(class_name[i]);}
  75. }else if(typeof class_name==='string'){element.classList.add(class_name);}
  76. if(is_appendChild){node.appendChild(element);}else{node.insertBefore(element, refNode);}
  77. return element;
  78. }
  79. function fn_url(url){
  80. let obj_url=new URL(url);
  81. let params=obj_url.searchParams;
  82. //let params=new URLSearchParams(obj_url.search);
  83. return [obj_url,params];
  84. }
  85. //console.log("break");
  86. function style_01(){
  87. if(style_user_css.parentNode==undefined){
  88. console.log("style_font_mono undefined");
  89. document.body.appendChild(style_font_face);
  90. document.body.appendChild(style_user_css);
  91. window.clearInterval(timeoutID_1);
  92. }
  93. }
  94. (function() {
  95. 'use strict';
  96. if(document.body==null)return;
  97. let url=fn_url(document.location);
  98. timeoutID_1=window.setInterval(( () => style_01()), 1000);
  99. //window.setTimeout(( () => style_01() ), 10000);
  100. GM_registerMenuCommand("use os mono font"+(value[0]==0?"✔️":""), () => {
  101. if(value[0]==0){
  102. value[1]=(value[1]+1)%(ary_os_font[value[0]].length);
  103. value=GM_setValue('value', [value[0],value[1]]);
  104. }
  105. else if(value[0]==1){
  106. value=GM_setValue('value', [0,1]);
  107. }
  108. });
  109. GM_registerMenuCommand("use web font"+(value[0]==1?"✔️":""), () => {
  110. if(value[0]==1){
  111. value[1]=(value[1]+1)%(ary_os_font[value[0]].length);
  112. value=GM_setValue('value', [value[0],value[1]]);
  113. }
  114. else if(value[0]==0){
  115. value=GM_setValue('value', [1,0]);
  116. }
  117. });
  118. if(value[0]==1){
  119. if(url[0].host.search(new RegExp("github.com", "i"))!=0&&url[0].host.search(new RegExp("steamdb.info", "i"))!=0&&url[0].host.search(new RegExp("developer.mozilla.org", "i"))!=0){
  120. let link=create_link_stylesheet(ary_url[value[1]],"gm_font_face_font_monospace",true,document.head);
  121. GM_registerMenuCommand("rst, "+web_font_name, () => {
  122. value=GM_setValue('value', [0,0]);
  123. });
  124. }
  125. else{
  126. GM_registerMenuCommand("rst, load webfont css fail", () => {
  127. value=GM_setValue('value', [0,0]);
  128. });
  129. }
  130. }
  131. //console.log(style_user_css.parentNode);
  132. })();