Skip to content

Commit f70eba5

Browse files
committed
rm ts errors
1 parent c54f00f commit f70eba5

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

src/background/background.ts

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { getChatGPTAccessToken } from './chatgpt/chatgpt.js';
22

3-
chrome.runtime.onMessage.addListener((request: any) => {
4-
if (request.type === 'OPEN_LOGIN_PAGE') {
5-
chrome.tabs.create({ url: 'https://chat.openai.com' });
6-
}
7-
});
8-
93
// Runs when the extension is installed
104
chrome.runtime.onInstalled.addListener(() => {
115
const jsonUrl = chrome.runtime.getURL('src/assets/data/leetcode_solutions.json');
@@ -37,15 +31,35 @@ chrome.runtime.onMessage.addListener(
3731
}
3832
// Append solutions/
3933
const newUrl = url + 'solutions/';
40-
chrome.tabs.update(tabs[0].id, { url: newUrl });
34+
if (tabs.length > 0 && tabs[0].id) {
35+
const tabId = tabs[0].id;
36+
const updateProperties = { url: newUrl };
37+
chrome.tabs.update(tabId, updateProperties);
38+
}
4139
}
4240
});
4341
sendResponse({ result: "Success" });
4442
}
4543
}
4644
);
4745

46+
chrome.runtime.onMessage.addListener((request: any) => {
47+
if (request.type === 'OPEN_LOGIN_PAGE') {
48+
chrome.tabs.create({ url: 'https://chat.openai.com' });
49+
}
50+
});
51+
52+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
53+
if (request.type === 'GET_CHATGPT_ACCESS_TOKEN') {
54+
getChatGPTAccessToken().then((accessToken) => {
55+
sendResponse({ accessToken: accessToken });
56+
});
57+
return true;
58+
}
59+
});
60+
4861
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
62+
// If descriptions tab is opened or updated, update the description
4963
let urlPattern = /^https:\/\/leetcode\.com\/problems\/.*\/(description\/)?/;
5064
if (changeInfo.status === 'complete' && tab.url && tab.url.match(urlPattern)) {
5165
setTimeout(() => {
@@ -55,6 +69,7 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
5569
}, 1000);
5670
}
5771

72+
// If solutions tab is opened or updated, add the video
5873
urlPattern = /^https:\/\/leetcode\.com\/problems\/.*\/solutions\/?/;
5974
if (changeInfo.status === 'complete' && tab.url && tab.url.match(urlPattern)) {
6075
setTimeout(() => {
@@ -64,19 +79,11 @@ chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
6479
}, 1000);
6580
}
6681

82+
// If problem tab is opened or updated, update the current problem title
6783
urlPattern = /^https:\/\/leetcode\.com\/problems\/.*\/?/;
6884
if (changeInfo.status === 'complete' && tab.url && tab.url.match(urlPattern)) {
6985
setTimeout(() => {
7086
chrome.storage.local.set({ 'currentLeetCodeProblemTitle': tab.title || 'title' });
7187
}, 1000);
7288
}
73-
});
74-
75-
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
76-
if (request.type === 'GET_CHATGPT_ACCESS_TOKEN') {
77-
getChatGPTAccessToken().then((accessToken) => {
78-
sendResponse({ accessToken: accessToken });
79-
});
80-
return true;
81-
}
82-
});
89+
});

src/popup/popup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ function processCode(
122122
ChatGPT, in your capacity as a coding expert, I need your assistance with a LeetCode problem titled ${problemTitle}.
123123
If only the function definition is provided, your task is to generate the optimal solution for this problem.
124124
Conversely, if the code is provided below, there is most likely error(s) in the code.
125-
Please correct any potential issues that is preventing the submission from being accepted.
125+
Please correct any potential issues that is preventing the submission f rom being accepted.
126126
If the code I provide is already correct and optimized, return it as is.
127127
All code should be returned in plain text, with no usage of code blocks, and only essential inline comments are permitted.
128128
`;

0 commit comments

Comments
 (0)