Font substitution: Noto Serif CJK JP using local fonts for Android9+

Userscript to use Local JP Serif font on all websites in Android browser for Android 9+.

当前为 2023-02-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Font substitution: Noto Serif CJK JP using local fonts for Android9+
  3. // @name:ja フォント置換:Noto Serif CJK JP Android9以降搭載のローカルフォント
  4. // @namespace https://greasyfork.org/ja/users/747568-yomosu
  5. // @description Userscript to use Local JP Serif font on all websites in Android browser for Android 9+.
  6. // @description:ja ウェブページでローカルの日本語明朝体フォントを使うユーザースクリプト。Android 9以降用。
  7. // @version 0.1.20220611.2
  8. // @license CC0-1.0
  9. // @include http://*
  10. // @include https://*
  11. // @match *://*/*
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. const setSerifFont = () => {
  19. const newFontFamilyName = 'Noto Serif CJK JP';
  20. // const oldFontFamilyNames = [
  21. // "Roboto",
  22. // "Google Sans",
  23. // "Droid Sans",
  24. // "MotoyaLMaru",
  25. // "MotoyaLCedar",
  26. // "Noto Sans JP",
  27. // "Noto Sans CJK JP",
  28. // "SEC CJK JP",
  29. // "Droid Sans Japanese"
  30. // ]
  31. const font = new FontFace(newFontFamilyName, `local(${newFontFamilyName})`);
  32. font.load().then(() => {document.fonts.add(font)});
  33. const myHead = document.getElementsByTagName('head')[0];
  34. const myCss = document.createElement('style');
  35. myCss.id = 'set_serif_font_style';
  36. myCss.insertAdjacentHTML('beforeend', `
  37. @font-face {font-family: ${newFontFamilyName}; src: local(${newFontFamilyName});}
  38. @font-face {font-family: "Roboto"; src: local(${newFontFamilyName});}
  39. @font-face {font-family: "Google Sans"; src: local(${newFontFamilyName});}
  40. @font-face {font-family: "Droid Sans"; src: local(${newFontFamilyName});}
  41. @font-face {font-family: "MotoyaLMaru"; src: local(${newFontFamilyName});}
  42. @font-face {font-family: "MotoyaLCedar"; src: local(${newFontFamilyName});}
  43. @font-face {font-family: "Noto Sans JP"; src: local(${newFontFamilyName});}
  44. @font-face {font-family: "Noto Sans CJK JP"; src: local(${newFontFamilyName});}
  45. @font-face {font-family: "SEC CJK JP"; src: local(${newFontFamilyName});}
  46. @font-face {font-family: "Droid Sans Japanese"; src: local(${newFontFamilyName});}
  47. *:not(pre):not(span):not(code):not(samp){font-family:'USERFONT-${newFontFamilyName}', Charis SIL Compact, Noto Serif CJK JP, Noto Serif, Droid Serif, serif;}
  48. `);
  49. myHead.appendChild(myCss);
  50. };
  51.  
  52. if (document.readyState === "loading") {
  53. document.addEventListener("DOMContentLoaded", setSerifFont);
  54. } else {
  55. setSerifFont();
  56. }
  57. })();