No Comic

Removes all occurrences of Comic Sans from websites.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         No Comic
// @description  Removes all occurrences of Comic Sans from websites.
// @namespace    https://scrumplex.net/
// @version      0.4.2
// @match        *://*/*
// @license      GPL-3.0-or-later
// ==/UserScript==


const MATCH_FONTS = /(['"]?([\w|\s|-]+)['"]?)(?:,\s?)?/gm;
const MATCH_COMIC = /[C|c]omics?[\s|-|_][S|s]ans/gm;

function ensureStyle(elem) {
  if (elem.style.fontFamily !== elem.getAttribute("data-new-font-family")) {
    elem.style.setProperty("font-family", elem.getAttribute("data-new-font-family"), "important");
  }
}
        
function handleNewElem(elem) {
  let fontFamily = getComputedStyle(elem).fontFamily;
  
  let fonts = [];
  let changed = false;

  for (const item of fontFamily.matchAll(MATCH_FONTS)) {
    if (item[2].match(MATCH_COMIC)) {  // font name without quotes
      changed = true;
    } else {
      fonts.push(item[1]);  // font name with quotes
    }
  }

  if (changed) {
    let newFontFamily = fonts.join(", ");
    if (newFontFamily.length === 0)
      newFontFamily = "inherit";

    elem.setAttribute("data-original-font-family", fontFamily);
    elem.setAttribute("data-new-font-family", newFontFamily);
    elem.style.setProperty("font-family", newFontFamily, "important");
  }
}

function handleRecursively(element) {
  if (element != null && element.nodeType === 1) {
    handleNewElem(element);
    element.childNodes.forEach(handleRecursively);
  }
}

function init() {
  handleRecursively(document.body);
}

if (document.readyState == 'complete') {
    init();
} else {
    window.addEventListener("load", init);
}

const config = {childList: true, subtree: true, attributes: true};

const observer = new MutationObserver((mutationsList, observer) => {
  for (const mutation of mutationsList) {
    if (mutation.type === "childList") {
      mutation.addedNodes.forEach(handleRecursively);
    } else if (mutation.type === "attributes") {
      ensureStyle(mutation.target);
    }
  }
});
observer.observe(document, config);