-
Notifications
You must be signed in to change notification settings - Fork 12
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
Added initial code to clear problem difficulties #383
base: main
Are you sure you want to change the base?
Conversation
I also couldn't figure out how to run prettier(or the js equivalent) on the file. |
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]; | ||
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 comment
The 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
|
||
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 comment
The 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.
'Brutal': 'Brutal', // In order to keep it from going to undefined if run too many times | ||
'Excruciating': 'Excruciating', | ||
'Soul-Crushing': 'Soul-Crushing' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really cool, good job @VolodymyrSemenov 🔥 !
Created 2 functions to clear problem difficulties on problemset page and individual problem pages.
Issues:
clearProblemSetDifficulties needs to wait for the problems to load. Currently using polling, but maybe a better way?
clearProblemSetDifficulties needs to run several times to work. I added code to let it only run once, but leetcode rewrites the problems so the function has to run multiple times.
Code to run clearIndividualProblemDifficulty isn't setup.