Better CodeHS

Enable autocomplete, set Vim mode, and apply Gruvbox theme the CodeHS editor + Keybindings for submit and check code.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Better CodeHS
// @namespace    http://tampermonkey.net/
// @version      1.1
// @license MIT
// @description  Enable autocomplete, set Vim mode, and apply Gruvbox theme the CodeHS editor + Keybindings for submit and check code.
// @author       Qyoh
// @icon         https://static1.codehs.com/img/logo.png
// @match        https://codehs.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    // Function to simulate a button click using the class or ID
    function clickButton(buttonSelector) {
        const button = document.querySelector(buttonSelector);
        if (button) {
            button.click();
        } else {
            console.error(`Button with selector "${buttonSelector}" not found.`);
        }
    }

    function switchToTestCasesTab() {
        const testCasesTab = document.querySelector('.r.c');  // Replace with actual selector
        if (testCasesTab) {
            testCasesTab.click();
        } else {
            console.error('Test Cases tab not found.');
        }
    }

    // Add event listener for keydown events
    document.addEventListener('keydown', (event) => {
        // Custom keybind for "Submit and Continue" (e.g., Ctrl + Enter)
        if (event.ctrlKey && event.key === 'Enter') {
            event.preventDefault();
            // Target the "Submit and Continue" button by class (adjust if necessary)
            clickButton('.StyledButtonKind-sc-1vhfpnt-0.fSozsy.sc-bkbkJK.eraKfR');
            console.log('"Submit and Continue" triggered.');
        }

        // Custom keybind for "Check Code" (e.g., Alt + C)
        if (event.altKey && event.key === 'c') {
            event.preventDefault();
            // Target the "Check Code" button by ID and class
            switchToTestCasesTab();
            clickButton('#grading-unit-test-run.btn.btn-main.spinner');
            console.log('"Check Code" triggered.');
        }
    });

    console.log('CodeHS keybinds loaded.');

    // Wait for the Ace Editor to be available
    function waitForAceEditor() {
        const editorElement = document.getElementById("ace-editor"); // Change ID if necessary
        if (editorElement) {
            initializeAceEditor();
        } else {
            setTimeout(waitForAceEditor, 500); // Retry after 500ms
        }
    }

    // Initialize Ace Editor with custom settings
    function initializeAceEditor() {
        const editor = ace.edit("ace-editor");
        ace.config.set("basePath", "https://cdnjs.cloudflare.com/ajax/libs/ace/1.9.6/");

        // Load language tools for autocomplete
        ace.config.loadModule("ace/ext/language_tools", function(languageTools) {
            editor.setOptions({
                enableBasicAutocompletion: true,
                enableLiveAutocompletion: true,
                enableSnippets: true
            });
        });

        // Set Vim keyboard mode
        editor.setKeyboardHandler("ace/keyboard/vim");

        // Set theme to Gruvbox
        editor.setTheme("ace/theme/gruvbox");

        console.log("Vim mode, Gruvbox theme, and autocomplete enabled.");
    }

    // Start the script
    waitForAceEditor();
})();