Skip to content

Commit dd363e3

Browse files
committed
add show ratings button
1 parent 5e4d933 commit dd363e3

File tree

3 files changed

+77
-49
lines changed

3 files changed

+77
-49
lines changed

src/content-script/update-description-tab.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ function showRating(problemTitle: string) {
5151
chrome.storage.local.get(['leetcodeProblems'], (result) => {
5252
const problem = result.leetcodeProblems.questions.find((problem: problem) => problem.title === problemTitle);
5353

54-
let ratingElement = document.getElementById('ratingElement');
54+
let ratingElement = document.getElementById('rating');
5555

5656
if (ratingElement) {
5757
// update the existing rating element
5858
ratingElement.textContent = problem.rating;
5959
} else {
6060
// create a new rating element
6161
ratingElement = document.createElement('div');
62-
ratingElement.id = 'ratingElement';
62+
ratingElement.id = 'rating';
6363
ratingElement.textContent = problem.rating;
6464
ratingElement.style.fontSize = '12px';
6565
ratingElement.style.color = 'lightcyan';
@@ -72,6 +72,13 @@ function showRating(problemTitle: string) {
7272
}
7373
});
7474
}
75+
else {
76+
const ratingElement = document.getElementById('rating');
77+
if (ratingElement) {
78+
ratingElement.style.display = 'none';
79+
ratingElement.remove();
80+
}
81+
}
7582
});
7683
}
7784

src/popup/settings.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ <h2 class="title">Settings</h2>
3131
<button id="show-difficulty-btn" class="material-button settings-btn">
3232
<span id="show-difficulty-icon"> </span> Show Difficulty
3333
</button>
34+
<button id="show-rating-btn" class="material-button settings-btn">
35+
<span id="show-rating-icon"> </span> Show Rating
36+
</button>
3437
</body>
3538

3639
</html>

src/popup/settings.ts

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -26,63 +26,81 @@ document.addEventListener('DOMContentLoaded', () => {
2626
const showDifficultyIcon = document.getElementById('show-difficulty-icon');
2727
if (showDifficultyIcon) showDifficultyIcon.textContent = result.showDifficulty ? '✅' : '❌';
2828
});
29-
});
29+
chrome.storage.local.get(['showRating'], (result) => {
30+
const showRatingIcon = document.getElementById('show-rating-icon');
31+
if (showRatingIcon) showRatingIcon.textContent = result.showRating ? '✅' : '❌';
32+
});
3033

31-
// Get font fize and check if it is already set in local storage
32-
const fontSizeSelect = document.getElementById('font-size-select') as HTMLSelectElement;
33-
chrome.storage.local.get('fontSize', function (data) {
34-
if (data.fontSize) {
35-
fontSizeSelect.value = data.fontSize;
36-
document.documentElement.style.setProperty('--dynamic-font-size', `${data.fontSize}px`);
37-
}
38-
});
39-
fontSizeSelect.onchange = function (event: Event) {
40-
const selectedFontSize = (event.target as HTMLInputElement).value;
41-
chrome.storage.local.set({ fontSize: selectedFontSize });
42-
document.documentElement.style.setProperty('--dynamic-font-size', `${selectedFontSize}px`);
43-
};
34+
// Get font fize and check if it is already set in local storage
35+
const fontSizeSelect = document.getElementById('font-size-select') as HTMLSelectElement;
36+
chrome.storage.local.get('fontSize', function (data) {
37+
if (data.fontSize) {
38+
fontSizeSelect.value = data.fontSize;
39+
document.documentElement.style.setProperty('--dynamic-font-size', `${data.fontSize}px`);
40+
}
41+
});
42+
fontSizeSelect.onchange = function (event: Event) {
43+
const selectedFontSize = (event.target as HTMLInputElement).value;
44+
chrome.storage.local.set({ fontSize: selectedFontSize });
45+
document.documentElement.style.setProperty('--dynamic-font-size', `${selectedFontSize}px`);
46+
};
4447

45-
const showCompanyTagsBtn = document.getElementById('show-company-tags-btn');
46-
showCompanyTagsBtn && showCompanyTagsBtn.addEventListener('click', function () {
47-
chrome.storage.local.get(['showCompanyTags'], (result) => {
48-
const showCompanyTags = !result.showCompanyTags;
49-
chrome.storage.local.set({ showCompanyTags: showCompanyTags }, () => {
50-
const showCompanyTagsIcon = document.getElementById('show-company-tags-icon');
51-
showCompanyTagsIcon && (showCompanyTagsIcon.textContent = showCompanyTags ? '✅' : '❌');
48+
const showCompanyTagsBtn = document.getElementById('show-company-tags-btn');
49+
showCompanyTagsBtn && showCompanyTagsBtn.addEventListener('click', function () {
50+
chrome.storage.local.get(['showCompanyTags'], (result) => {
51+
const showCompanyTags = !result.showCompanyTags;
52+
chrome.storage.local.set({ showCompanyTags: showCompanyTags }, () => {
53+
const showCompanyTagsIcon = document.getElementById('show-company-tags-icon');
54+
showCompanyTagsIcon && (showCompanyTagsIcon.textContent = showCompanyTags ? '✅' : '❌');
55+
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
56+
chrome.tabs.sendMessage(tabs[0].id || 0, { action: 'updateDescription', title: tabs[0].title || 'title' });
57+
});
58+
});
59+
});
60+
});
61+
62+
let showExamplesBtn = document.getElementById('show-examples-btn');
63+
showExamplesBtn && showExamplesBtn.addEventListener('click', function () {
64+
chrome.storage.local.get(['showExamples'], (result) => {
65+
const showExamples = !result.showExamples;
66+
chrome.storage.local.set({ showExamples: showExamples }, () => {
67+
const showExamplesIcon = document.getElementById('show-examples-icon');
68+
showExamplesIcon && (showExamplesIcon.textContent = showExamples ? '✅' : '❌');
69+
});
70+
// Manually trigger the update description after toggling
5271
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
5372
chrome.tabs.sendMessage(tabs[0].id || 0, { action: 'updateDescription', title: tabs[0].title || 'title' });
5473
});
5574
});
5675
});
57-
});
5876

59-
let showExamplesBtn = document.getElementById('show-examples-btn');
60-
showExamplesBtn && showExamplesBtn.addEventListener('click', function () {
61-
chrome.storage.local.get(['showExamples'], (result) => {
62-
const showExamples = !result.showExamples;
63-
chrome.storage.local.set({ showExamples: showExamples }, () => {
64-
const showExamplesIcon = document.getElementById('show-examples-icon');
65-
showExamplesIcon && (showExamplesIcon.textContent = showExamples ? '✅' : '❌');
66-
});
67-
// Manually trigger the update description after toggling
68-
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
69-
chrome.tabs.sendMessage(tabs[0].id || 0, { action: 'updateDescription', title: tabs[0].title || 'title' });
77+
const showDifficultyBtn = document.getElementById('show-difficulty-btn');
78+
showDifficultyBtn && showDifficultyBtn.addEventListener('click', function () {
79+
chrome.storage.local.get(['showDifficulty'], (result) => {
80+
const showDifficulty = !result.showDifficulty;
81+
chrome.storage.local.set({ showDifficulty: showDifficulty }, () => {
82+
const showDifficultyIcon = document.getElementById('show-difficulty-icon');
83+
if (showDifficultyIcon) showDifficultyIcon.textContent = showDifficulty ? '✅' : '❌';
84+
});
85+
// Manually trigger the update description after toggling
86+
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
87+
chrome.tabs.sendMessage(tabs[0].id || 0, { action: 'updateDescription', title: tabs[0].title || 'title' });
88+
});
7089
});
7190
});
72-
});
7391

74-
const showDifficultyBtn = document.getElementById('show-difficulty-btn');
75-
showDifficultyBtn && showDifficultyBtn.addEventListener('click', function () {
76-
chrome.storage.local.get(['showDifficulty'], (result) => {
77-
const showDifficulty = !result.showDifficulty;
78-
chrome.storage.local.set({ showDifficulty: showDifficulty }, () => {
79-
const showDifficultyIcon = document.getElementById('show-difficulty-icon');
80-
if (showDifficultyIcon) showDifficultyIcon.textContent = showDifficulty ? '✅' : '❌';
81-
});
82-
// Manually trigger the update description after toggling
83-
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
84-
chrome.tabs.sendMessage(tabs[0].id || 0, { action: 'updateDescription', title: tabs[0].title || 'title' });
92+
const showRatingBtn = document.getElementById('show-rating-btn');
93+
showRatingBtn && showRatingBtn.addEventListener('click', function () {
94+
chrome.storage.local.get(['showRating'], (result) => {
95+
const showRating = !result.showRating;
96+
chrome.storage.local.set({ showRating: showRating }, () => {
97+
const showRatingIcon = document.getElementById('show-rating-icon');
98+
if (showRatingIcon) showRatingIcon.textContent = showRating ? '✅' : '❌';
99+
});
100+
// Manually trigger the update description after toggling
101+
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
102+
chrome.tabs.sendMessage(tabs[0].id || 0, { action: 'updateDescription', title: tabs[0].title || 'title' });
103+
});
85104
});
86105
});
87-
});
88-
106+
});

0 commit comments

Comments
 (0)