-
Notifications
You must be signed in to change notification settings - Fork 12
Added initial code to clear problem difficulties #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
console.log('hard-mode.js Running'); | ||
|
||
const difficulty_conversion = { | ||
'Easy': 'Brutal', | ||
'Medium': 'Excruciating', | ||
'Hard': 'Soul-Crushing', | ||
'Brutal': 'Brutal', // In order to keep it from going to undefined if run too many times | ||
'Excruciating': 'Excruciating', | ||
'Soul-Crushing': 'Soul-Crushing' | ||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we just not change it if it's not in the map? |
||
} | ||
|
||
const problem_difficulty_classes = ["text-olive dark:text-dark-olive", "text-yellow dark:text-dark-yellow", "text-pink dark:text-dark-pink"]; | ||
|
||
let problemClearingInterval = setInterval(clearProblemSetDifficulties, 100); // Needed because we have to wait for leetcode to request problems (nonblockingly) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like a reasonable starting point but I wonder if we could intercept the API data and rewrite the difficulties there... Running a script 10 times a second probably isn't great for perf. |
||
|
||
function clearProblemSetDifficulties() { | ||
console.log("Clearing Difficulties") | ||
let finished = false; | ||
for (const difficulty of problem_difficulty_classes){ | ||
Array.from(document.getElementsByClassName(difficulty)).forEach( | ||
(elem)=> { | ||
elem.setAttribute("class", "text-olive dark:text-dark-olive"); | ||
elem.innerText = difficulty_conversion[elem.innerText]; | ||
finished = true; | ||
}); | ||
} | ||
|
||
// if (finished) { // We need it to run multiple times cause changes don't stick | ||
// console.log("Cleared") | ||
// clearInterval(problemClearingInterval); | ||
// } | ||
} | ||
|
||
|
||
function clearIndividualProblemDifficulty() { | ||
let difficulty_elem = document.getElementsByClassName("dark:text-difficulty-hard")[0] || document.getElementsByClassName("dark:text-difficulty-easy")[0] || document.getElementsByClassName("dark:text-difficulty-medium")[0]; | ||
VolodymyrSemenov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
difficulty_elem.innerText = difficulty_conversion[difficulty_elem.innerText]; | ||
difficulty_elem.setAttribute("class", "relative inline-flex items-center justify-center text-caption px-2 py-1 gap-1 rounded-full bg-fill-secondary text-difficulty-easy dark:text-difficulty-easy"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm assuming you just want to modify one of the classes, not all of them. If so, try this API instead: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList |
||
} |
Uh oh!
There was an error while loading. Please reload this page.