1
1
import { browserAction , webNavigation , type Tabs , tabs } from 'webextension-polyfill' ;
2
2
import { getHostname , invertHostState } from './utils/storage' ;
3
- import { matcher , runtimeMapUrl } from './bg' ;
3
+ import { matcher as mapsUrlMatcher , runtimeMapUrl } from './bg' ;
4
4
5
5
const replacedUrlMatcher = new RegExp ( `^${ runtimeMapUrl } \?` ) ;
6
6
@@ -9,8 +9,7 @@ const replacedUrlMatcher = new RegExp(`^${runtimeMapUrl}\?`);
9
9
* Takes the current tab, takes its hostname and inverts the state of the hostname.
10
10
*
11
11
* Requests all frames from the current tab, filters them for extension Leaflet frames and Maps frames.
12
- * Reloads the full tab on extension Leaflet frame match.
13
- * If no extension Leaflet frames were found it just reloads the Maps frames
12
+ * Reloads the full tab on extension Leaflet or Maps frame match.
14
13
* @param tab Currently active tab
15
14
*/
16
15
async function actionClick ( tab : Tabs . Tab ) : Promise < void > {
@@ -21,29 +20,13 @@ async function actionClick(tab: Tabs.Tab): Promise<void> {
21
20
22
21
let frames = ( await webNavigation . getAllFrames ( { tabId : tab . id } ) ) ?? [ ] ;
23
22
24
- // Added instead of commented below, as map currently isn't loaded properly on just frame reload...
25
- if ( frames . some ( ( frame ) => frame . url . match ( replacedUrlMatcher ) || frame . url . match ( matcher ) ) ) {
23
+ if (
24
+ frames . some ( ( frame ) => {
25
+ frame . url . match ( replacedUrlMatcher ) || frame . url . match ( mapsUrlMatcher ) ;
26
+ } )
27
+ ) {
26
28
tabs . reload ( tab . id , { bypassCache : true } ) ;
27
- return ;
28
29
}
29
-
30
- // TODO: check if reusable
31
- /*
32
- // matches osm frames (just reloading the frame ist not working for some reason, so in case of replaced maps the whole tab is reloaded)
33
- if (frames.some((frame) => frame.url.match(replacedUrlMatcher))) {
34
- tabs.reload(tab.id, { bypassCache: true });
35
- return;
36
- }
37
-
38
- // matches maps frames (finds the frames that have maps and reloads only them)
39
- frames = frames.filter((frame) => frame.url.match(matcher));
40
- frames.forEach((frame) => {
41
- tabs.executeScript(tab.id, {
42
- frameId: frame.frameId,
43
- code: 'document.location.reload();',
44
- });
45
- });
46
- */
47
30
}
48
31
49
32
browserAction . onClicked . addListener ( actionClick ) ;
0 commit comments