Skip to content

Instantly share code, notes, and snippets.

@Pierce01
Last active May 3, 2024 20:20
Show Gist options
  • Save Pierce01/f527a650ff81b94d10a1abd92f20f908 to your computer and use it in GitHub Desktop.
Save Pierce01/f527a650ff81b94d10a1abd92f20f908 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name CodeHS Solution Script
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Adds in a button that does the work for you
// @author Pierce
// @match https://codehs.com/editor/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
const url = window.location.href;
const solutionId = url.split("/")[4];
const panel = document.getElementById("sidebar-files-tab");
const button = document.createElement("button");
button.className = "btn btn-cs btn-main";
button.style = "width:100%;font-size:14pxpadding-top: 3px;padding-bottom: 3px;margin-bottom: 5px;font-size: 12px;font-family: 'Proxima Nova',proxima-nova,sans-serif;";
button.onclick = function() {
const files = Array(document.getElementsByClassName("file"))[0];
for (let file = 0; file < files.length; file++) {
const xhr = new XMLHttpRequest();
xhr.open('GET', `https://codehs.com/editor/${solutionId}/solution/${files[file].innerText}`);
xhr.send();
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (document.getElementById(files[file].innerText)) {
document.getElementById(files[file].innerText).remove();
}
let area = document.createElement("div");
area.innerHTML = `<div>${files[file].innerText}:</div>`;
let input = document.createElement("textarea");
input.id = files[file].innerText;
input.value = this.responseText;
area.appendChild(input);
panel.appendChild(area);
}
};
}
}
const text = document.createTextNode("Get supported solutions");
button.appendChild(text);
panel.appendChild(button);
})();
@Pierce01
Copy link
Author

this script is meant for people who already know what they are doing and want to quickly get through the module to work on other things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment