@@ -37,36 +37,10 @@ function backgroundCheck() {
3737 if ( tab !== undefined ) {
3838 activity . setCurrentActiveTab ( tab . url ) ;
3939 chrome . idle . queryState ( parseInt ( setting_interval_inactivity ) , function ( state ) {
40- if ( state === 'active' || ( state === 'idle' && checkDOM ( ) ) ) {
41- if ( activity . isLimitExceeded ( activeUrl , tab ) ) {
42- setBlockPageToCurrent ( activeUrl ) ;
43- }
44- if ( ! activity . isInBlackList ( activeUrl ) )
45- tab . incSummaryTime ( ) ;
46- if ( setting_view_in_badge === true ) {
47- if ( activity . isInBlackList ( activeUrl ) ) {
48- chrome . browserAction . setBadgeBackgroundColor ( { color : '#FF0000' } )
49- chrome . browserAction . setBadgeText ( {
50- tabId : activeTab . id ,
51- text : 'n/a'
52- } ) ;
53- } else {
54- chrome . browserAction . setBadgeBackgroundColor ( { color : [ 0 , 0 , 0 , 0 ] } )
55- var today = new Date ( ) . toLocaleDateString ( ) ;
56- var summary = tab . days . find ( s => s . date === today ) . summary ;
57- chrome . browserAction . setBadgeText ( {
58- tabId : activeTab . id ,
59- text : String ( convertSummaryTimeToBadgeString ( summary ) )
60- } ) ;
61- }
62- } else {
63- chrome . browserAction . setBadgeBackgroundColor ( { color : [ 0 , 0 , 0 , 0 ] } )
64- chrome . browserAction . setBadgeText ( {
65- tabId : activeTab . id ,
66- text : ''
67- } ) ;
68- }
40+ if ( state === 'active' ) {
41+ mainTRacker ( activeUrl , tab , activeTab ) ;
6942 }
43+ else checkDOM ( state , activeUrl , tab , activeTab ) ;
7044 } ) ;
7145 } else {
7246 if ( activity . isInBlackList ( activeUrl ) ) {
@@ -82,6 +56,37 @@ function backgroundCheck() {
8256 } ) ;
8357}
8458
59+ function mainTRacker ( activeUrl , tab , activeTab ) {
60+ if ( activity . isLimitExceeded ( activeUrl , tab ) ) {
61+ setBlockPageToCurrent ( activeUrl ) ;
62+ }
63+ if ( ! activity . isInBlackList ( activeUrl ) )
64+ tab . incSummaryTime ( ) ;
65+ if ( setting_view_in_badge === true ) {
66+ if ( activity . isInBlackList ( activeUrl ) ) {
67+ chrome . browserAction . setBadgeBackgroundColor ( { color : '#FF0000' } )
68+ chrome . browserAction . setBadgeText ( {
69+ tabId : activeTab . id ,
70+ text : 'n/a'
71+ } ) ;
72+ } else {
73+ chrome . browserAction . setBadgeBackgroundColor ( { color : [ 0 , 0 , 0 , 0 ] } )
74+ var today = new Date ( ) . toLocaleDateString ( ) ;
75+ var summary = tab . days . find ( s => s . date === today ) . summary ;
76+ chrome . browserAction . setBadgeText ( {
77+ tabId : activeTab . id ,
78+ text : String ( convertSummaryTimeToBadgeString ( summary ) )
79+ } ) ;
80+ }
81+ } else {
82+ chrome . browserAction . setBadgeBackgroundColor ( { color : [ 0 , 0 , 0 , 0 ] } )
83+ chrome . browserAction . setBadgeText ( {
84+ tabId : activeTab . id ,
85+ text : ''
86+ } ) ;
87+ }
88+ }
89+
8590function setBlockPageToCurrent ( activeUrl ) {
8691 var blockUrl = chrome . runtime . getURL ( "block.html" ) + '?url=' + activeUrl ;
8792 chrome . tabs . query ( { currentWindow : true , active : true } , function ( tab ) {
@@ -91,17 +96,19 @@ function setBlockPageToCurrent(activeUrl) {
9196
9297function isVideoPlayedOnPage ( ) {
9398 var videoElement = document . getElementsByTagName ( 'video' ) [ 0 ] ;
94- if ( videoElement !== undefined && videoElement . currentTime > 0 && ! videoElement . paused && ! videoElement . ended && videoElement . readyState > 2 )
99+ if ( videoElement !== undefined && videoElement . currentTime > 0 && ! videoElement . paused && ! videoElement . ended && videoElement . readyState > 2 ) {
95100 return true ;
101+ }
102+ else return false ;
96103}
97104
98- function checkDOM ( ) {
99- chrome . tabs . executeScript ( {
100- code : '(' + isVideoPlayedOnPage + ')();'
101- } , ( results ) => {
102- if ( results !== undefined && results !== null && results [ 0 ] !== undefined )
103- return results [ 0 ] ;
104- } ) ;
105+ function checkDOM ( state , activeUrl , tab , activeTab ) {
106+ if ( state === 'idle' ) {
107+ chrome . tabs . executeScript ( { code : "var videoElement = document.getElementsByTagName('video')[0]; (videoElement !== undefined && videoElement.currentTime > 0 && !videoElement.paused && !videoElement.ended && videoElement.readyState > 2);" } , ( results ) => {
108+ if ( results !== undefined && results [ 0 ] !== undefined && results [ 0 ] === true )
109+ mainTRacker ( activeUrl , tab , activeTab ) ;
110+ } ) ;
111+ }
105112}
106113
107114function backgroundUpdateStorage ( ) {
0 commit comments