HackTheBox Academy - Press Enter To Submit

Automatically submits any dynamic question input by pressing ENTER

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         HackTheBox Academy - Press Enter To Submit
// @namespace    https://greasyfork.org/en/users/1488917-l0wk3y-iaan

// @compatible   Tampermonkey
// @version      1.0
// @description  Automatically submits any dynamic question input by pressing ENTER
// @author       L0WK3Y @infophreak
 
// @match        https://www.hackthebox.com/home*
// @match        https://academy.hackthebox.com/*
// @match        https://www.hackthebox.eu/home*
// @icon         https://www.hackthebox.com/images/favicon.png
 
// @grant        none
// @license MIT
// ==/UserScript==
 
(function () {
    'use strict';
 
    function setupInputListeners() {
        const inputs = document.querySelectorAll('input[id^="answer"]');
 
        inputs.forEach(input => {
            if (input.dataset.enterListenerAttached) return; // prevent duplicates
 
            input.dataset.enterListenerAttached = true;
 
            input.addEventListener('keydown', function (e) {
                if (e.key === 'Enter') {
                    e.preventDefault();
                    const idSuffix = this.id.replace('answer', '');
                    const submitBtn = document.getElementById(`btnAnswer${idSuffix}`);
                    if (submitBtn) submitBtn.click();
                }
            });
        });
    }
 
    // Re-run listener setup as new elements may be loaded dynamically
    const observer = new MutationObserver(() => setupInputListeners());
    observer.observe(document.body, { childList: true, subtree: true });
 
    // Initial setup
    setupInputListeners();
})();