Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions workspaces/chrome-extension-hello-world/hard-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
console.log('hard-mode.js Running');

Check failure on line 1 in workspaces/chrome-extension-hello-world/hard-mode.js

View workflow job for this annotation

GitHub Actions / check-formatting

Formatting error

This file does not respect the repository's formatting rules. Run `yarn format` in the repository root to auto-fix it.

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
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?

}

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.


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];
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

}
8 changes: 7 additions & 1 deletion workspaces/chrome-extension-hello-world/manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{

Check failure on line 1 in workspaces/chrome-extension-hello-world/manifest.json

View workflow job for this annotation

GitHub Actions / check-formatting

Formatting error

This file does not respect the repository's formatting rules. Run `yarn format` in the repository root to auto-fix it.
"name": "Hello Extensions",
"description": "Base Level Extension",
"version": "1.0.0",
Expand All @@ -6,5 +6,11 @@
"action": {
"default_popup": "hello.html",
"default_icon": "hello_extensions.png"
}
},
"content_scripts": [
{
"matches": ["https://leetcode.com/*"],
"js": ["hard-mode.js"]
}
]
}
Loading