Skip to content

Commit c3da6b8

Browse files
committed
add toggle show difficulty button
1 parent ee36408 commit c3da6b8

File tree

5 files changed

+31
-2
lines changed

5 files changed

+31
-2
lines changed

src/background/background.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ chrome.runtime.onInstalled.addListener(() => {
1515
chrome.storage.local.set({ fontSize: 14 });
1616
chrome.storage.local.set({ showCompanyTags: true });
1717
chrome.storage.local.set({ showExamples: true });
18+
chrome.storage.local.set({ showDifficulty: true });
1819
});
1920

2021
chrome.runtime.onMessage.addListener(

src/content-script/update-description.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ function showExamples() {
2222
});
2323
}
2424

25+
function showDifficulty() {
26+
chrome.storage.local.get(['showDifficulty'], (result) => {
27+
let showDifficulty = result.showDifficulty;
28+
let difficultyContainer = document.querySelectorAll('div.bg-olive')[0];
29+
difficultyContainer.style.display = showDifficulty ? 'block' : 'none';
30+
});
31+
}
32+
2533
function showCompanyTags(problemTitle: string) {
2634
chrome.storage.local.get(['showCompanyTags'], (result) => {
2735
let showCompanyTags = result.showCompanyTags;
@@ -130,5 +138,6 @@ chrome.runtime.onMessage.addListener((request) => {
130138
if (request.action === 'updateDescription') {
131139
showExamples();
132140
showCompanyTags(request.title.split('-')[0].trim());
141+
showDifficulty();
133142
}
134143
});

src/popup/popup.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,6 @@ async function main(): Promise<void> {
219219
}
220220
});
221221

222-
223-
224222
// get language from storage and set the classname of the code block to it
225223
chrome.storage.local.get('language', function (data) {
226224
fixCodeResponse!.classList.add('language-' + data.language);

src/popup/settings.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ <h2 class="title">Settings</h2>
2828
<button id="show-examples-btn" class="material-button settings-btn">
2929
<span id="show-examples-icon"> </span> Show Examples
3030
</button>
31+
<button id="show-difficulty-btn" class="material-button settings-btn">
32+
<span id="show-difficulty-icon"> </span> Show Difficulty
33+
</button>
3134
</body>
3235

3336
</html>

src/popup/settings.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ document.addEventListener('DOMContentLoaded', (event) => {
1111
let showExamplesIcon = document.getElementById('show-examples-icon');
1212
showExamplesIcon!.textContent = result.showExamples ? '✅' : '❌';
1313
});
14+
15+
chrome.storage.local.get(['showDifficulty'], (result) => {
16+
let showDifficultyIcon = document.getElementById('show-difficulty-icon');
17+
showDifficultyIcon!.textContent = result.showDifficulty ? '✅' : '❌';
18+
});
1419
});
1520

1621
// Get font fize and check if it is already set in local storage
@@ -54,6 +59,19 @@ document.getElementById('show-examples-btn')!.addEventListener('click', function
5459
});
5560
});
5661

62+
document.getElementById('show-difficulty-btn')!.addEventListener('click', function () {
63+
chrome.storage.local.get(['showDifficulty'], (result) => {
64+
const showDifficulty = !result.showDifficulty;
65+
chrome.storage.local.set({ showDifficulty: showDifficulty }, () => {
66+
document.getElementById('show-difficulty-icon')!.textContent = showDifficulty ? '✅' : '❌';
67+
})
68+
// Manually trigger the update description after toggling
69+
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
70+
chrome.tabs.sendMessage(tabs[0].id!, { action: 'updateDescription', title: tabs[0].title || 'title' });
71+
});
72+
});
73+
});
74+
5775
function sendMessageToActiveTab(message: object): void {
5876
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
5977
chrome.tabs.sendMessage(tabs[0].id!, message);

0 commit comments

Comments
 (0)