Keep Scrambling

scrambles all the text on a page on a 1 second interval

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         Keep Scrambling
// @namespace    https://greasyfork.org/en/scripts/22128-keep-scrambling
// @version      1.0
// @description  scrambles all the text on a page on a 1 second interval
// @author       abbott
// @match        *://*/*
// ==/UserScript==

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

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

      elements[i].innerHTML = text;
    }
  }, 1000);
};

function scramble(s) { // scrambles middle letters 
  if (s.includes('&nbsp;')) { // ignores nbsp messes up the scramble a bunch
    return s;
  }

  return s.split(' ').map(function(word) {
    if (word.length > 3) {
      var chars = word.split('');

      for (var i = 1; i < chars.length - 1; i++) {
        var j = Math.floor(Math.random() * (i - 1) + 1);
        var temp = chars[i];
        chars[i] = chars[j];
        chars[j] = temp;
      }

      return chars.join('');
    }

    return word;
  }).join(' ');
}