diff --git a/manifest.json b/manifest.json index 4978e66..19bec77 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "Leetcode Explained", "version": "2.0.4", - "description": "Adds video solutions, company tags, and GPT code analysis into each problem.", + "description": "Adds video solutions, company tags, GPT code analysis and more.", "icons": { "16": "src/assets/images/logo/icon-16.png", "32": "src/assets/images/logo/icon-32.png", diff --git a/src/background/background.ts b/src/background/background.ts index 70730ee..c6f03e5 100644 --- a/src/background/background.ts +++ b/src/background/background.ts @@ -11,11 +11,14 @@ chrome.runtime.onInstalled.addListener(() => { .catch((error) => { console.error(error); }); + + // Default settings chrome.storage.local.set({ language: 'python' }); chrome.storage.local.set({ fontSize: 14 }); chrome.storage.local.set({ showCompanyTags: true }); chrome.storage.local.set({ showExamples: true }); chrome.storage.local.set({ showDifficulty: true }); + chrome.storage.local.set({ clickedCompany: 'Amazon' }) }); chrome.runtime.onMessage.addListener( @@ -44,6 +47,28 @@ chrome.runtime.onMessage.addListener( } ); +chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + if (request.action === "openCompanyPage") { + chrome.storage.local.set({ clickedCompany: request.company }); + chrome.tabs.create({ + url: chrome.runtime.getURL("src/popup/company.html"), + active: true + }, function (tab) { + // Keep a reference to the listener so it can be removed later + let listener = function (tabId, changedProps) { + // When the tab is done loading + if (tabId == tab.id && changedProps.status == "complete") { + chrome.tabs.sendMessage(tabId, request); + // Remove the listener once the tab is loaded + chrome.tabs.onUpdated.removeListener(listener); + } + }; + // Attach the listener + chrome.tabs.onUpdated.addListener(listener); + }); + } +}); + chrome.runtime.onMessage.addListener((request: any) => { if (request.type === 'OPEN_LOGIN_PAGE') { chrome.tabs.create({ url: 'https://chat.openai.com' }); @@ -59,6 +84,9 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { } }); + + + chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { // If descriptions tab is opened or updated, update the description let urlPattern = /^https:\/\/leetcode\.com\/problems\/.*\/(description\/)?/; diff --git a/src/content-script/update-description-tab.ts b/src/content-script/update-description-tab.ts index fd1a5cd..3da5786 100644 --- a/src/content-script/update-description-tab.ts +++ b/src/content-script/update-description-tab.ts @@ -97,15 +97,31 @@ function loadCompanyTags(problemTitle: string, companyTagContainer: HTMLElement) chrome.storage.local.get(['leetcodeProblems'], (result) => { const problem = result.leetcodeProblems.questions.find((problem: problem) => problem.title === problemTitle); if (problem.companies && problem.companies.length > 0) { - // slice the array to get only the first five companies const topCompanies = problem.companies.slice(0, 5); - // create a button for each company topCompanies.forEach((company: { name: string; score: any; }) => { const button = document.createElement('button'); + + // opens the company page when the button is clicked + button.onclick = () => { + chrome.runtime.sendMessage({ + // passes the company name and score to the background script + action: 'openCompanyPage', company: company.name + }) + } + + + // on hover, set background color to black + button.onmouseover = () => { + button.style.color = 'orange'; + } + button.onmouseout = () => { + button.style.color = 'white'; + } + button.style.display = 'flex'; - button.style.alignItems = 'center'; // align items vertically in the center - button.style.justifyContent = 'center'; // align items horizontally in the center + button.style.alignItems = 'center'; + button.style.justifyContent = 'center'; const icon = document.createElement('img'); icon.src = `https://logo.clearbit.com/${company.name.toLowerCase().replace(/\s/g, '')}.com`; // replace spaces with nothing diff --git a/src/popup/company.css b/src/popup/company.css new file mode 100644 index 0000000..870cb3b --- /dev/null +++ b/src/popup/company.css @@ -0,0 +1,67 @@ +body { + background-color: #202020; + color: #f0f0f0; + font-size: 18px; + font-family: 'Roboto', sans-serif; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + text-align: center; + margin: 0; + padding: 20px; +} + +h1 { + font-size: 36px; + margin-bottom: 20px; + color: lightcyan; +} + +table { + border-collapse: collapse; + margin: auto; + width: 500px; +} + +table, +th, +td { + border: 1px solid #FFFFFF; + padding: 10px; + text-align: center; +} + +th { + font-size: 18px; + background-color: #424242; +} + +td { + font-size: 16px; +} + +a { + color: lightgreen; + text-decoration: none; +} + +a:hover { + color: lightcyan; +} + +.header { + color: lightcyan; + +} + +.header:hover { + color: lightgreen; + cursor: pointer; + background-color: #202020; +} + +#score { + color: lightgreen; + font-weight: bold; +} \ No newline at end of file diff --git a/src/popup/company.html b/src/popup/company.html new file mode 100644 index 0000000..ca2f0f0 --- /dev/null +++ b/src/popup/company.html @@ -0,0 +1,27 @@ + + + +
+ ++ Score = How likely the company is to ask this question on a scale of 1-10 +
++ Data collected from 2021-2023 +
+# | +Title | +Score | +
---|