Skip to content

Commit 1c37b9e

Browse files
committed
give description, constraints, and examples to gpt for better gpt analysis
1 parent d59fa08 commit 1c37b9e

File tree

3 files changed

+36
-10
lines changed

3 files changed

+36
-10
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Leetcode Explained
22
![Downloads](https://img.shields.io/chrome-web-store/users/cofoinjfjcpgcjiinjhcpomcjoalijbe)
3-
![Version](https://img.shields.io/chrome-web-store/v/cofoinjfjcpgcjiinjhcpomcjoalijbe)
43
![Rating](https://img.shields.io/chrome-web-store/rating/cofoinjfjcpgcjiinjhcpomcjoalijbe)
4+
![Version](https://img.shields.io/chrome-web-store/v/cofoinjfjcpgcjiinjhcpomcjoalijbe)
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
66

77
A free, open source browser extension that adds video solutions, company tags, and GPT code analysis into each Leetcode problem
@@ -52,10 +52,8 @@ We welcome contributions! Please see the [CONTRIBUTING.md](docs/CONTRIBUTING.md)
5252
### Screenshots
5353

5454
<img src="src/assets/images/screenshots/add-video.png" alt="Add Video" width="600"/>
55-
56-
55+
<img src="src/assets/images/screenshots/get-company-tags.png" alt="Company Tags" width="600"/>
5756
<img src="src/assets/images/screenshots/get-complexity.png" alt="Code Complexity" width="600"/>
58-
5957
<img src="src/assets/images/screenshots/fix-code.png" alt="Fix Code" width="600"/>
6058

6159

src/content-script/get-user-code.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,40 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
77
}
88
});
99

10-
// Read the users code from the Leetcode problem page
10+
// Read the users code and examples from the Leetcode problem page
1111
function getCode() {
1212
const viewLines = document.getElementsByClassName('view-line');
13-
const textArray = [];
13+
const textArray = ['Heres the code'];
1414

1515
for (const viewLine of viewLines) {
1616
textArray.push(viewLine.textContent);
1717
}
18+
19+
textArray.push('Heres the problem description, test cases, and constraints\n');
20+
21+
// Add the test cases & examples to the
22+
const descriptionContainer = document.querySelector('div._1l1MA') as Element;
23+
if (!descriptionContainer) {
24+
return;
25+
}
26+
27+
// Add all the text from description container to the text array
28+
for (const child of descriptionContainer.children) {
29+
textArray.push(child.textContent);
30+
}
31+
32+
const examples = descriptionContainer.getElementsByClassName('example');
33+
if (examples && examples.length > 0) {
34+
const parent = examples[0].parentNode as Element;
35+
if (!parent) {
36+
return;
37+
}
38+
const startIndex = Array.from(descriptionContainer.children).indexOf(parent);
39+
for (let i = startIndex; i < descriptionContainer.children.length; i++) {
40+
const child = descriptionContainer.children[i] as HTMLElement;
41+
console.log(child);
42+
child.style.display = showExamples ? 'block' : 'none';
43+
}
44+
}
1845
return textArray;
1946
}

src/popup/popup.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,14 @@ function processCode(
137137
As a coding expert, I require your aid with a specific LeetCode problem
138138
called ${problemTitle}. Generate the best possible, optimized solution
139139
for this problem. Only the function definition and code should be returned
140-
in plain text format with no usage of code blocks. Do not return any code comments.
141-
Anything other than the code text is not permitted.`;
142-
if (infoMessage) infoMessage.textContent = 'Creating the solution ...';
140+
in plain text format with no usage of code blocks. Code comments are optional.
141+
Anything other than the code text is not permitted. I should be able to copy
142+
and paste the code into the LeetCode editor and run it successfully.`;
143+
if (infoMessage) infoMessage.textContent = 'Generating solution code ...';
143144
analyzeCodeResponse && analyzeCodeResponse.classList.add('hidden');
144145
fixCodeContainer && fixCodeContainer.classList.remove('hidden');
145146
}
146-
prompt += 'Copy the same function definition. Ignore my code\n' + codeText;
147+
prompt += 'Heres the problem description, examples, constraints and my code. Note that code might not exist and may be incorrect.\n' + codeText;
147148

148149
let response = '';
149150
Promise.race([

0 commit comments

Comments
 (0)