Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

VolodymyrSemenov
Copy link
Contributor

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.

@VolodymyrSemenov
Copy link
Contributor Author

I also couldn't figure out how to run prettier(or the js equivalent) on the file.

@VolodymyrSemenov VolodymyrSemenov self-assigned this Aug 25, 2024
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");
Copy link
Contributor

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)
Copy link
Contributor

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.

Comment on lines +7 to +9
'Brutal': 'Brutal', // In order to keep it from going to undefined if run too many times
'Excruciating': 'Excruciating',
'Soul-Crushing': 'Soul-Crushing'
Copy link
Contributor

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?

Copy link
Contributor

@elimanzo elimanzo left a 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 🔥 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants