MacType

Render font like macOS

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         MacType
// @namespace    MacType@JMRY
// @version      0.1.2
// @license      MIT
// @description  Render font like macOS
// @author       JMRY
// @match        *://**/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';
    //字体渲染强度,默认:0.25
    var macTypeWeight=0.25;
    var macTypeCss=[
        //字体渲染样式,可根据需求自行添加CSS
        '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}',
    ];
    var macTypeWhiteList=[
        //在这里添加不希望被渲染的网站域名
    ];


    var util = {
        addStyle:function(id, tag, css) {
            tag = tag || 'style';
            var doc = document, styleDom = doc.getElementById(id);
            if (styleDom) return;
            var styleElement = doc.createElement(tag);
            styleElement.rel = 'stylesheet';
            styleElement.id = id;
            tag === 'style' ? styleElement.innerHTML = css : styleElement.href = css;
            document.head.appendChild(styleElement);
        },

        removeElementById:function(eleId) {
            var ele = document.getElementById(eleId);
            ele && ele.parentNode.removeChild(ele);
        }
    };

    var main = {
        generateStyle:function() {
            return macTypeCss.join(' ');
        },

        changeStyle:function() {
            document.getElementById('mactype-style').innerHTML = this.generateStyle();
        },

        addPluginStyle:function() {
            var insertMacTypeStyle = this.generateStyle();

            if (document.head) {
                util.addStyle('mactype-style', 'style', insertMacTypeStyle);
            }
            var headObserver = new MutationObserver(function(){
                util.addStyle('mactype-style', 'style', insertMacTypeStyle);
            });
            headObserver.observe(document.head, {childList: true, subtree: true});
        },

        isTopWindow:function() {
            return window.self === window.top;
        },

        init:function() {
            this.isTopWindow();
            if (macTypeWhiteList.includes(location.host)) return;
            this.addPluginStyle();
        }
    };
    main.init();
})();