CodeHS Brython Graphics Patcher

Patches CodeHS Brython runtimes.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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         CodeHS Brython Graphics Patcher
// @namespace    https://thetridentguy.com/
// @version      0.1.0
// @description  Patches CodeHS Brython runtimes.
// @author       TheTridentGuy
// @match        https://*.codehs.me/__codehs__/index.html*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=codehs.com
// @license      MIT
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    const patch = `
import traceback
def _patch_handler(handler):
    def patched_handler(callback):
        def patched_callback(*args, **kwargs):
            try: 
                callback(*args, **kwargs)
            except:
                print()
                print(traceback.format_exc())
        handler(patched_callback)
    return patched_handler

add_mouse_click_handler = _patch_handler(add_mouse_click_handler)
add_key_down_handler = _patch_handler(add_key_down_handler)
add_key_up_handler = _patch_handler(add_key_up_handler)\n`
    let old_append_child = HTMLBodyElement.prototype.appendChild;
    HTMLBodyElement.prototype.appendChild = function(element){
        if(element.tagName == "SCRIPT"){
            let original_code = element.innerHTML.split("\n")
            element.innerHTML = original_code.slice(0,2).join("\n") + patch + original_code.slice(2).join("\n");
        }
        return old_append_child.call(this, element);
    };
})();