BreakoutEDU answers script

alerts or prints the answers whenever you open a lock.

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 or Violentmonkey 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         BreakoutEDU answers script
// @namespace    http://tampermonkey.net/
// @version      2024-09-23
// @description  alerts or prints the answers whenever you open a lock.
// @author       PowfuArras
// @match        https://student.breakoutedu.com/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=breakoutedu.com
// @grant        none
// @license      GNU AGPLv3
// ==/UserScript==

(function () {
    "use strict";

    const nativeOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function (method, url, ...rest) {
        if (url.includes("student.breakoutedu.com/game-with-locks/play/lock-of-the-day")) {
            this.addEventListener('load', function () {
                const response = this.responseText;
                const data = JSON.parse(response);
                if (data.payload.gameLocks.length !== 1) {
                    console.log("Not supported. Printing answers to console.");
                    console.table(data.payload.gameLocks.map(lock => lock.ans));
                }
                alert(`The answer is:\n\n${data.payload.gameLocks[0].ans.replaceAll(",", ", ")}`);
            });
        }
        return nativeOpen.call(this, method, url, ...rest);
    };
})();