@@ -20,7 +20,7 @@ const iconsDisabled = {
2020
2121const twitchUrlRegexp = / ^ h t t p s : \/ \/ w w w .t w i t c h .t v \/ * / ;
2222
23- let isEnabled ;
23+ let isEnabled = true ;
2424
2525browser . storage . local . get ( ) . then ( ( currentState ) => {
2626 isEnabled = typeof currentState . isEnabled === 'boolean' ? currentState . isEnabled : true ;
@@ -44,11 +44,6 @@ function broadcastUpdate(isEnabled) {
4444}
4545
4646function emitStatus ( tabId , isEnabled ) {
47- if ( isEnabled ) {
48- unlockForTab ( tabId ) ;
49- } else {
50- lockForTab ( tabId ) ;
51- }
5247 browser . tabs . sendMessage ( tabId , { isEnabled } ) ;
5348}
5449
@@ -74,29 +69,24 @@ browser.storage.onChanged.addListener((changes, areaName) => {
7469
7570const redirectedToTwitch = { } ;
7671
77-
78- console . log ( 'location' , window . location . href ) ;
79-
8072browser . tabs . onUpdated . addListener ( ( tabId , changeInfo , tab ) => {
81- if ( changeInfo . status === 'loading' && changeInfo . url ) {
82- console . log ( 'changeInfo' , changeInfo ) ;
73+ if ( changeInfo . status === 'loading' ) {
8374 // if redirecting within twitch
84- if ( ! redirectedToTwitch [ tabId ] && twitchUrlRegexp . test ( changeInfo . url ) ) {
85- console . log ( 'valid url' , ( changeInfo || tab ) . url ) ;
75+ if (
76+ ( ! redirectedToTwitch [ tabId ] && changeInfo . url && twitchUrlRegexp . test ( changeInfo . url ) )
77+ || ( ! changeInfo . url && twitchUrlRegexp . test ( tab . url ) )
78+ ) {
8679 unlockForTab ( tabId ) ;
8780 redirectedToTwitch [ tabId ] = true ;
8881 // if was on twitch, but is redirecting outside
89- } else if ( redirectedToTwitch [ tabId ] && ! twitchUrlRegexp . test ( changeInfo . url ) ) {
82+ } else if ( redirectedToTwitch [ tabId ] && changeInfo . url && ! twitchUrlRegexp . test ( changeInfo . url ) ) {
9083 lockForTab ( tabId ) ;
91- console . log ( 'leaving twitch' , changeInfo . url ) ;
9284 delete redirectedToTwitch [ tabId ] ;
9385 // if not twitch
94- } else if ( ! redirectedToTwitch [ tabId ] && ! twitchUrlRegexp . test ( changeInfo . url ) ) {
95- console . log ( 'not twitch' , changeInfo . url ) ;
86+ } else if ( ! redirectedToTwitch [ tabId ] && changeInfo . url && ! twitchUrlRegexp . test ( changeInfo . url ) ) {
9687 lockForTab ( tabId ) ;
9788 }
9889 } else if ( changeInfo . status === 'complete' && redirectedToTwitch [ tabId ] ) {
99- console . log ( 'changeInfo' , changeInfo ) ;
10090 emitStatus ( tabId , isEnabled ) ;
10191 }
10292} ) ;
@@ -106,24 +96,3 @@ browser.tabs.onRemoved.addListener((tabId) => {
10696 delete redirectedToTwitch [ tabId ] ;
10797 }
10898} )
109-
110- // browser.runtime.onMessage.addListener((message, sender) => {
111- // console.log('sender', sender);
112- // console.log('message', message);
113- // if (sender.origin === 'https://www.twitch.tv') {
114- // const tabId = sender.tab.id;
115- // if (!twitchUrlRegexp.test(message.url)) {
116- // console.log('false');
117- // emitStatus(tabId, false);
118- // } else if (typeof isEnabled === 'boolean') {
119- // console.log('returning', isEnabled);
120- // emitStatus(sender.tab.id, isEnabled);
121- // } else {
122- // browser.storage.local.get().then((currentState) => {
123- // console.log('returning', typeof currentState.isEnabled === 'boolean' ? currentState.isEnabled : true);
124- // const isEnabled = typeof currentState.isEnabled === 'boolean' ? currentState.isEnabled : true;
125- // emitStatus(sender.tab.id, isEnabled);
126- // });
127- // }
128- // }
129- // })
0 commit comments