Hackthis.co.uk coding level 2

Calculates and fills in the solution to coding level 2 on hackthis.co.uk

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name        Hackthis.co.uk coding level 2
// @namespace   urn://https://www.georgegillams.co.uk/greasemonkey/hackthis_coding_2
// @include     https://www.hackthis.co.uk/levels/coding/2
// @exclude     none
// @version     3
// @description Calculates and fills in the solution to coding level 2 on hackthis.co.uk
// @description:en Calculates and fills in the solution to coding level 2 on hackthis.co.uk
// @grant    		none
// ==/UserScript==

let answer = 'INCOMPLETE';

function decrypt(n) {
  if (n === ' ') {
    return n;
  }
  return String.fromCharCode(126 + 32 - n);
}

function solveLevel() {
  if (answer !== 'INCOMPLETE') {
    return;
  }
  const allElements = document.getElementsByTagName('textarea');
  for (let i = 0; i < allElements.length; i += 1) {
    const element = allElements[i];
    if (element.style.height === '140px') {
      element.style.backgroundColor = '#44aeff';
      if (answer === 'INCOMPLETE') {
        answer = '';
        const values = element.value.split(',');
        for (let j = 0; j < values.length; j += 1) {
          answer += decrypt(values[j]);
        }
      } else {
        element.value = answer;
      }
    }
  }
}

solveLevel();
setInterval(solveLevel, 500);