@@ -5,6 +5,8 @@ declare global {
55 const chrome : any ;
66}
77
8+ const isChrome = window . navigator . userAgent . toLowerCase ( ) . includes ( 'chrome' ) ;
9+
810function checkTab ( tabId : number , changeInfo : object , tab : browser . tabs . Tab ) {
911 browser . tabs . sendMessage ( tabId , {
1012 action : MessageAction . CheckTab ,
@@ -31,23 +33,31 @@ function send(tabId: number, message: string) {
3133 } ) ;
3234}
3335
36+ function enablePageAction ( tabId : number ) {
37+ if ( isChrome ) {
38+ chrome . pageAction . show ( tabId ) ;
39+ } else {
40+ browser . pageAction . show ( tabId ) ;
41+ }
42+ }
43+
44+ function disablePageAction ( tabId : number ) {
45+ if ( isChrome ) {
46+ chrome . pageAction . hide ( tabId ) ;
47+ } else {
48+ browser . pageAction . hide ( tabId ) ;
49+ }
50+ }
51+
3452function handleMessage ( message : Message , sender : browser . runtime . MessageSender ) {
3553 if ( ! sender . tab ) return ;
3654
3755 switch ( message . action ) {
3856 case MessageAction . EnableParsing :
39- if ( ( window as any ) . hasChromeAPIs ) {
40- chrome . pageAction . show ( message . payload . tabId ) ;
41- } else {
42- browser . pageAction . show ( message . payload . tabId ) ;
43- }
57+ enablePageAction ( message . payload . tabId ) ;
4458 break ;
4559 case MessageAction . DisableParsing :
46- if ( ( window as any ) . hasChromeAPIs ) {
47- chrome . pageAction . hide ( message . payload . tabId ) ;
48- } else {
49- browser . pageAction . hide ( message . payload . tabId ) ;
50- }
60+ disablePageAction ( message . payload . tabId ) ;
5161 break ;
5262 case MessageAction . SendTask :
5363 send ( sender . tab . id , message . payload . message ) ;
0 commit comments