diff --git a/html/popup.html b/html/popup.html index 016850cc..349f04e6 100644 --- a/html/popup.html +++ b/html/popup.html @@ -271,6 +271,14 @@

Better Canvas

Color coded tab icons +
+ + +
+
+
+
Quiz Strikethrough +
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, } }; diff --git a/js/content.js b/js/content.js index c2301d3e..5dfb12e9 100644 --- a/js/content.js +++ b/js/content.js @@ -224,6 +224,7 @@ function startExtension() { loadCustomFont(); applyAestheticChanges(); changeFavicon(); + initQuizStrikethrough(); updateReminders(); //getClassAverages(); setTimeout(() => runDarkModeFixer(false), 800); @@ -266,6 +267,8 @@ function applyOptionsChanges(changes) { case ("dashboard_notes"): loadDashboardNotes(); break; + case ("quiz_strikethrough"): + initQuizStrikethrough() case ("dashboard_grades"): case ("grade_hover"): if (!grades) getGrades(); @@ -1845,6 +1848,79 @@ 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() { + + 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 }; + + 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 */ @@ -2224,4 +2300,4 @@ function logError(e) { const CSRFtoken = function () { return decodeURIComponent((document.cookie.match('(^|;) *_csrf_token=([^;]*)') || '')[2]) -} \ No newline at end of file +} diff --git a/js/popup.js b/js/popup.js index 650d139b..694285b9 100644 --- a/js/popup.js +++ b/js/popup.js @@ -1,4 +1,4 @@ -const syncedSwitches = ['remind', '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 = ['remind', '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,