From 5d33decc7df15a14eb3e03bbefef07a4776d0ea9 Mon Sep 17 00:00:00 2001 From: z0ccc Date: Thu, 14 Apr 2022 00:50:04 -0400 Subject: [PATCH] Added popup button to refresh ip --- src/manifest.json | 2 +- src/pages/Background/index.js | 65 +++++++++++++++++++++-------------- src/pages/Popup/Popup.jsx | 24 +++++-------- 3 files changed, 49 insertions(+), 42 deletions(-) diff --git a/src/manifest.json b/src/manifest.json index 6efffda..1385f4e 100755 --- a/src/manifest.json +++ b/src/manifest.json @@ -3,7 +3,7 @@ "name": "Vytal", "description": "Vytal", "options_page": "options.html", - "permissions": ["debugger", "activeTab"], + "permissions": ["storage", "debugger", "activeTab"], "background": { "service_worker": "background.bundle.js" }, "action": { "default_popup": "popup.html", diff --git a/src/pages/Background/index.js b/src/pages/Background/index.js index 1b6e12b..fc0f304 100644 --- a/src/pages/Background/index.js +++ b/src/pages/Background/index.js @@ -1,8 +1,22 @@ import countryLocales from './countryLocales'; const attachTab = (tabId, ipData) => { + console.log(1); chrome.debugger.attach({ tabId: tabId }, '1.3', function () { + console.log(2, chrome.runtime.lastError); + if (!chrome.runtime.lastError) { + console.log(3); + + chrome.debugger.sendCommand( + { tabId: tabId }, + 'Emulation.clearGeolocationOverride' + ); + + chrome.debugger.sendCommand( + { tabId: tabId }, + 'Emulation.clearIdleOverride' + ); chrome.debugger.sendCommand( { tabId: tabId }, @@ -20,9 +34,9 @@ const attachTab = (tabId, ipData) => { { tabId: tabId }, 'Emulation.setGeolocationOverride', { - latitude: ipData.lat, - longitude: ipData.lon, - accuracy: 1, + latitude: ipData.lat, + longitude: ipData.lon, + accuracy: 1, } ); @@ -41,22 +55,24 @@ const attachTab = (tabId, ipData) => { }; chrome.tabs.onUpdated.addListener((tabId, change, tab) => { + // chrome.debugger.getTargets((tabs) => { + // let tab = tabs.find((obj) => { + // return obj.tabId === tabId; + // }); - chrome.debugger.getTargets((results) => { - - let result = results.find((obj) => { - return obj.tabId === tabId; - }); - - if (!result.attached) { - fetch('http://ip-api.com/json/') - .then(response => response.json()) - .then(ipData => attachTab(tabId, ipData)); - } - - }); + // if (!tab.attached) { + chrome.storage.sync.get(['ipData'], (result) => { + console.log(result.ipData) + attachTab(tabId, result.ipData); + }); + // } + // }); }); +// fetch('http://ip-api.com/json/') +// .then((response) => response.json()) +// .then((ipData) => {}); + // Detects if there are posts for current url // chrome.tabs.onCreated.addListener((tab) => { // console.log(tab.id) @@ -82,12 +98,11 @@ chrome.tabs.onUpdated.addListener((tabId, change, tab) => { // }); // }); - - // chrome.debugger.sendCommand( - // { tabId: tabId }, - // "Emulation.setAutomationOverride", - // { - // enabled: - // true, - // }, - // ); \ No newline at end of file +// chrome.debugger.sendCommand( +// { tabId: tabId }, +// "Emulation.setAutomationOverride", +// { +// enabled: +// true, +// }, +// ); diff --git a/src/pages/Popup/Popup.jsx b/src/pages/Popup/Popup.jsx index 3f63bef..998ffa3 100644 --- a/src/pages/Popup/Popup.jsx +++ b/src/pages/Popup/Popup.jsx @@ -1,25 +1,17 @@ import React from 'react'; -import logo from '../../assets/img/logo.svg'; -// import Greetings from '../../containers/Greetings/Greetings'; import './Popup.css'; +const getIP = () => fetch('http://ip-api.com/json/') +.then((response) => response.json()) +.then((ipData) => { + chrome.storage.sync.set({ ipData }); +}); + + const Popup = () => { return (
-
- logo -

- Edit src/pages/Popup/Popup.jsx and save to reload. -

- - Learn React! - -
+
); };