No Caps

Makes stuff with all caps lowercase

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         No Caps
// @namespace    https://greasyfork.org/en/scripts/22856-no-caps
// @version      1.0
// @description  Makes stuff with all caps lowercase
// @author       abbott
// @match        *://*/*
// ==/UserScript==

window.onload = function() {
  var elements = document.body.getElementsByTagName('*');

  for (var i = 0, element;  element = elements[i]; i++) {
    var text = '';
    element.innerHTML.split(/(<.+?>)/).forEach(function(s) {
      text += s.charAt(0) === '<' ? s : noCaps(s);
    });

    element.innerHTML = text;
  }
};

// enforces proper capitalization, lowercases words with all caps
function noCaps(s) {
  return s.split(' ').map(function(word) {
    var caps = 0;

    for (var i = 0, char; char = word.charAt(i); i++) {
      if (char !== char.toLowerCase()) {
        caps++;
      }
    }

    if (caps === (word.length - nonAlpha(word))) {
      return word.toLowerCase();  
    }
    
    return word;
  }).join(' ');
}

function nonAlpha(s) {
  var count = 0;

  for (var i = 0, char; char = s.charAt(i); i++) {
    count += (char.toUpperCase() === char.toLowerCase()) ? 1 : 0; // non letters would return the same result
  }

  return count;
}