From 245a73e0f9c86053adf2879a687cf7471d92ca55 Mon Sep 17 00:00:00 2001 From: Aarav Juneja Date: Wed, 11 Oct 2023 08:29:25 -0700 Subject: [PATCH 1/2] Migrate to manifest v3 --- report_ai/background.js | 12 ------------ report_ai/manifest.json | 11 ++++------- 2 files changed, 4 insertions(+), 19 deletions(-) delete mode 100644 report_ai/background.js diff --git a/report_ai/background.js b/report_ai/background.js deleted file mode 100644 index 6a728bf..0000000 --- a/report_ai/background.js +++ /dev/null @@ -1,12 +0,0 @@ -/* global chrome */ - -chrome.tabs.onActivated.addListener(function (activeInfo) { - console.log(activeInfo.tabId) - console.log('Tab changed') - const btn4 = document.querySelector('#refreshBtn') - btn4.onclick = () => { - chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { - chrome.tabs.reload(tabs[0].id) - }) - } -}) diff --git a/report_ai/manifest.json b/report_ai/manifest.json index 67e6522..f9ef5f0 100644 --- a/report_ai/manifest.json +++ b/report_ai/manifest.json @@ -1,16 +1,13 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "Report.AI", "description": "5-Star Rating, Summary, Report n much more..", "version": "3.1", - "browser_action": { + "action": { "default_popup": "index.html" }, - "permissions": ["storage", "http://127.0.0.1:5000/*", "background", "tabs"], - "background": { - "scripts": ["./background.js", "./popup.js"], - "persistent": false - }, + "permissions": ["storage", "tabs"], + "host_permissions": ["http://127.0.0.1:5000/*"], "icons": { "16": "assets/icon.png", "32": "assets/icon.png", From b5255c7ae27bf9ef4f6b34a9e348fc9c63303b15 Mon Sep 17 00:00:00 2001 From: Aarav Juneja Date: Sat, 14 Oct 2023 19:52:02 -0700 Subject: [PATCH 2/2] Added messaging in popup from content script. --- report_ai/content.js | 10 +++++++++- report_ai/popup.js | 13 ++++++++++--- server.py | 4 +++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/report_ai/content.js b/report_ai/content.js index 50dfb90..567553f 100644 --- a/report_ai/content.js +++ b/report_ai/content.js @@ -1,6 +1,6 @@ /* global chrome */ -let theText +let theText = '' const toSelect = ['p', 'h1', 'h2', 'h3', 'h5', 'h6', 'li'] // tags to extract texts from // extracting the data @@ -247,3 +247,11 @@ const pageMeta = { // saving the data in local storage chrome.storage.local.set({ key: pageMeta }) +chrome.runtime.onMessage.addListener( + function (request, sender, sendResponse) { + console.log(sender.tab + ? 'from a content script:' + sender.tab.url + : 'from the extension') + request.to === 'content_script' && sendResponse({ pageMeta }) + } +) diff --git a/report_ai/popup.js b/report_ai/popup.js index 6585e32..8c9e0c3 100644 --- a/report_ai/popup.js +++ b/report_ai/popup.js @@ -40,7 +40,7 @@ function logger (result) { } btn1.onclick = () => { - if (result && result.key && result.key.freqWord) { + if (result?.key?.freqWord) { for (let i = 0; i < 10; i++) { const s = document.createElement('span') s.innerHTML = result.key.freqWord[i] @@ -193,8 +193,15 @@ function saveEntry (rating, url) { }) } -// fetching the local data and calling the logger -chrome.storage.local.get(['key'], logger) +(async () => { + const [tab] = await chrome.tabs.query({ active: true, currentWindow: true }) + console.log(tab) + const response = await chrome.tabs.sendMessage(tab.id, { + to: 'content_script' + }) + console.log(response) + logger({ key: response.pageMeta }) +})() function checkConnectionSignal () { const element = document.getElementById('connectionSignal') diff --git a/server.py b/server.py index 461cd89..befcabc 100644 --- a/server.py +++ b/server.py @@ -25,7 +25,9 @@ ROBERTA = os.environ.get("BART", None) headersBart = {"Authorization": BART} headersRoberta = {"Authorization": ROBERTA} -MONGO_URI = os.environ.get("mongo_uri","mongodb+srv://admin:admin@reportai.ks0reyi.mongodb.net/") +MONGO_URI = os.environ.get( + "mongo_uri", "mongodb+srv://admin:admin@reportai.ks0reyi.mongodb.net/" +) client = MongoClient(MONGO_URI, server_api=ServerApi("1")) try: client.admin.command("ping")