1+ const mountId = Math . random ( ) ;
2+
13export default defineContentScript ( {
24 matches : [ "*://*.github.com/*" ] ,
35 runAt : "document_end" ,
46
5- main ( ) {
7+ main ( ctx ) {
68 main ( ) ;
79 // TODO: schedule next interval for 1 second AFTER the main function finishes. If the main
810 // function takes more than 1 second, it might cause problems.
9- setInterval ( main , SECOND ) ;
11+ const loop = ctx . setInterval ( main , SECOND ) ;
12+ ctx . setTimeout ( ( ) => {
13+ clearInterval ( loop ) ;
14+ } , 10 * SECOND ) ;
1015 } ,
1116} ) ;
1217
@@ -16,19 +21,19 @@ function main() {
1621 if ( ! repo || ! owner ) return ;
1722
1823 const pr = getCurrentPr ( ) ;
19- if ( pr ) return replaceCount ( { type : "pr" , repo, owner, pr } , PrDiff ) ;
24+ if ( pr ) return replaceCount ( { mountId , type : "pr" , repo, owner, pr } , PrDiff ) ;
2025
2126 const commitHash = getCurrentRef ( ) ;
2227 if ( commitHash )
2328 return replaceCount (
24- { type : "commit" , repo, owner, ref : commitHash } ,
29+ { mountId , type : "commit" , repo, owner, ref : commitHash } ,
2530 CommitDiff ,
2631 ) ;
2732
2833 const commitRefs = getCurrentCompare ( ) ;
2934 if ( commitRefs )
3035 return replaceCount (
31- { type : "compare" , repo, owner, commitRefs } ,
36+ { mountId , type : "compare" , repo, owner, commitRefs } ,
3237 CompareDiff ,
3338 ) ;
3439}
0 commit comments