No Caps

Makes stuff with all caps lowercase

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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