HoholDetector

Helps you detect Ukrainian text

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name            HoholDetector
// @name:ru         Обнаружитель мовы
// @namespace       Violentmonkey Scripts
// @match           *://*/*
// @grant           none
// @version         1.0
// @author          -
// @description     Helps you detect Ukrainian text
// @description:ru  Помогает в обнаружении украинского языка в тексте
// @license MIT
// ==/UserScript==

const ukrainianSymbols = /[ґєії]/i;

const replaceMovaString = (s) => {
  if (s.includes("🐷") || !ukrainianSymbols.test(s)) {
    return s;
  }

  return `🐷${s}🐷`;
};

const replaceMovaHTML = (element) => {
  element.childNodes.forEach((node) => replaceMovaHTML(node));
  if (element.nodeType == Node.TEXT_NODE) {
    const newValue = replaceMovaString(element.nodeValue);
    if (element.nodeValue !== newValue) {
      element.nodeValue = newValue;
    }
  }
};

const observer = new MutationObserver(
  (mutationList, observer) => {
    for (const mutation of mutationList) {
      switch (mutation.type) {
        case 'childList':
          mutation.addedNodes.forEach(replaceMovaHTML);
          break;
        case 'attributes':
          break;
        case 'characterData':
          replaceMovaHTML(mutation.target);
          break;
        case 'subtree':
          break;
      }
    }
  }
);

observer.observe(document, {
  childList: true,
  // attributes: true,
  characterData: true,
  subtree: true
});

const onLoad = () => {
  replaceMovaHTML(document.getElementsByTagName('html')[0]);
};

window.addEventListener('load', onLoad, false);