This repository was archived by the owner on Aug 27, 2025. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { debounce } from 'lodash-es';
22
33const interval = 200 ;
44const maxCount = 10000 / interval ;
5- export function observe ( selector : string , callback : ( ele : Element ) => void ) {
5+ export function observe ( selector : string , callback : ( ele : Element ) => void , endless ?: boolean ) {
66 let observer : MutationObserver ;
77 let cache : Element ;
88 const cb = ( result : Element ) => {
@@ -14,7 +14,7 @@ export function observe(selector: string, callback: (ele: Element) => void) {
1414 const run = ( ) => {
1515 let currentCount = 0 ;
1616 const result = document . querySelector ( selector ) ;
17- if ( result ) {
17+ if ( result && ! endless ) {
1818 cb ( result ) ;
1919 } else {
2020 if ( observer ) {
@@ -23,13 +23,19 @@ export function observe(selector: string, callback: (ele: Element) => void) {
2323 observer = new MutationObserver (
2424 debounce ( ( ) => {
2525 const result = document . querySelector ( selector ) ;
26- if ( result ) {
27- observer . disconnect ( ) ;
28- cb ( result ) ;
29- } else if ( currentCount > maxCount ) {
30- observer . disconnect ( ) ;
26+ if ( ! endless ) {
27+ if ( result ) {
28+ observer . disconnect ( ) ;
29+ cb ( result ) ;
30+ } else if ( currentCount > maxCount ) {
31+ observer . disconnect ( ) ;
32+ } else {
33+ currentCount ++ ;
34+ }
3135 } else {
32- currentCount ++ ;
36+ if ( result ) {
37+ cb ( result ) ;
38+ }
3339 }
3440 } , interval ) ,
3541 ) ;
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ class TwitterHook {
3333 callback : async ( el ) => {
3434 this . mountSyncOldTweets ( ) ;
3535 } ,
36+ endless : true ,
3637 } ,
3738 ] ;
3839
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import '../css/lib.css';
1111export interface Hook {
1212 selector : string ;
1313 callback : ( el : Element ) => void ;
14+ endless ?: boolean ;
1415}
1516
1617class CrossSyncContentScript {
@@ -29,7 +30,7 @@ class CrossSyncContentScript {
2930 switch ( new URL ( window . location . href ) . host ) {
3031 case 'twitter.com' :
3132 new TwitterHook ( this ) . hooks . forEach ( ( h ) => {
32- observe ( h . selector , h . callback ) ;
33+ observe ( h . selector , h . callback , h . endless ) ;
3334 } ) ;
3435 break ;
3536 default :
You can’t perform that action at this time.
0 commit comments