From 75277eb83007aeee4270a81d9d4ddd070c0f4d9b Mon Sep 17 00:00:00 2001 From: Aiden Johnson Date: Thu, 10 Oct 2024 00:22:51 -0500 Subject: [PATCH 1/3] Adds Quiz Strikethrough Option - For PR --- html/popup.html | 8 ++++++ js/content.js | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ js/popup.js | 3 +- 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/html/popup.html b/html/popup.html index 6c53823b..ef4dac32 100644 --- a/html/popup.html +++ b/html/popup.html @@ -244,6 +244,14 @@

Better Canvas

Color coded tab icons +
+ + +
+
+
+
Quiz Strikethrough +
diff --git a/js/content.js b/js/content.js index 2075f99c..981e3587 100644 --- a/js/content.js +++ b/js/content.js @@ -107,6 +107,7 @@ function startExtension() { loadCustomFont(); applyAestheticChanges(); changeFavicon(); + if (options.quiz_strikethrough) initQuizStrikethrough(); //getClassAverages(); setTimeout(() => runDarkModeFixer(false), 800); setTimeout(() => runDarkModeFixer(false), 4500); @@ -148,6 +149,8 @@ function applyOptionsChanges(changes) { case ("dashboard_notes"): loadDashboardNotes(); break; + case ("quiz_strikethrough"): + initQuizStrikethrough() case ("dashboard_grades"): case ("grade_hover"): if (!grades) getGrades(); @@ -1723,6 +1726,77 @@ function setupGPACalc() { } } +/* +Quiz Strikethrough +*/ + +const strikeStyle = + "background-color: transparent; right: 10px; font-size: 30px; position: absolute; text-decoration: none !important; color: red; border: none; z-index: 2"; + +function initQuizStrikethrough() { + // Listen for any answer choices being added after runtime + const bodyElement = document.body; + const config = { childList: true, subtree: true }; + + const callback = (mutationList, observer) => { + for (const mutation of mutationList) { + if (mutation.type === "childList") { + mutation.addedNodes.forEach((node) => { + if (node.nodeName === "DIV") { + if (isValid(node)) { + initChoice(node); + } + } + }); + } + } + }; + + const observer = new MutationObserver(callback); + observer.observe(bodyElement, config); + + const answerDivs = document.querySelectorAll(".answer"); + answerDivs.forEach((element) => { + if (isValid(element)) initChoice(element); + }); +} + + +function initChoice(element) { + const button = document.createElement("button"); + button.setAttribute("type", "button"); // Prevents button from submitting since
is an ancestor + button.id = "strikethrough"; + button.textContent = "-"; + button.style = strikeStyle; + + element.style.display = "flex"; + element.appendChild(button); + + let striked = false; + + button.addEventListener("click", (event) => { + event.stopPropagation(); + event.preventDefault(); + + if (!striked) { + element.style.textDecoration = "line-through"; + element.style.color = "gray"; + } else { + element.style.textDecoration = "initial"; + element.style.color = "initial"; + } + + striked = !striked; + }); +} + +function isValid(element) { + return ( + element.classList.contains("answer") && + element.parentElement.nodeName == "FIELDSET" + ); +} + /* Dashboard notes */ diff --git a/js/popup.js b/js/popup.js index b66a0492..a62ffc0f 100644 --- a/js/popup.js +++ b/js/popup.js @@ -1,4 +1,4 @@ -const syncedSwitches = ['tab_icons', 'hide_feedback', 'dark_mode', 'remlogo', 'full_width', 'auto_dark', 'assignments_due', 'gpa_calc', 'gradient_cards', 'disable_color_overlay', 'dashboard_grades', 'dashboard_notes', 'better_todo', 'condensed_cards']; +const syncedSwitches = ['tab_icons', 'hide_feedback', 'dark_mode', 'remlogo', 'full_width', 'auto_dark', 'assignments_due', 'gpa_calc', 'gradient_cards', 'disable_color_overlay', 'dashboard_grades', 'dashboard_notes', 'better_todo', 'condensed_cards', 'quiz_strikethrough']; const syncedSubOptions = ['todo_colors', 'device_dark', 'relative_dues', 'card_overdues', 'todo_overdues', 'gpa_calc_prepend', 'auto_dark', 'auto_dark_start', 'auto_dark_end', 'num_assignments', 'assignment_date_format', 'todo_hr24', 'grade_hover', 'hide_completed', 'num_todo_items', 'hover_preview']; const localSwitches = []; @@ -35,6 +35,7 @@ const defaultOptions = { "assignments_done": [], "dashboard_grades": false, "assignment_date_format": false, + "quiz_strikethrough": true, "dashboard_notes": false, "dashboard_notes_text": "", "better_todo": false, From e8ce395f6f903b23529260b5f89ac2b9423eef15 Mon Sep 17 00:00:00 2001 From: george <59516750+ksucpea@users.noreply.github.com> Date: Tue, 29 Oct 2024 00:55:25 -0400 Subject: [PATCH 2/3] added url check so it only runs on quiz pages --- js/content.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/js/content.js b/js/content.js index 8d721063..5dfb12e9 100644 --- a/js/content.js +++ b/js/content.js @@ -224,7 +224,7 @@ function startExtension() { loadCustomFont(); applyAestheticChanges(); changeFavicon(); - if (options.quiz_strikethrough) initQuizStrikethrough(); + initQuizStrikethrough(); updateReminders(); //getClassAverages(); setTimeout(() => runDarkModeFixer(false), 800); @@ -1856,6 +1856,8 @@ const strikeStyle = "background-color: transparent; right: 10px; font-size: 30px; position: absolute; text-decoration: none !important; color: red; border: none; z-index: 2"; function initQuizStrikethrough() { + + if (options.quiz_strikethrough !== true || !current_page.includes("quizzes")) return; // Listen for any answer choices being added after runtime const bodyElement = document.body; const config = { childList: true, subtree: true }; @@ -2298,4 +2300,4 @@ function logError(e) { const CSRFtoken = function () { return decodeURIComponent((document.cookie.match('(^|;) *_csrf_token=([^;]*)') || '')[2]) -} \ No newline at end of file +} From 7d996f48508acfc112da818e9ebbb5125dbf53c7 Mon Sep 17 00:00:00 2001 From: george <59516750+ksucpea@users.noreply.github.com> Date: Tue, 29 Oct 2024 00:59:01 -0400 Subject: [PATCH 3/3] set default value for quiz_strikethrough --- js/background.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/background.js b/js/background.js index 7ab79062..68244042 100644 --- a/js/background.js +++ b/js/background.js @@ -89,6 +89,7 @@ chrome.runtime.onInstalled.addListener(function () { "new_browser": null, "gpa_calc_cumulative": false, "gpa_calc_weighted": true, + "quiz_strikethrough": false, } };