Only attach if options enabled

This commit is contained in:
z0ccc 2022-05-02 17:31:39 -04:00
parent 46d8afdb18
commit ba176ea762

View file

@ -1,5 +1,3 @@
import countryLocales from '../../utils/countryLocales'
const attachTab = (tabId, ipData) => { const attachTab = (tabId, ipData) => {
chrome.storage.sync.get( chrome.storage.sync.get(
[ [
@ -15,6 +13,13 @@ const attachTab = (tabId, ipData) => {
'userAgent', 'userAgent',
], ],
(result) => { (result) => {
if (
result.timezone ||
result.lat ||
result.lon ||
result.locale ||
result.userAgent
) {
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(
@ -37,17 +42,6 @@ const attachTab = (tabId, ipData) => {
) )
} }
console.log(
result.localeMatchIP,
countryLocales[result.ipData.countryCode].locale,
result.locale
)
console.log(
result.localeMatchIP
? countryLocales[result.ipData.countryCode].locale
: result.locale
)
if (result.locale) { if (result.locale) {
chrome.debugger.sendCommand( chrome.debugger.sendCommand(
{ tabId: tabId }, { tabId: tabId },
@ -58,28 +52,21 @@ const attachTab = (tabId, ipData) => {
) )
} }
const latitude = result.latMatchIP if (result.lat || result.lon) {
? result.ipData.lat
: parseFloat(result.lat)
const longitude = result.lonMatchIP
? result.ipData.lon
: parseFloat(result.lon)
console.log(
result.latMatchIP,
result.ipData.lat,
parseFloat(result.lat)
)
chrome.debugger.sendCommand( chrome.debugger.sendCommand(
{ tabId: tabId }, { tabId: tabId },
'Emulation.setGeolocationOverride', 'Emulation.setGeolocationOverride',
{ {
latitude, latitude: result.lat
longitude, ? parseFloat(result.lat)
: result.ipData.lat,
longitude: result.lon
? parseFloat(result.lon)
: result.ipData.lon,
accuracy: 1, accuracy: 1,
} }
) )
}
if (result.userAgent) { if (result.userAgent) {
chrome.debugger.sendCommand( chrome.debugger.sendCommand(
@ -96,6 +83,7 @@ const attachTab = (tabId, ipData) => {
} }
}) })
} }
}
) )
} }