CodehsHack

Auto get HTML/styles for codeHS assignments

As of 20.12.2022. See ბოლო ვერსია.

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         CodehsHack
// @namespace    https://greatest.deepsurf.us/users/783447
// @version      1.0
// @description  Auto get HTML/styles for codeHS assignments
// @author       You
// @match        https://codehs.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=codehs.com
// @grant        none
// ==/UserScript==

(function() {

//Tedious
if(window.location.pathname.substring(0, 9) == "/student/") {
var itemID = document.getElementsByClassName('banner alert-warning center')[0].children[1].getAttribute('data-item-id')

window.open("https://codehs.com/editor/"+itemID+"/solution/index.html");
window.open("https://codehs.com/editor/"+itemID+"/solution/style.css");
//window.open("https://codehs.com/editor/"+itemID+"/solution/jobinfo.html");
}
else if(window.location.pathname.substring(0, 8) == "/editor/") {




setInterval(function(){
        if (document.getElementsByTagName('html')[0].innerHTML.indexOf('<!--') !== -1) {
            var scriptStart = document.getElementsByTagName('html')[0].innerHTML.indexOf('<noscript>');
            var scriptEnd = document.getElementsByTagName('html')[0].innerHTML.indexOf('</script>');
            var subScript = document.getElementsByTagName('html')[0].innerHTML.slice(scriptStart, scriptEnd+9);
            document.getElementsByTagName('html')[0].innerHTML = document.getElementsByTagName('html')[0].innerHTML.replace(subScript, '')

            var titleStart = document.getElementsByTagName('html')[0].innerHTML.indexOf('&lt;');
            var titleEnd = document.getElementsByTagName('html')[0].innerHTML.indexOf('&gt;');
            var titleSlice = document.getElementsByTagName('html')[0].innerHTML.slice(titleStart, titleEnd+4);
            document.getElementsByTagName('html')[0].innerHTML = document.getElementsByTagName('html')[0].innerHTML.replace(titleSlice, '')


            var badStart = document.getElementsByTagName('html')[0].innerHTML.indexOf('<!--');
            var badEnd = document.getElementsByTagName('html')[0].innerHTML.indexOf('-->');
            var badSub = document.getElementsByTagName('html')[0].innerHTML.slice(badStart, badEnd+3);
            var newHTML = document.getElementsByTagName('html')[0].innerHTML.replace(badSub, '');
            document.getElementsByTagName('html')[0].innerHTML = newHTML

            badStart = newHTML.indexOf('<!--', '-->')
            badEnd = newHTML.indexOf('-->');
            badSub = newHTML.slice(badStart, badEnd+3);

            if (document.getElementsByTagName('html')[0].innerHTML.indexOf('<!--') == -1) {
                console.log(newHTML)
                document.getElementsByTagName('body')[0].style.color = 'white'
                document.getElementsByTagName('body')[0].style.backgroundImage = "url('https://wallpaperaccess.com/full/1129018.jpg')"
                document.getElementsByTagName('body')[0].textContent = ''

                const newPre = document.createElement('pre')
                newPre.id = "preId"
                newPre.textContent = newHTML
                document.getElementsByTagName('body')[0].appendChild(newPre);

            }
        }
}, 1);
}
})();