File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,16 +48,20 @@ function showWhiteSpacesOn(line: Element): void {
4848 }
4949}
5050
51- async function run ( ) : Promise < void > {
52- let timeKeeper = Date . now ( ) ;
53- for ( const line of select . all ( '.blob-code-inner' ) ) {
54- line . classList . add ( 'rgh-showing-whitespace' ) ;
55- showWhiteSpacesOn ( line ) ;
56- if ( timeKeeper + 100 < Date . now ( ) ) {
57- await new Promise ( resolve => setTimeout ( resolve , 50 ) ) ;
58- timeKeeper = Date . now ( ) ;
51+ const viewportObserver = new IntersectionObserver ( changes => {
52+ for ( const change of changes ) {
53+ if ( change . isIntersecting ) {
54+ showWhiteSpacesOn ( change . target ) ;
55+ viewportObserver . unobserve ( change . target ) ;
5956 }
6057 }
58+ } ) ;
59+
60+ async function run ( ) : Promise < void > {
61+ for ( const line of select . all ( '.blob-code-inner:not(.rgh-observing-whitespace)' ) ) {
62+ line . classList . add ( 'rgh-observing-whitespace' ) ;
63+ viewportObserver . observe ( line ) ;
64+ }
6165}
6266
6367function init ( ) : void {
You can’t perform that action at this time.
0 commit comments