diff --git a/workspaces/chrome-extension-hello-world/hard-mode.js b/workspaces/chrome-extension-hello-world/hard-mode.js new file mode 100644 index 00000000..155a6253 --- /dev/null +++ b/workspaces/chrome-extension-hello-world/hard-mode.js @@ -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' +} + +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) + +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"); +} diff --git a/workspaces/chrome-extension-hello-world/manifest.json b/workspaces/chrome-extension-hello-world/manifest.json index db4cba18..6e014b5f 100644 --- a/workspaces/chrome-extension-hello-world/manifest.json +++ b/workspaces/chrome-extension-hello-world/manifest.json @@ -6,5 +6,11 @@ "action": { "default_popup": "hello.html", "default_icon": "hello_extensions.png" - } + }, + "content_scripts": [ + { + "matches": ["https://leetcode.com/*"], + "js": ["hard-mode.js"] + } + ] }