@@ -3,65 +3,60 @@ import { getOptionsFromBg, isAllowed } from '../options/syncOptions';
33let payload ;
44let sendMessage ;
55
6- getOptionsFromBg ( options => {
7- if ( ! isAllowed ( ) ) return ;
8-
9- // Relay background script massages to the page script
10- onMessage ( ( message ) => {
11- if ( message . action ) {
12- window . postMessage ( {
13- type : 'ACTION' ,
14- payload : message . action ,
15- source : 'redux-cs'
16- } , '*' ) ;
17- }
18- } ) ;
19-
20- if ( window . devToolsExtensionID ) { // Send external messages
21- sendMessage = function ( message ) {
22- chrome . runtime . sendMessage ( window . devToolsExtensionID , message ) ;
23- } ;
24- } else {
25- sendMessage = sendToBg ;
26-
27- let s = document . createElement ( 'script' ) ;
28- s . type = 'text/javascript' ;
29- s . appendChild ( document . createTextNode ( 'window.devToolsOptions=' + JSON . stringify ( options ) ) ) ;
30- ( document . head || document . documentElement ) . appendChild ( s ) ;
31-
32- s = document . createElement ( 'script' ) ;
33- s . src = chrome . extension . getURL ( 'js/page.bundle.js' ) ;
34- s . onload = function ( ) {
35- this . parentNode . removeChild ( this ) ;
36- } ;
37- ( document . head || document . documentElement ) . appendChild ( s ) ;
6+ getOptionsFromBg ( ) ;
7+
8+ // Relay background script massages to the page script
9+ onMessage ( ( message ) => {
10+ if ( message . action ) {
11+ window . postMessage ( {
12+ type : 'ACTION' ,
13+ payload : message . action ,
14+ source : 'redux-cs'
15+ } , '*' ) ;
3816 }
17+ } ) ;
3918
40- // Resend messages from the page to the background script
41- window . addEventListener ( 'message' , function ( event ) {
42- if ( ! event || event . source !== window || typeof event . data !== 'object' ) return ;
43- const message = event . data ;
44- if ( message . source !== 'redux-page' ) return ;
45- if ( message . payload ) payload = message . payload ;
46- sendMessage ( message ) ;
47- } , false ) ;
48-
49- if ( typeof window . onbeforeunload !== 'undefined' ) {
50- // Prevent adding beforeunload listener for Chrome apps
51- window . onbeforeunload = function ( ) {
52- sendMessage ( { type : 'PAGE_UNLOADED' } ) ;
53- } ;
19+ if ( window . devToolsExtensionID ) { // Send external messages
20+ sendMessage = function ( message ) {
21+ chrome . runtime . sendMessage ( window . devToolsExtensionID , message ) ;
22+ } ;
23+ } else {
24+ sendMessage = sendToBg ;
25+
26+ let s = document . createElement ( 'script' ) ;
27+ s . src = chrome . extension . getURL ( 'js/page.bundle.js' ) ;
28+ s . onload = function ( ) {
29+ this . parentNode . removeChild ( this ) ;
30+ } ;
31+ ( document . head || document . documentElement ) . appendChild ( s ) ;
32+ }
33+
34+ // Resend messages from the page to the background script
35+ window . addEventListener ( 'message' , function ( event ) {
36+ if ( ! isAllowed ( ) ) return ;
37+ if ( ! event || event . source !== window || typeof event . data !== 'object' ) return ;
38+ const message = event . data ;
39+ if ( message . source !== 'redux-page' ) return ;
40+ if ( message . payload ) payload = message . payload ;
41+ sendMessage ( message ) ;
42+ } , false ) ;
43+
44+ if ( typeof window . onbeforeunload !== 'undefined' ) {
45+ // Prevent adding beforeunload listener for Chrome apps
46+ window . onbeforeunload = function ( ) {
47+ if ( ! isAllowed ( ) ) return ;
48+ sendMessage ( { type : 'PAGE_UNLOADED' } ) ;
49+ } ;
50+ }
51+
52+ // Detect when the tab is reactivated
53+ document . addEventListener ( 'visibilitychange' , function ( ) {
54+ if ( ! isAllowed ( ) ) return ;
55+ if ( document . visibilityState === 'visible' && payload ) {
56+ sendMessage ( {
57+ payload : payload ,
58+ source : 'redux-page' ,
59+ init : true
60+ } ) ;
5461 }
55-
56- // Detect when the tab is reactivated
57- document . addEventListener ( 'visibilitychange' , function ( ) {
58- if ( document . visibilityState === 'visible' && payload ) {
59- sendMessage ( {
60- payload : payload ,
61- source : 'redux-page' ,
62- init : true
63- } ) ;
64- }
65- } , false ) ;
66-
67- } ) ;
62+ } , false ) ;
0 commit comments