use custom data for debugger
This commit is contained in:
parent
d461af86e8
commit
fbaac625ed
2 changed files with 68 additions and 45 deletions
|
|
@ -1,6 +1,17 @@
|
||||||
import countryLocales from './countryLocales'
|
import countryLocales from './countryLocales'
|
||||||
|
|
||||||
const attachTab = (tabId, ipData) => {
|
const attachTab = (tabId, ipData) => {
|
||||||
|
chrome.storage.sync.get(
|
||||||
|
[
|
||||||
|
'ipData',
|
||||||
|
'timezone',
|
||||||
|
'timezoneMatchIP',
|
||||||
|
'lat',
|
||||||
|
'latitudeMatchIP',
|
||||||
|
'lon',
|
||||||
|
'longitudeMatchIP',
|
||||||
|
],
|
||||||
|
(result) => {
|
||||||
chrome.debugger.attach({ tabId: tabId }, '1.3', function () {
|
chrome.debugger.attach({ tabId: tabId }, '1.3', function () {
|
||||||
if (!chrome.runtime.lastError) {
|
if (!chrome.runtime.lastError) {
|
||||||
// chrome.debugger.sendCommand(
|
// chrome.debugger.sendCommand(
|
||||||
|
|
@ -16,21 +27,34 @@ const attachTab = (tabId, ipData) => {
|
||||||
chrome.debugger.sendCommand(
|
chrome.debugger.sendCommand(
|
||||||
{ tabId: tabId },
|
{ tabId: tabId },
|
||||||
'Emulation.setTimezoneOverride',
|
'Emulation.setTimezoneOverride',
|
||||||
{ timezoneId: ipData.timezone }
|
{
|
||||||
|
timezoneId: result.timezoneMatchIP
|
||||||
|
? result.ipData.timezone
|
||||||
|
: result.timezone,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
chrome.debugger.sendCommand(
|
chrome.debugger.sendCommand(
|
||||||
{ tabId: tabId },
|
{ tabId: tabId },
|
||||||
'Emulation.setLocaleOverride',
|
'Emulation.setLocaleOverride',
|
||||||
{ locale: countryLocales[ipData.countryCode].locale }
|
{ locale: countryLocales[result.ipData.countryCode].locale }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const latitude = result.latMatchIP
|
||||||
|
? result.ipData.lat
|
||||||
|
: parseFloat(result.lat)
|
||||||
|
const longitude = result.lonMatchIP
|
||||||
|
? result.ipData.lon
|
||||||
|
: parseFloat(result.lon)
|
||||||
|
|
||||||
|
console.log(latitude, longitude)
|
||||||
|
|
||||||
chrome.debugger.sendCommand(
|
chrome.debugger.sendCommand(
|
||||||
{ tabId: tabId },
|
{ tabId: tabId },
|
||||||
'Emulation.setGeolocationOverride',
|
'Emulation.setGeolocationOverride',
|
||||||
{
|
{
|
||||||
latitude: ipData.lat,
|
latitude,
|
||||||
longitude: ipData.lon,
|
longitude,
|
||||||
accuracy: 1,
|
accuracy: 1,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
@ -47,12 +71,12 @@ const attachTab = (tabId, ipData) => {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
|
chrome.tabs.onUpdated.addListener((tabId, change, tab) => {
|
||||||
chrome.storage.sync.get(['ipData'], (result) => {
|
attachTab(tabId)
|
||||||
attachTab(tabId, result.ipData)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// const attachTabs = (ipData) => {
|
// const attachTabs = (ipData) => {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ const DebugSettings = ({ type, ip }) => {
|
||||||
chrome.storage.sync.get([type, matchIPStorage], (result) => {
|
chrome.storage.sync.get([type, matchIPStorage], (result) => {
|
||||||
console.log(1, result)
|
console.log(1, result)
|
||||||
|
|
||||||
// result[matchIPStorage] && setMatchIP(result[matchIPStorage])
|
setMatchIP(result[matchIPStorage])
|
||||||
|
|
||||||
if (result[matchIPStorage]) {
|
if (result[matchIPStorage]) {
|
||||||
setValue(ip[type])
|
setValue(ip[type])
|
||||||
|
|
@ -50,7 +50,6 @@ const DebugSettings = ({ type, ip }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const changeTextValue = (e) => {
|
const changeTextValue = (e) => {
|
||||||
console.log(e.target.value)
|
|
||||||
chrome.storage.sync.set({ [type]: e.target.value })
|
chrome.storage.sync.set({ [type]: e.target.value })
|
||||||
setValue(e.target.value)
|
setValue(e.target.value)
|
||||||
if (matchIP) {
|
if (matchIP) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue