CodeHS Brython Graphics Patcher

Patches CodeHS Brython runtimes.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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);
    };
})();