@@ -16,6 +16,7 @@ var setting_notification_list;
1616var setting_notification_message ;
1717
1818var isHasPermissioForYouTube ;
19+ var isHasPermissioForNetflix ;
1920var isHasPermissioForNotification ;
2021
2122function updateSummaryTime ( ) {
@@ -145,25 +146,45 @@ function isVideoPlayedOnPage() {
145146function checkDOM ( state , activeUrl , tab , activeTab ) {
146147 if ( state === 'idle' && isDomainEquals ( activeUrl , "youtube.com" ) ) {
147148 trackForYT ( mainTRacker , activeUrl , tab , activeTab ) ;
149+ } else if ( state === 'idle' && isDomainEquals ( activeUrl , "netflix.com" ) ) {
150+ trackForNetflix ( mainTRacker , activeUrl , tab , activeTab ) ;
148151 } else activity . closeIntervalForCurrentTab ( ) ;
149152}
150153
151154function trackForYT ( callback , activeUrl , tab , activeTab ) {
152155 if ( isHasPermissioForYouTube ) {
153- executeScript ( callback , activeUrl , tab , activeTab ) ;
156+ executeScriptYoutube ( callback , activeUrl , tab , activeTab ) ;
154157 } else {
155- checkPermissionsForYT ( executeScript , activity . closeIntervalForCurrentTab , callback , activeUrl , tab , activeTab ) ;
158+ checkPermissionsForYT ( executeScriptYoutube , activity . closeIntervalForCurrentTab , callback , activeUrl , tab , activeTab ) ;
156159 }
157160}
158161
159- function executeScript ( callback , activeUrl , tab , activeTab ) {
162+ function trackForNetflix ( callback , activeUrl , tab , activeTab ) {
163+ if ( isHasPermissioForNetflix ) {
164+ executeScriptNetflix ( callback , activeUrl , tab , activeTab ) ;
165+ } else {
166+ checkPermissionsForNetflix ( executeScriptNetflix , activity . closeIntervalForCurrentTab , callback , activeUrl , tab , activeTab ) ;
167+ }
168+ }
169+
170+ function executeScriptYoutube ( callback , activeUrl , tab , activeTab ) {
160171 chrome . tabs . executeScript ( { code : "var videoElement = document.getElementsByTagName('video')[0]; (videoElement !== undefined && videoElement.currentTime > 0 && !videoElement.paused && !videoElement.ended && videoElement.readyState > 2);" } , ( results ) => {
161172 if ( results !== undefined && results [ 0 ] !== undefined && results [ 0 ] === true )
162173 callback ( activeUrl , tab , activeTab ) ;
163174 else activity . closeIntervalForCurrentTab ( ) ;
164175 } ) ;
165176}
166177
178+ function executeScriptNetflix ( callback , activeUrl , tab , activeTab ) {
179+ chrome . tabs . executeScript ( { code : "var videoElement = document.getElementsByTagName('video')[0]; (videoElement !== undefined && videoElement.currentTime > 0 && !videoElement.paused && !videoElement.ended && videoElement.readyState > 2);" } , ( results ) => {
180+ if ( results !== undefined && results [ 0 ] !== undefined && results [ 0 ] === true ) {
181+ callback ( activeUrl , tab , activeTab ) ;
182+ } else {
183+ activity . closeIntervalForCurrentTab ( ) ;
184+ }
185+ } ) ;
186+ }
187+
167188function backgroundUpdateStorage ( ) {
168189 if ( tabs != undefined && tabs . length > 0 )
169190 storage . saveTabs ( tabs ) ;
@@ -324,6 +345,7 @@ function loadAddDataFromStorage() {
324345
325346function loadPermissions ( ) {
326347 checkPermissionsForYT ( ) ;
348+ checkPermissionsForNetflix ( ) ;
327349 checkPermissionsForNotifications ( ) ;
328350}
329351
@@ -340,6 +362,19 @@ function checkPermissionsForYT(callbackIfTrue, callbackIfFalse, ...props) {
340362 } ) ;
341363}
342364
365+ function checkPermissionsForNetflix ( callbackIfTrue , callbackIfFalse , ...props ) {
366+ chrome . permissions . contains ( {
367+ permissions : [ 'tabs' ] ,
368+ origins : [ "https://www.netflix.com/*" ]
369+ } , function ( result ) {
370+ if ( callbackIfTrue != undefined && result )
371+ callbackIfTrue ( ...props ) ;
372+ if ( callbackIfFalse != undefined && ! result )
373+ callbackIfFalse ( ) ;
374+ isHasPermissioForNetflix = result ;
375+ } ) ;
376+ }
377+
343378function checkPermissionsForNotifications ( callback , ...props ) {
344379 chrome . permissions . contains ( {
345380 permissions : [ "notifications" ]
0 commit comments