Default fonts

Replace web fonts with browser's default fonts

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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,
  });
})();