Update system data when ip changes
This commit is contained in:
parent
cf587fdb74
commit
1f9d9a84e8
8 changed files with 77 additions and 26 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
// import { useState, useEffect } from 'react'
|
import { useState, useEffect } from 'react'
|
||||||
// import { Box } from 'theme-ui'
|
// import { Box } from 'theme-ui'
|
||||||
import Page from '../../Components/Page'
|
import Page from '../../Components/Page'
|
||||||
import CheckBox from '../../Components/CheckBox'
|
import CheckBox from '../../Components/CheckBox'
|
||||||
|
|
@ -7,10 +7,11 @@ import { Box, Label, Select } from 'theme-ui'
|
||||||
|
|
||||||
interface SystemPageProps {
|
interface SystemPageProps {
|
||||||
tab: string
|
tab: string
|
||||||
|
reverseGeocoding: any
|
||||||
}
|
}
|
||||||
|
|
||||||
const AutofillPage = ({ tab }: SystemPageProps) => {
|
const AutofillPage = ({ tab, reverseGeocoding }: SystemPageProps) => {
|
||||||
// const [ip, setIP] = useState(null)
|
const [city, setCity] = useState('')
|
||||||
// const [configuration, setConfiguration] = useState('default')
|
// const [configuration, setConfiguration] = useState('default')
|
||||||
|
|
||||||
// useEffect(() => {
|
// useEffect(() => {
|
||||||
|
|
@ -24,6 +25,15 @@ const AutofillPage = ({ tab }: SystemPageProps) => {
|
||||||
// })
|
// })
|
||||||
// }, [])
|
// }, [])
|
||||||
|
|
||||||
|
const changeUserAgent = () => {
|
||||||
|
// if (userAgentType !== 'custom') {
|
||||||
|
// setUserAgentType('custom')
|
||||||
|
// chrome.storage.local.set({
|
||||||
|
// userAgentType: 'custom',
|
||||||
|
// })
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page isCurrentTab={tab === 'autofill'} title={'Autofill Options'}>
|
<Page isCurrentTab={tab === 'autofill'} title={'Autofill Options'}>
|
||||||
<CheckBox title={'Disable Built-In Address Autofill'} />
|
<CheckBox title={'Disable Built-In Address Autofill'} />
|
||||||
|
|
@ -43,13 +53,13 @@ const AutofillPage = ({ tab }: SystemPageProps) => {
|
||||||
))} */}
|
))} */}
|
||||||
</Select>
|
</Select>
|
||||||
</Box>
|
</Box>
|
||||||
{/* <DebouncedInput
|
<DebouncedInput
|
||||||
name="userAgent"
|
name="city"
|
||||||
title="User Agent"
|
title="City"
|
||||||
value={userAgent}
|
value={city}
|
||||||
setValue={setUserAgent}
|
setValue={setCity}
|
||||||
onChange={changeUserAgent}
|
onChange={changeUserAgent}
|
||||||
/> */}
|
/>
|
||||||
</Page>
|
</Page>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,26 +6,26 @@ interface CurrentPageProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
const CurrentPage = ({ tab }: CurrentPageProps) => {
|
const CurrentPage = ({ tab }: CurrentPageProps) => {
|
||||||
let options: any
|
// let options: any
|
||||||
|
|
||||||
function success(pos: any) {
|
// function success(pos: any) {
|
||||||
var crd = pos.coords
|
// var crd = pos.coords
|
||||||
console.log('Your current position is:')
|
// console.log('Your current position is:')
|
||||||
console.log(`Latitude : ${crd.latitude}`)
|
// console.log(`Latitude : ${crd.latitude}`)
|
||||||
console.log(`Longitude: ${crd.longitude}`)
|
// console.log(`Longitude: ${crd.longitude}`)
|
||||||
console.log(`More or less ${crd.accuracy} meters.`)
|
// console.log(`More or less ${crd.accuracy} meters.`)
|
||||||
}
|
// }
|
||||||
|
|
||||||
function error(err: any) {
|
// function error(err: any) {
|
||||||
console.error(`ERROR(${err.code}): ${err.message}`)
|
// console.error(`ERROR(${err.code}): ${err.message}`)
|
||||||
}
|
// }
|
||||||
// options = {
|
// options = {
|
||||||
// enableHighAccuracy: false,
|
// enableHighAccuracy: false,
|
||||||
// timeout: 5000,
|
// timeout: 5000,
|
||||||
// maximumAge: 0,
|
// maximumAge: 0,
|
||||||
// }
|
// }
|
||||||
|
|
||||||
navigator.geolocation.watchPosition(success, error)
|
// navigator.geolocation.watchPosition(success, error)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page isCurrentTab={tab === 'current'} title={'Current Info'}>
|
<Page isCurrentTab={tab === 'current'} title={'Current Info'}>
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,19 @@ const SystemPage = ({ tab, ipData }: SystemPageProps) => {
|
||||||
chrome.storage.local.get(
|
chrome.storage.local.get(
|
||||||
['systemType', 'configuration', 'timezone', 'locale', 'lat', 'lon'],
|
['systemType', 'configuration', 'timezone', 'locale', 'lat', 'lon'],
|
||||||
(storage) => {
|
(storage) => {
|
||||||
if (storage.systemType !== 'default') {
|
console.log(ipData)
|
||||||
|
if (storage.systemType === 'matchIp' && ipData) {
|
||||||
|
setTimezone(ipData.timezone)
|
||||||
|
setLocale(countryLocales[ipData.countryCode].locale)
|
||||||
|
setLatitude(`${ipData.lat}`)
|
||||||
|
setLongitude(`${ipData.lon}`)
|
||||||
|
chrome.storage.local.set({
|
||||||
|
timezone: ipData.timezone,
|
||||||
|
locale: countryLocales[ipData.countryCode].locale,
|
||||||
|
lat: ipData.lat,
|
||||||
|
lon: ipData.lon,
|
||||||
|
})
|
||||||
|
} else if (storage.systemType === 'custom') {
|
||||||
storage.configuration && setConfiguration(storage.configuration)
|
storage.configuration && setConfiguration(storage.configuration)
|
||||||
storage.timezone && setTimezone(storage.timezone)
|
storage.timezone && setTimezone(storage.timezone)
|
||||||
storage.locale && setLocale(storage.locale)
|
storage.locale && setLocale(storage.locale)
|
||||||
|
|
@ -37,7 +49,7 @@ const SystemPage = ({ tab, ipData }: SystemPageProps) => {
|
||||||
: setSystemType('default')
|
: setSystemType('default')
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}, [])
|
}, [ipData])
|
||||||
|
|
||||||
const changeType = (e: ChangeEvent<HTMLInputElement>) => {
|
const changeType = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
detachDebugger()
|
detachDebugger()
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import DebouncedInput from '../../Components/DebouncedInput'
|
||||||
import userAgents from '../../../utils/userAgents'
|
import userAgents from '../../../utils/userAgents'
|
||||||
import detachDebugger from '../../../utils/detachDebugger'
|
import detachDebugger from '../../../utils/detachDebugger'
|
||||||
import Page from '../../Components/Page'
|
import Page from '../../Components/Page'
|
||||||
|
import CheckBox from '../../Components/CheckBox'
|
||||||
|
|
||||||
interface UserAgentPageProps {
|
interface UserAgentPageProps {
|
||||||
tab: string
|
tab: string
|
||||||
|
|
@ -152,7 +153,9 @@ const UserAgentPage = ({ tab }: UserAgentPageProps) => {
|
||||||
value={userAgent}
|
value={userAgent}
|
||||||
setValue={setUserAgent}
|
setValue={setUserAgent}
|
||||||
onChange={changeUserAgent}
|
onChange={changeUserAgent}
|
||||||
|
mb="12px"
|
||||||
/>
|
/>
|
||||||
|
<CheckBox title={'Enable Debugger API Spoofing'} />
|
||||||
</Page>
|
</Page>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,16 +19,27 @@ import WebRtcPage from './Pages/WebRtcPage'
|
||||||
import CurrentPage from './Pages/CurrentPage'
|
import CurrentPage from './Pages/CurrentPage'
|
||||||
import { ipData } from '../types'
|
import { ipData } from '../types'
|
||||||
import getIp from '../utils/getIp'
|
import getIp from '../utils/getIp'
|
||||||
|
import getReverseGeocoding from '../utils/getReverseGeocoding'
|
||||||
import '../assets/global.css'
|
import '../assets/global.css'
|
||||||
import OtherOptionsPage from './Pages/OtherOptionsPage'
|
import OtherOptionsPage from './Pages/OtherOptionsPage'
|
||||||
|
|
||||||
const Popup = () => {
|
const Popup = () => {
|
||||||
const [tab, setTab] = useState('autofill')
|
const [tab, setTab] = useState('autofill')
|
||||||
const [ipData, setIpData] = useState<ipData | undefined>(undefined)
|
const [ipData, setIpData] = useState<ipData | undefined>(undefined)
|
||||||
|
const [reverseGeocoding, setReverseGeocoding] = useState<any>(undefined)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Promise.resolve(getIp()).then((data) => {
|
getIp().then((ipDataRes) => {
|
||||||
setIpData(data)
|
|
||||||
|
setIpData(ipDataRes)
|
||||||
|
if (ipDataRes.lat && ipDataRes.lon) {
|
||||||
|
getReverseGeocoding(ipDataRes.lat, ipDataRes.lon).then(
|
||||||
|
(reverseGeocodingRes) => {
|
||||||
|
setReverseGeocoding(reverseGeocodingRes)
|
||||||
|
console.log(reverseGeocodingRes)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
@ -91,7 +102,7 @@ const Popup = () => {
|
||||||
<Box sx={{ m: '12px', width: '100%' }}>
|
<Box sx={{ m: '12px', width: '100%' }}>
|
||||||
<CurrentPage tab={tab} />
|
<CurrentPage tab={tab} />
|
||||||
<SystemPage tab={tab} ipData={ipData} />
|
<SystemPage tab={tab} ipData={ipData} />
|
||||||
<AutofillPage tab={tab} />
|
<AutofillPage tab={tab} reverseGeocoding={reverseGeocoding} />
|
||||||
<WebRtcPage tab={tab} />
|
<WebRtcPage tab={tab} />
|
||||||
<UserAgentPage tab={tab} />
|
<UserAgentPage tab={tab} />
|
||||||
<OtherOptionsPage tab={tab} />
|
<OtherOptionsPage tab={tab} />
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ export const theme: Theme = {
|
||||||
forms: {
|
forms: {
|
||||||
label: { width: 'auto', alignItems: 'center' },
|
label: { width: 'auto', alignItems: 'center' },
|
||||||
input: {
|
input: {
|
||||||
|
// border: '2px solid',
|
||||||
p: '2px 8px',
|
p: '2px 8px',
|
||||||
mb: '8px',
|
mb: '8px',
|
||||||
borderColor: 'grey',
|
borderColor: 'grey',
|
||||||
|
|
@ -33,6 +34,7 @@ export const theme: Theme = {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
|
// border: '2px solid',
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
p: '2px 8px',
|
p: '2px 8px',
|
||||||
borderColor: 'grey',
|
borderColor: 'grey',
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ const getIp = () =>
|
||||||
fetch('http://ip-api.com/json/')
|
fetch('http://ip-api.com/json/')
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((ipData) => {
|
.then((ipData) => {
|
||||||
|
console.log(ipData)
|
||||||
chrome.storage.local.set({ ipData })
|
chrome.storage.local.set({ ipData })
|
||||||
return ipData
|
return ipData
|
||||||
})
|
})
|
||||||
|
|
|
||||||
12
src/utils/getReverseGeocoding.ts
Normal file
12
src/utils/getReverseGeocoding.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
const getReverseGeocoding = (lat: number, lon: number) =>
|
||||||
|
fetch(
|
||||||
|
`https://nominatim.openstreetmap.org/reverse?format=geojson&lat=${lat}&lon=${lon}`
|
||||||
|
)
|
||||||
|
.then((response) => response.json())
|
||||||
|
.then((data) => {
|
||||||
|
// chrome.storage.local.set({ ipData })
|
||||||
|
console.log(data)
|
||||||
|
return data.features[0].properties.address
|
||||||
|
})
|
||||||
|
|
||||||
|
export default getReverseGeocoding
|
||||||
Loading…
Add table
Reference in a new issue