File tree Expand file tree Collapse file tree 5 files changed +39
-21
lines changed
Expand file tree Collapse file tree 5 files changed +39
-21
lines changed Original file line number Diff line number Diff line change 44 < meta charset ="utf-8 ">
55 < title > WebActivity Time Tracker</ title >
66 < link href ="style/webact.css " rel ="stylesheet "/>
7- < script src ="scripts/webact .js "> </ script >
7+ < script src ="scripts/storage .js "> </ script >
88 < script src ="scripts/common.js "> </ script >
9+ < script src ="scripts/webact.js "> </ script >
910</ head >
1011< body >
1112 < div id ="resultTable ">
Original file line number Diff line number Diff line change @@ -4,13 +4,13 @@ var tabs = [];
44var activity = new Activity ( ) ;
55var storage = new LocalStorage ( ) ;
66
7- chrome . tabs . onActivated . addListener ( function ( info ) {
8- chrome . tabs . get ( info . tabId , function ( tab ) {
9- activity . addTab ( tab ) ;
10- } ) ;
11- } ) ;
7+ function updateSummaryTime ( ) {
8+ setInterval ( backgroundCheck , SETTINGS_INTERVAL_CHECK ) ;
9+ }
1210
13- setInterval ( backgroundCheck , SETTINGS_INTERVAL_CHECK ) ;
11+ function updateStorage ( ) {
12+ setInterval ( backgroundUpdateStorage , SETTINGS_INTERVAL_SAVE_STORAGE ) ;
13+ }
1414
1515function backgroundCheck ( ) {
1616 chrome . windows . getLastFocused ( { populate : true } , function ( currentWindow ) {
@@ -29,4 +29,21 @@ function backgroundCheck() {
2929 }
3030 }
3131 } ) ;
32- }
32+ }
33+
34+ function backgroundUpdateStorage ( ) {
35+ if ( tabs . length > 0 )
36+ storage . save ( STORAGE_TABS , tabs ) ;
37+ }
38+
39+ function addListener ( ) {
40+ chrome . tabs . onActivated . addListener ( function ( info ) {
41+ chrome . tabs . get ( info . tabId , function ( tab ) {
42+ activity . addTab ( tab ) ;
43+ } ) ;
44+ } ) ;
45+ }
46+
47+ addListener ( ) ;
48+ updateSummaryTime ( ) ;
49+ updateStorage ( ) ;
Original file line number Diff line number Diff line change 11var STORAGE_TABS = 'tabs' ;
22var SETTINGS_INTERVAL_INACTIVITY = 30 ;
33var SETTINGS_INTERVAL_CHECK = 1000 ;
4+ var SETTINGS_INTERVAL_SAVE_STORAGE = 3000 ;
5+ var SETTINGS_INTERVAL_CHECK_STORAGE = 3000 ;
46
57function isEmpty ( obj ) {
68 for ( var prop in obj ) {
Original file line number Diff line number Diff line change 33class LocalStorage {
44 load ( name ) {
55 chrome . storage . local . get ( name , function ( item ) {
6- return item [ name ] ;
6+ if ( item [ name ] !== undefined )
7+ return JSON . parse ( item [ name ] ) ;
78 } ) ;
89 }
910
1011 save ( name , value ) {
11- chrome . storage . local . set ( name ) ;
12+ chrome . storage . local . set ( { name : JSON . stringify ( value ) } ) ;
1213 }
1314} ;
Original file line number Diff line number Diff line change 1- window . onload = function ( ) {
2- var resultTabs = { } ;
3- //var tabs = chrome.extension.getBackgroundPage().timer.tabs;
4- setInterval ( getDataFromStorage , 3000 ) ;
5- } ;
1+ var storage = new LocalStorage ( ) ;
62
7- function getDataFromStorage ( ) {
8- chrome . storage . local . get ( 'tabs' , function ( val ) {
9- resultTabs = JSON . parse ( val . tabs ) ;
10- getTabsFromStorage ( resultTabs ) ;
11- } ) ;
3+ setInterval ( getDataFromStorage , SETTINGS_INTERVAL_CHECK_STORAGE ) ;
4+
5+ function getDataFromStorage ( ) {
6+ var currentTabs = storage . load ( STORAGE_TABS ) ;
7+ if ( currentTabs !== undefined && currentTabs . length > 0 )
8+ getTabsFromStorage ( currentTabs ) ;
129}
1310
14- function getTabsFromStorage ( tabs ) {
11+ function getTabsFromStorage ( tabs ) {
1512 var table = document . getElementById ( 'resultTable' ) ;
1613 table . innerHTML = null ;
1714 for ( var i = 0 ; i < tabs . length ; i ++ ) {
You can’t perform that action at this time.
0 commit comments