Default fonts

Replace web fonts with browser's default fonts

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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