Added popup button to refresh ip
This commit is contained in:
parent
4f26e63d21
commit
5d33decc7d
3 changed files with 49 additions and 42 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
// },
|
||||
// );
|
||||
// chrome.debugger.sendCommand(
|
||||
// { tabId: tabId },
|
||||
// "Emulation.setAutomationOverride",
|
||||
// {
|
||||
// enabled:
|
||||
// true,
|
||||
// },
|
||||
// );
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div className="App">
|
||||
<header className="App-header">
|
||||
<img src={logo} className="App-logo" alt="logo" />
|
||||
<p>
|
||||
Edit <code>src/pages/Popup/Popup.jsx</code> and save to reload.
|
||||
</p>
|
||||
<a
|
||||
className="App-link"
|
||||
href="https://reactjs.org"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>
|
||||
Learn React!
|
||||
</a>
|
||||
</header>
|
||||
<button type="button" onClick={() => getIP()}>Click Me!</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue