Skip to content

Commit

Permalink
Optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
kashifalikhan36 committed Dec 2, 2024
1 parent 89f6997 commit c356b54
Show file tree
Hide file tree
Showing 25 changed files with 169 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Extension/assets/index-B3SAdMjW.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Extension/assets/index-DRson3vD.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions Extension/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>LeakCode</title>
<script type="module" crossorigin src="/assets/index-B3SAdMjW.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DRson3vD.css">
</head>
<body>
<div id="root"></div>
</body>
</html>
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions Sourcecode/public/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// background.js

chrome.action.onClicked.addListener((tab) => {
// Execute custom.js in the context of the current tab when the extension icon is clicked
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["custom.js"],
});
});

// Listen for messages from the popup and trigger content.js injection
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "runCustomScript") {
chrome.scripting.executeScript({
target: { allFrames: true },
files: ["custom.js"],
});
sendResponse({ status: "custom script executed" });
}
});
68 changes: 68 additions & 0 deletions Sourcecode/public/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Function to evaluate an XPath expression and return the matching element
function evaluateXPath(xpathExpression) {
const xpathResult = document.evaluate(
xpathExpression,
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
);
return xpathResult.singleNodeValue; // Returns the first matching node or null
}

// Wait for 30 seconds before checking for the element
setTimeout(async () => {
const xpath =
'//*[@id="editor"]/div[2]/div[1]/div/div/div[1]/div[2]/div[1]/div[5]';
const element = evaluateXPath(xpath);
console.log("wait for 30sec");

if (element) {
try {
// Assuming `ai.languageModel.create()` is a valid API call and returns a session object
const session = await ai.languageModel.create({
systemPrompt:
"Pretend to be an LeetCode master and give me code without changing the logic whenever I provide my code. Return code by improving it don't change the logic and variable and make the code working. as Example: 'def twoSum(nums, target):\n for i in range(len(nums)):\n complement = target - nums[i]\n for j in range(i + 1, len(nums)):\n if nums[j] == complement:\n return [nums[i], nums[j]]\n return []\n",
});

const response = await session.prompt(element.textContent);
console.log(response);

const session_2 = await ai.languageModel.create({
systemPrompt:
"Pretend to be a LeetCode master. I will provide you with a code , and your task is to give me shortest and easiest explanation in very short and simple way and in simple and short steps of it with new lines. Do not modify or rewrite the code. Just explain how the code works and what it does.",
});

const response_2 = await session_2.prompt(element.textContent);
console.log(response_2);

const session_3 = await ai.languageModel.create({
systemPrompt:
"You have to Pretend like a Youtube Video Searecher. I will give you the code and You will write a query to serach in 4-8 words only for youtube to get right video of it . Example:- 'two sum question leetcode' ",
});

const response_3 = await session_3.prompt(element.textContent);
console.log(response_3);

function openCodeViewerPage(code, explain, query) {
// Encode the code to be URL-safe
const encodedCode = encodeURIComponent(code);
const encodedExplain = encodeURIComponent(explain);
const encodedVideolink = encodeURIComponent(query);
// Open the codeViewer.html in a new tab with the code as a URL parameter

window.open(
`https://kashifalikhan36.github.io/LeakCode?code=${encodedCode}&explanation=${encodedExplain}&queryvideo=${encodedVideolink}`,
"_blank"
);
}

// Call the function to open the new page with the code
openCodeViewerPage(response, response_2, response_3);
} catch (error) {
console.error("Error interacting with the language model:", error);
}
} else {
console.log("Element not found.");
}
}, 10000); // 30000 milliseconds = 30 seconds
Binary file added Sourcecode/public/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions Sourcecode/public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"manifest_version": 3,
"name": "LeakCode",
"version": "1.0",
"description": "Solve questions with your logic. If you can't finish in 30 minutes, you'll get a hint to help you solve it with the same logic.",
"action": {
"default_popup": "index.html"
},
"permissions": ["activeTab", "scripting", "storage"],
"background": {
"service_worker": "background.js"
},
"host_permissions": ["https://leetcode.com/problems/*"],
"content_scripts": [
{
"matches": ["https://leetcode.com/problems/*"],
"js": ["content.js"],
"run_at": "document_end"
}
],
"icons": {
"16": "logo.png",
"48": "logo.png",
"128": "logo.png"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c356b54

Please sign in to comment.