Skip to content

Commit 140b269

Browse files
committed
v2.0.2 release
1 parent 6139f3c commit 140b269

File tree

8 files changed

+47
-41
lines changed

8 files changed

+47
-41
lines changed

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "leetcode-explained",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "Used to log into GPT-3 and return the token",
55
"main": "background.js",
66
"scripts": {
-1.12 KB
Binary file not shown.

src/content-script/update-description.ts

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

25-
// shows the company tags if the user has enabled it in the settings
2625
function showCompanyTags(problemTitle: string) {
2726
chrome.storage.local.get(['showCompanyTags'], (result) => {
2827
let showCompanyTags = result.showCompanyTags;
2928
let companyTagContainer = document.getElementById('companyTagContainer');
29+
3030
if (!showCompanyTags) {
3131
if (companyTagContainer) {
3232
companyTagContainer.style.display = 'none';
3333
}
3434
return;
3535
}
3636

37-
// if the company tag container already exists then just show it
37+
// Always re-load company tags, regardless if container already exists
3838
if (companyTagContainer) {
39+
// Remove old tags
40+
while (companyTagContainer.firstChild) {
41+
companyTagContainer.firstChild.remove();
42+
}
43+
} else {
44+
companyTagContainer = document.createElement('div');
45+
companyTagContainer.id = 'companyTagContainer';
3946
companyTagContainer.style.display = 'flex';
40-
return;
47+
companyTagContainer.style.flexDirection = 'row';
48+
companyTagContainer.style.marginTop = '10px';
49+
companyTagContainer.style.gap = '5px';
50+
const descriptionBtns = document.querySelectorAll('div.mt-3.flex')[0];
51+
if (descriptionBtns) {
52+
descriptionBtns.parentElement?.appendChild(companyTagContainer);
53+
}
4154
}
42-
companyTagContainer = loadCompanyTags(problemTitle) || null;
55+
56+
// Load new tags
57+
loadCompanyTags(problemTitle, companyTagContainer);
4358
});
4459
}
4560

46-
function loadCompanyTags(problemTitle: string) {
61+
function loadCompanyTags(problemTitle: string, companyTagContainer: HTMLElement) {
4762
// create a new container for buttons
48-
let companyTagContainer = document.createElement('div');
4963
companyTagContainer.id = 'companyTagContainer'; // add an id
5064
companyTagContainer.style.display = 'flex';
5165
companyTagContainer.style.flexDirection = 'row';

src/content-script/update-solutions.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
const VIDEO_ASPECT_RATIO = 56.25; // 16:9 aspect ratio
22

3-
function createStyledElement(tagName, styles = {}) {
3+
function createStyledElement(tagName: string, styles: {}) {
44
const element = document.createElement(tagName);
5-
for (let [key, value] of Object.entries(styles)) {
6-
element.style[key] = value;
5+
for (const [key, value] of Object.entries(styles)) {
6+
if (typeof element.style[key as any] !== 'undefined') {
7+
(element.style as any)[key] = value;
8+
}
79
}
810
return element;
911
}
1012

11-
function createButton(content, className, styles = {}) {
13+
function createButton(content: string, className: string, styles = {}) {
1214
const button = createStyledElement('button', styles);
1315
button.textContent = content;
1416
button.classList.add(className);
1517
return button;
1618
}
1719

18-
function createControlsContainer(channelName) {
20+
function createControlsContainer(channelName: string) {
1921
const controlsContainer = createStyledElement('div', {
2022
display: 'flex',
2123
justifyContent: 'center',
@@ -35,7 +37,7 @@ function createControlsContainer(channelName) {
3537
});
3638
channelElement.classList.add('channel'); // add this line
3739
channelElement.textContent = channelName;
38-
channelElement.fontWeight = 'bold';
40+
channelElement.style.fontWeight = '600';
3941
channelElement.style.color = 'lightcyan';
4042
channelElement.style.textShadow = '0 0 5px #000000';
4143
channelElement.style.fontFamily = 'Menlo, Monaco, Consolas, "Courier New", monospace'
@@ -53,7 +55,7 @@ function createControlsContainer(channelName) {
5355
return { controlsContainer, prevButton, nextButton, toggleButton };
5456
}
5557

56-
function createVideoContainer(videoUrl, channelName) {
58+
function createVideoContainer(videoUrl: string, channelName: string) {
5759
const container = createStyledElement('div', {
5860
position: 'relative',
5961
display: 'flex',
@@ -74,7 +76,7 @@ function createVideoContainer(videoUrl, channelName) {
7476
width: '95%',
7577
height: '95%',
7678
border: '1px solid grey'
77-
});
79+
}) as HTMLIFrameElement;
7880
iframe.classList.add('youtube-video');
7981
iframe.src = videoUrl;
8082
iframe.allowFullscreen = true;
@@ -97,7 +99,7 @@ function addVideo(title: string) {
9799
if (existingContainer) return;
98100

99101
chrome.storage.local.get(['leetcodeProblems'], (result) => {
100-
const problem = result.leetcodeProblems.questions.find((problem) => problem.title === title);
102+
const problem = result.leetcodeProblems.questions.find((problem: { title: string }) => problem.title === title);
101103
if (problem?.videos?.length) {
102104
let currentVideoIndex = 0;
103105
const { container, iframe, prevButton, nextButton, toggleButton } = createVideoContainer(
@@ -109,7 +111,7 @@ function addVideo(title: string) {
109111
prevButton?.addEventListener('click', () => {
110112
currentVideoIndex = (currentVideoIndex - 1 + problem.videos.length) % problem.videos.length;
111113
updateVideo(
112-
container,
114+
container as HTMLDivElement,
113115
problem.videos[currentVideoIndex].embedded_url,
114116
problem.videos[currentVideoIndex].channel,
115117
);
@@ -118,14 +120,14 @@ function addVideo(title: string) {
118120
nextButton?.addEventListener('click', () => {
119121
currentVideoIndex = (currentVideoIndex + 1) % problem.videos.length;
120122
updateVideo(
121-
container,
123+
container as HTMLDivElement,
122124
problem.videos[currentVideoIndex].embedded_url,
123125
problem.videos[currentVideoIndex].channel,
124126
);
125127
});
126128

127129
toggleButton?.addEventListener('click', () => {
128-
const videoContainer = document.querySelector('div.video-container');
130+
const videoContainer = document.querySelector('div.video-container') as HTMLDivElement;
129131
if (videoContainer) {
130132
videoContainer.style.paddingBottom = videoContainer.style.paddingBottom === '0%' ? `${VIDEO_ASPECT_RATIO}% ` : '0%';
131133
if (videoContainer.style.paddingBottom === '0%') {
@@ -151,8 +153,8 @@ function addVideo(title: string) {
151153
});
152154
}
153155

154-
function updateVideo(container, videoUrl, channelName) {
155-
const iframe = container.querySelector('iframe.youtube-video');
156+
function updateVideo(container: HTMLDivElement, videoUrl: string, channelName: string) {
157+
const iframe = container.querySelector('iframe.youtube-video') as HTMLIFrameElement;
156158
const channelElement = container.querySelector('div.channel');
157159

158160
if (iframe) iframe.src = videoUrl;
@@ -172,14 +174,14 @@ chrome.runtime.onMessage.addListener((request) => {
172174
* Prevents the iframe from freezing when it's being resized while the mouse is hovering over it.
173175
*/
174176
window.addEventListener('mousedown', () => {
175-
const iframe = document.querySelector('iframe.youtube-video');
177+
const iframe = document.querySelector('iframe.youtube-video') as HTMLIFrameElement;
176178
if (iframe) {
177179
iframe.style.pointerEvents = 'none';
178180
}
179181
});
180182

181183
window.addEventListener('mouseup', () => {
182-
const iframe = document.querySelector('iframe.youtube-video');
184+
const iframe = document.querySelector('iframe.youtube-video') as HTMLIFrameElement;
183185
if (iframe) {
184186
iframe.style.pointerEvents = 'auto';
185187
}

src/popup/prism.css

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)