-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: WIP: crrently one directional, reload frames instead of tab
- Loading branch information
Showing
3 changed files
with
21 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
}, | ||
"permissions": [ | ||
"tabs", | ||
"webNavigation", | ||
"storage", | ||
"webRequest", | ||
"webRequestBlocking", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import { browserAction, tabs, type Tabs } from 'webextension-polyfill'; | ||
import { browserAction, webNavigation, type Tabs, tabs } from 'webextension-polyfill'; | ||
import { getHostname, invertHostState } from './utils/storage'; | ||
import { updateIcon } from './utils/actionIcon'; | ||
import { matcher, runtimeMapUrl } from './bg'; | ||
|
||
const replacedUrlMatcher = new RegExp(`^${runtimeMapUrl}\?`); | ||
|
||
browserAction.onClicked.addListener(async (tab: Tabs.Tab) => { | ||
if (!tab.url) return; | ||
if (!tab.url || !tab.id) return; | ||
|
||
let hostname = getHostname(tab.url); | ||
await invertHostState(hostname); | ||
|
||
updateIcon(hostname); | ||
|
||
// TODO: reload only frames (that have gmaps url), not full page | ||
tabs.reload(tab.id, { bypassCache: true }); | ||
let frames = (await webNavigation.getAllFrames({ tabId: tab.id })) ?? []; | ||
frames = frames.filter((frame) => { | ||
return frame.url.match(matcher) || frame.url.match(replacedUrlMatcher); | ||
}); | ||
frames.forEach((frame) => { | ||
// TODO: currently only works "from maps to osm" and "not from osm to maps" => fix it... | ||
tabs.executeScript(tab.id, { | ||
frameId: frame.frameId, | ||
code: 'document.location.reload();', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters