Greasy Fork is available in English.

MacType

Render font like macOS

  1. // ==UserScript==
  2. // @name MacType
  3. // @namespace MacType@JMRY
  4. // @version 0.1.2
  5. // @license MIT
  6. // @description Render font like macOS
  7. // @author JMRY
  8. // @match *://**/*
  9. // @grant none
  10. // @run-at document-start
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. //字体渲染强度,默认:0.25
  16. var macTypeWeight=0.25;
  17. var macTypeCss=[
  18. //字体渲染样式,可根据需求自行添加CSS
  19. 'html, body, input, textarea, select, button, div, p, span, iframe, h1, h2, h3, h4, h5, h6, pre{-webkit-text-stroke:'+macTypeWeight+'px !important; text-stroke:'+macTypeWeight+'px}',
  20. ];
  21. var macTypeWhiteList=[
  22. //在这里添加不希望被渲染的网站域名
  23. ];
  24.  
  25.  
  26. var util = {
  27. addStyle:function(id, tag, css) {
  28. tag = tag || 'style';
  29. var doc = document, styleDom = doc.getElementById(id);
  30. if (styleDom) return;
  31. var styleElement = doc.createElement(tag);
  32. styleElement.rel = 'stylesheet';
  33. styleElement.id = id;
  34. tag === 'style' ? styleElement.innerHTML = css : styleElement.href = css;
  35. document.head.appendChild(styleElement);
  36. },
  37.  
  38. removeElementById:function(eleId) {
  39. var ele = document.getElementById(eleId);
  40. ele && ele.parentNode.removeChild(ele);
  41. }
  42. };
  43.  
  44. var main = {
  45. generateStyle:function() {
  46. return macTypeCss.join(' ');
  47. },
  48.  
  49. changeStyle:function() {
  50. document.getElementById('mactype-style').innerHTML = this.generateStyle();
  51. },
  52.  
  53. addPluginStyle:function() {
  54. var insertMacTypeStyle = this.generateStyle();
  55.  
  56. if (document.head) {
  57. util.addStyle('mactype-style', 'style', insertMacTypeStyle);
  58. }
  59. var headObserver = new MutationObserver(function(){
  60. util.addStyle('mactype-style', 'style', insertMacTypeStyle);
  61. });
  62. headObserver.observe(document.head, {childList: true, subtree: true});
  63. },
  64.  
  65. isTopWindow:function() {
  66. return window.self === window.top;
  67. },
  68.  
  69. init:function() {
  70. this.isTopWindow();
  71. if (macTypeWhiteList.includes(location.host)) return;
  72. this.addPluginStyle();
  73. }
  74. };
  75. main.init();
  76. })();