@@ -49,6 +49,12 @@ module Content {
49
49
setTimeout ( function ( ) { fn . call ( null , data ) ; } , timeout ) ;
50
50
}
51
51
52
+ var cleanupMonitor = null ; function startCleanupMonitor ( ) {
53
+ cleanupMonitor = setTimeout ( function ( ) { clear ( ) } , 500 )
54
+ } ; function stopCleanupMonitor ( afterStop ) { if ( cleanupMonitor != null )
55
+ { clearTimeout ( cleanupMonitor ) ; afterStop ( ) ; }
56
+ }
57
+
52
58
chrome . runtime . onMessage . addListener (
53
59
function ( request , sender , sendResponse ) {
54
60
Log . debug ( "Received command " + request . command ) ;
@@ -60,6 +66,7 @@ module Content {
60
66
flags = "gi" ;
61
67
}
62
68
clear ( ) ;
69
+ startCleanupMonitor ( ) ;
63
70
infoSpan . add ( ) ;
64
71
infoSpan . setText ( "Searching..." ) ;
65
72
var re = new RegExp ( request . regexp , flags ) ;
@@ -73,6 +80,8 @@ module Content {
73
80
move ( false ) ;
74
81
} else if ( request . command == "next" ) {
75
82
move ( true ) ;
83
+ } else if ( request . command == "ping" ) {
84
+ stopCleanupMonitor ( ( ) => startCleanupMonitor ( ) ) ; // restart the monitor
76
85
} else {
77
86
Log . debug ( "Invalid command" ) ;
78
87
}
@@ -177,6 +186,7 @@ module Content {
177
186
// Remove all matches
178
187
function clear ( ) : void {
179
188
infoSpan . setText ( "Clearing..." ) ;
189
+ stopCleanupMonitor ( ( ) => cleanupMonitor = null )
180
190
setTimeout ( function ( ) {
181
191
cur = 0 ;
182
192
for ( var i = 0 ; i < marks . length ; i ++ ) {
0 commit comments