@@ -2,47 +2,77 @@ import '../../assets/img/icon-34.png';
22import '../../assets/img/icon-128.png' ;
33
44( function ( ) {
5- let startURLDomensionsUpdated = false ;
5+ let startURLDimensionsUpdated = false ;
66 let aEvents = [ ] ;
77
8+ chrome . storage . local . get ( [ 'recordingEvents' , 'startURLDimensionsUpdated' , 'recordingTimestamp' ] , ( data ) => {
9+ const now = Date . now ( ) ;
10+ const dataTTL = 10 * 60 * 1000 ;
11+
12+ if ( data . recordingTimestamp && ( now - data . recordingTimestamp ) > dataTTL ) {
13+ chrome . storage . local . remove ( [ 'recordingEvents' , 'startURLDimensionsUpdated' , 'recordingTimestamp' ] ) ;
14+ aEvents = [ ] ;
15+ startURLDimensionsUpdated = false ;
16+ } else {
17+ if ( data . recordingEvents && Array . isArray ( data . recordingEvents ) ) {
18+ aEvents = data . recordingEvents ;
19+ }
20+ if ( data . startURLDimensionsUpdated !== undefined ) {
21+ startURLDimensionsUpdated = data . startURLDimensionsUpdated ;
22+ }
23+ }
24+ } ) ;
25+
826 chrome . storage . sync . get ( [ 'isRecording' ] , ( data ) => {
927 if ( data . isRecording ) {
1028 ( chrome . action || chrome . browserAction ) . setBadgeText (
1129 {
1230 text : '🔴' ,
1331 } ,
14- ( ) => { }
32+ ( ) => { }
1533 ) ;
1634 } else {
1735 ( chrome . action || chrome . browserAction ) . setBadgeText (
1836 {
1937 text : '' ,
2038 } ,
21- ( ) => { }
39+ ( ) => { }
2240 ) ;
2341 }
2442 } ) ;
2543
44+ function saveEventsToStorage ( ) {
45+ chrome . storage . local . set ( {
46+ recordingEvents : aEvents ,
47+ startURLDimensionsUpdated : startURLDimensionsUpdated ,
48+ recordingTimestamp : Date . now ( )
49+ } ) ;
50+ }
51+
2652 chrome . runtime . onMessage . addListener ( ( data , sender , sendResponse ) => {
2753 if ( data . messageType === 'events' ) {
28- if ( ! startURLDomensionsUpdated ) {
29- startURLDomensionsUpdated = true ;
54+ if ( ! startURLDimensionsUpdated ) {
55+ startURLDimensionsUpdated = true ;
3056 if ( aEvents . length === 1 && data . event . type === 'goto' ) {
3157 aEvents [ 0 ] . windowWidth = data . event . windowWidth ;
3258 aEvents [ 0 ] . windowHeight = data . event . windowHeight ;
3359
3460 if ( aEvents [ 0 ] . url === data . event . url ) {
61+ saveEventsToStorage ( ) ;
3562 return ;
3663 }
3764 }
3865 }
3966 aEvents . push ( data . event ) ;
67+ saveEventsToStorage ( ) ;
4068 } else if ( data . messageType === 'start' ) {
41- startURLDomensionsUpdated = false ;
69+ startURLDimensionsUpdated = false ;
4270 aEvents = [ data . event ] ;
71+ saveEventsToStorage ( ) ;
4372 } else if ( data . messageType === 'clear' ) {
44- startURLDomensionsUpdated = false ;
73+ startURLDimensionsUpdated = false ;
4574 aEvents = [ ] ;
75+ chrome . storage . local . remove ( [ 'recordingEvents' , 'startURLDimensionsUpdated' , 'recordingTimestamp' ] ) ;
4676 } else if ( data . messageType === 'give_recording_data' ) {
4777 chrome . runtime . sendMessage ( {
4878 messageType : 'recording_data' ,
0 commit comments