Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 513ad6d

Browse files
Update code.js
1 parent 9b96c0b commit 513ad6d

File tree

1 file changed

+105
-52
lines changed

1 file changed

+105
-52
lines changed

code.js

Lines changed: 105 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name Quill.org Cheat
33
// @namespace http://tampermonkey.net/
4-
// @version 0.1
4+
// @version 0.2
55
// @description Get answers for Quill.org
66
// @author Caden Finkelstein
77
// @match https://www.quill.org/connect/*
@@ -11,68 +11,121 @@
1111
(function () {
1212
"use strict";
1313

14-
document.addEventListener("DOMContentLoaded", function() {
15-
const quillButton = document.querySelector(".regen-button");
16-
if (quillButton) {
17-
quillButton.addEventListener("click", start);
14+
// Function to clear existing content
15+
function clearContent() {
16+
const contentDiv = document.querySelector(".student-container");
17+
if (contentDiv) {
18+
contentDiv.innerHTML = ""; // Clear the content
1819
} else {
19-
console.error("Quill button not found.");
20+
console.error("Content container not found.");
2021
}
21-
});
22+
}
2223

24+
// Function to get URL parameters
2325
function getUrlParams(url) {
24-
const params = new URLSearchParams(url);
25-
const studentId = params.get("student");
26-
return { studentId };
26+
const match = url.match(/\/lesson\/([^?#/]+)/);
27+
if (match) {
28+
const id = match[1];
29+
return { id };
2730
}
31+
return { id: null }; // Return null if ID is not found
32+
}
33+
34+
// Function to display questions and answers
35+
function displayQuestionsAndAnswers(questions, responses) {
36+
const contentDiv = document.querySelector(".student-container");
37+
if (contentDiv) {
38+
questions.forEach((question, index) => {
39+
const questionDiv = document.createElement("div");
40+
questionDiv.textContent = `Question: ${question.key}`;
41+
contentDiv.appendChild(questionDiv);
2842

29-
function displayQuestionsAndAnswers(questionSet) {
30-
const contentDiv = document.querySelector(".student-container");
31-
const question = questionSet.question;
32-
const attempts = questionSet.attempts;
33-
const questionDiv = document.createElement("div");
34-
questionDiv.textContent = `Question: ${question}`;
35-
contentDiv.appendChild(questionDiv);
36-
const regenButton = document.createElement("button");
37-
regenButton.className = "regen-button";
38-
contentDiv.appendChild(regenButton);
39-
const separator = document.createElement("hr");
40-
contentDiv.appendChild(separator);
43+
const responseDiv = document.createElement("div");
44+
responseDiv.textContent = `Response: ${responses[index]}`;
45+
contentDiv.appendChild(responseDiv);
46+
47+
const separator = document.createElement("hr");
48+
contentDiv.appendChild(separator);
49+
});
50+
} else {
51+
console.error("Content container not found.");
52+
}
53+
}
54+
55+
// Function to fetch responses for questions
56+
async function fetchResponses(questions) {
57+
const responses = [];
58+
for (const question of questions) {
59+
const questionId = question.key;
60+
try {
61+
const responseUrl = `https://cms.quill.org/questions/${questionId}/responses`;
62+
const response = await fetch(responseUrl);
63+
const responseData = await response.json();
64+
65+
// Check if responseData is an array of objects
66+
if (Array.isArray(responseData) && responseData.length > 0 && typeof responseData[0] === 'object') {
67+
// Extract relevant information from each object and concatenate into a string
68+
const responseText = responseData.map(obj => obj.text).join(', ');
69+
responses.push(responseText);
70+
} else {
71+
console.error(`Invalid response data format for question ${questionId}`);
72+
responses.push("Error fetching response");
73+
}
74+
} catch (error) {
75+
console.error(`Error fetching responses for question ${questionId}:`, error);
76+
responses.push("Error fetching response");
77+
}
4178
}
79+
return responses;
80+
}
4281

43-
function start() {
82+
// Function to start the script
83+
async function start() {
84+
clearContent(); // Clear existing content
4485
const currentUrl = window.location.href;
45-
const { studentId } = getUrlParams(currentUrl);
46-
const jsonUrl = `https://www.quill.org/api/v1/active_activity_sessions/${studentId}.json`;
47-
48-
fetch(jsonUrl)
49-
.then((response) => response.json())
50-
.then((jsonData) => {
51-
const questionId = jsonData.currentQuestion.question;
52-
const apiUrl = `https://cms.quill.org/questions/${questionId}/responses`;
53-
54-
fetch(apiUrl)
55-
.then((response) => response.json())
56-
.then((data) => {
57-
console.log("Response:", data);
58-
data.forEach(answer => {
59-
const contentDiv = document.querySelector(".student-container");
60-
const answerDiv = document.createElement("div");
61-
answerDiv.textContent = `Answer: ${answer.text}`;
62-
contentDiv.appendChild(answerDiv);
63-
});
64-
})
65-
.catch((error) => {
66-
console.error("Error fetching data:", error);
67-
});
86+
const { id } = getUrlParams(currentUrl);
87+
const jsonUrl = `https://www.quill.org/api/v1/lessons/${id}.json`;
6888

69-
const questionSet = jsonData.currentQuestion;
70-
displayQuestionsAndAnswers(questionSet);
71-
})
72-
.catch((error) => {
89+
try {
90+
const response = await fetch(jsonUrl);
91+
const jsonData = await response.json();
92+
const questions = jsonData.questions;
93+
94+
const responses = await fetchResponses(questions);
95+
displayQuestionsAndAnswers(questions, responses);
96+
} catch (error) {
7397
console.error("Error fetching JSON data:", error);
98+
}
99+
}
100+
101+
// Function to initialize the script
102+
function initialize() {
103+
const quillButton = document.querySelector(".quill-button");
104+
if (quillButton) {
105+
quillButton.addEventListener("click", start);
106+
} else {
107+
console.error("Quill button not found, waiting for it to appear.");
108+
waitForQuillButton();
109+
}
110+
}
111+
112+
// Function to wait for the Quill button
113+
function waitForQuillButton() {
114+
const observer = new MutationObserver((mutations) => {
115+
mutations.forEach((mutation) => {
116+
const quillButton = document.querySelector(".quill-button");
117+
if (quillButton) {
118+
observer.disconnect();
119+
quillButton.addEventListener("click", start);
120+
console.log("Quill button found and event listener attached.");
121+
}
122+
});
74123
});
124+
125+
observer.observe(document.body, { childList: true, subtree: true });
75126
}
76127

77-
start();
78-
})();
128+
// Call the initialize function
129+
initialize();
130+
131+
})();

0 commit comments

Comments
 (0)