@@ -5,15 +5,22 @@ var currentTab;
55var activity = new Activity ( ) ;
66var storage = new LocalStorage ( ) ;
77
8+ var setting_interval_save ;
9+ var setting_interval_inactivity ;
10+ var setting_view_in_badge ;
11+
812function updateSummaryTime ( ) {
913 setInterval ( backgroundCheck , SETTINGS_INTERVAL_CHECK_DEFAULT ) ;
1014}
1115
1216function updateStorage ( ) {
13- setInterval ( backgroundUpdateStorage , SETTINGS_INTERVAL_SAVE_STORAGE ) ;
17+ storage . getSettings ( SETTINGS_INTERVAL_SAVE_STORAGE , function ( item ) { setting_interval_save = item ; } ) ;
18+ setInterval ( backgroundUpdateStorage , setting_interval_save ) ;
1419}
1520
1621function backgroundCheck ( ) {
22+ storage . getSettings ( SETTINGS_INTERVAL_INACTIVITY , function ( item ) { setting_interval_inactivity = item ; } ) ;
23+ storage . getSettings ( SETTINGS_VIEW_TIME_IN_BADGE , function ( item ) { setting_view_in_badge = item ; } ) ;
1724 chrome . windows . getLastFocused ( { populate : true } , function ( currentWindow ) {
1825 if ( currentWindow . focused ) {
1926 var activeTab = currentWindow . tabs . find ( t => t . active === true ) ;
@@ -26,13 +33,15 @@ function backgroundCheck() {
2633
2734 if ( tab !== undefined ) {
2835 activity . setCurrentActiveTab ( tab . url ) ;
29- chrome . idle . queryState ( SETTINGS_INTERVAL_INACTIVITY , function ( state ) {
36+ chrome . idle . queryState ( setting_interval_inactivity , function ( state ) {
3037 if ( state === 'active' ) {
3138 tab . incSummaryTime ( ) ;
32- chrome . browserAction . setBadgeText ( {
33- tabId : activeTab . id ,
34- text : String ( convertSummaryTimeToBadgeString ( tab . summaryTime ) )
35- } ) ;
39+ if ( setting_view_in_badge ) {
40+ chrome . browserAction . setBadgeText ( {
41+ tabId : activeTab . id ,
42+ text : String ( convertSummaryTimeToBadgeString ( tab . summaryTime ) )
43+ } ) ;
44+ }
3645 }
3746 } ) ;
3847 }
@@ -46,7 +55,7 @@ function backgroundUpdateStorage() {
4655 storage . saveTabs ( tabs ) ;
4756}
4857
49- function setDefaultSettings ( ) {
58+ function setDefaultSettings ( ) {
5059 storage . saveSettings ( SETTINGS_INTERVAL_INACTIVITY , SETTINGS_INTERVAL_INACTIVITY_DEFAULT ) ;
5160 storage . saveSettings ( SETTINGS_INTERVAL_RANGE , SETTINGS_INTERVAL_RANGE_DEFAULT ) ;
5261 storage . saveSettings ( SETTINGS_VIEW_TIME_IN_BADGE , SETTINGS_VIEW_TIME_IN_BADGE_DEFAULT ) ;
@@ -67,7 +76,7 @@ function addListener() {
6776 } ) ;
6877 chrome . runtime . onInstalled . addListener ( function ( details ) {
6978 //if (details.reason == "install") {
70- setDefaultSettings ( ) ;
79+ setDefaultSettings ( ) ;
7180 //}
7281 } ) ;
7382}
0 commit comments