Skip to content

Commit

Permalink
Only inject code on search page
Browse files Browse the repository at this point in the history
  • Loading branch information
workeffortwaste committed May 20, 2022
1 parent ca91f0d commit 0480218
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
8 changes: 7 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,15 @@ const runtimeInjection = async (settings) => {
window.vitalsDevice = settings.vitalsDevice
}

const validLocation = async () => {
return location.pathname === '/search'
}

chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.status === 'complete' && tab.url !== undefined) {
/* Abort if we're not on a search page */
if (new URL(tab.url).pathname !== '/search') return

const cruxKey = await getLocalStorageValue('apiKey')
let device = await getLocalStorageValue('deviceSettings')
let level = await getLocalStorageValue('levelSettings')
Expand All @@ -34,7 +41,6 @@ chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
level: level.levelSettings,
vitalsDevice: device.deviceSettings
}

chrome.scripting.executeScript({
target: { tabId: tab.id },
func: runtimeInjection,
Expand Down
56 changes: 28 additions & 28 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,33 @@
"scripting"
],
"host_permissions": [
"https://www.google.com/search?*",
"https://www.google.co.uk/search?*",
"https://www.google.de/search?*",
"https://www.google.nl/search?*",
"https://www.google.fr/search?*",
"https://www.google.dk/search?*",
"https://www.google.co.jp/search?*",
"https://www.google.es/search?*",
"https://www.google.ca/search?*",
"https://www.google.it/search?*",
"https://www.google.com.au/search?*",
"https://www.google.com.tw/search?*",
"https://www.google.com.br/search?*",
"https://www.google.com.tr/search?*",
"https://www.google.be/search?*",
"https://www.google.com.gr/search?*",
"https://www.google.co.in/search?*",
"https://www.google.com.mx/search?*",
"https://www.google.com.ar/search?*",
"https://www.google.ch/search?*",
"https://www.google.cl/search?*",
"https://www.google.at/search?*",
"https://www.google.ie/search?*",
"https://www.google.com.co/search?*",
"https://www.google.pl/search?*",
"https://www.google.pt/search?*",
"https://www.google.com.pk/search?*",
"https://www.google.co.kr/search?*"
"https://www.google.com/",
"https://www.google.co.uk/",
"https://www.google.de/",
"https://www.google.nl/",
"https://www.google.fr/",
"https://www.google.dk/",
"https://www.google.co.jp/",
"https://www.google.es/",
"https://www.google.ca/",
"https://www.google.it/",
"https://www.google.com.au/",
"https://www.google.com.tw/",
"https://www.google.com.br/",
"https://www.google.com.tr/",
"https://www.google.be/",
"https://www.google.com.gr/",
"https://www.google.co.in/",
"https://www.google.com.mx/",
"https://www.google.com.ar/",
"https://www.google.ch/",
"https://www.google.cl/",
"https://www.google.at/",
"https://www.google.ie/",
"https://www.google.com.co/",
"https://www.google.pl/",
"https://www.google.pt/",
"https://www.google.com.pk/",
"https://www.google.co.kr/"
]
}

0 comments on commit 0480218

Please sign in to comment.