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,86 +13,76 @@ const attachTab = (tabId, ipData) => {
'userAgent', 'userAgent',
], ],
(result) => { (result) => {
chrome.debugger.attach({ tabId: tabId }, '1.3', function () { if (
if (!chrome.runtime.lastError) { result.timezone ||
// chrome.debugger.sendCommand( result.lat ||
// { tabId: tabId }, result.lon ||
// 'Emulation.clearGeolocationOverride' result.locale ||
// ) result.userAgent
) {
chrome.debugger.attach({ tabId: tabId }, '1.3', function () {
if (!chrome.runtime.lastError) {
// chrome.debugger.sendCommand(
// { tabId: tabId },
// 'Emulation.clearGeolocationOverride'
// )
// chrome.debugger.sendCommand( // chrome.debugger.sendCommand(
// { tabId: tabId }, // { tabId: tabId },
// 'Emulation.clearIdleOverride' // 'Emulation.clearIdleOverride'
// ) // )
if (result.timezone) { if (result.timezone) {
chrome.debugger.sendCommand( chrome.debugger.sendCommand(
{ tabId: tabId }, { tabId: tabId },
'Emulation.setTimezoneOverride', 'Emulation.setTimezoneOverride',
{ {
timezoneId: result.timezone, timezoneId: result.timezone,
} }
) )
}
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) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setLocaleOverride',
{
locale: result.locale,
}
)
}
const latitude = result.latMatchIP
? 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(
{ tabId: tabId },
'Emulation.setGeolocationOverride',
{
latitude,
longitude,
accuracy: 1,
} }
)
if (result.userAgent) { if (result.locale) {
chrome.debugger.sendCommand( chrome.debugger.sendCommand(
{ tabId: tabId }, { tabId: tabId },
'Emulation.setUserAgentOverride', 'Emulation.setLocaleOverride',
{ {
userAgent: result.userAgent, locale: result.locale,
} }
// { acceptLanguage: "en-CA" }, )
// { platform: "WebTV OS" } }
)
// 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.69', if (result.lat || result.lon) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setGeolocationOverride',
{
latitude: result.lat
? parseFloat(result.lat)
: result.ipData.lat,
longitude: result.lon
? parseFloat(result.lon)
: result.ipData.lon,
accuracy: 1,
}
)
}
if (result.userAgent) {
chrome.debugger.sendCommand(
{ tabId: tabId },
'Emulation.setUserAgentOverride',
{
userAgent: result.userAgent,
}
// { acceptLanguage: "en-CA" },
// { platform: "WebTV OS" }
)
// 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.69',
}
} }
} })
}) }
} }
) )
} }