Default fonts

Replace web fonts with browser's default fonts

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Default fonts
// @version      1.1
// @description  Replace web fonts with browser's default fonts
// @author       KenHV
// @namespace    https://kenhv.com
// @supportURL   https://kenhv.com
// @homepageURL  https://kenhv.com
// @match        *://*/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
  "use strict";

  // Cache to keep track of processed rules and stylesheets
  const processedRules = new WeakSet();
  const processedStyleSheets = new WeakSet();

  function fontReplace() {
    Array.from(document.styleSheets).forEach((styleSheet) => {
      if (processedStyleSheets.has(styleSheet)) {
        return;
      }

      let rules;
      try {
        rules = Array.from(styleSheet.cssRules);
      } catch (err) {
        return;
      }

      rules.forEach((rule) => {
        if (rule instanceof CSSStyleRule && !processedRules.has(rule)) {
          if (rule.style.fontFamily.includes("sans")) {
            rule.style.fontFamily = "sans-serif";
            processedRules.add(rule);
            return;
          }
          if (rule.style.fontFamily.includes("serif")) {
            rule.style.fontFamily = "serif";
            processedRules.add(rule);
            return;
          }
          if (rule.style.fontFamily.includes("mono")) {
            rule.style.fontFamily = "monospace";
            processedRules.add(rule);
            return;
          }
          processedRules.add(rule);
        }
      });

      processedStyleSheets.add(styleSheet);
    });
  }

  fontReplace();

  // Use MutationObserver to react to changes in the DOM
  const observer = new MutationObserver(() => {
    fontReplace();
  });

  observer.observe(document.documentElement, {
    childList: true,
    subtree: true,
  });
})();