@@ -54,17 +54,17 @@ function checkForElement(selector, callback, options = {}) {
54
54
setTimeout ( checkElement , config . initialDelay ) ;
55
55
}
56
56
57
- // Watch for element changes in the DOM
57
+ // watch changess
58
58
class ElementWatcher {
59
59
constructor ( ) {
60
60
this . watchList = new Map ( ) ;
61
61
this . isWatching = false ;
62
62
this . observer = null ;
63
- this . processedScripts = new Set ( ) ; // Track scripts that have been processed
63
+ this . processedScripts = new Set ( ) ; // track processed scripts
64
64
}
65
65
66
66
watch ( selector , callback , scriptId ) {
67
- // Don't add duplicate watches for the same script
67
+ // dont process the same script multiple times
68
68
if ( this . processedScripts . has ( scriptId ) ) {
69
69
return ;
70
70
}
@@ -123,17 +123,16 @@ class ElementWatcher {
123
123
}
124
124
}
125
125
126
- // Create the ElementWatcher
126
+ // create watcher (I need a init function)
127
127
const elementWatcher = new ElementWatcher ( ) ;
128
- const executedScripts = new Set ( ) ; // Track executed scripts
128
+ const executedScripts = new Set ( ) ;
129
129
130
130
// Get messages from the background
131
131
chrome . runtime . onMessage . addListener ( ( message , sender , sendResponse ) => {
132
132
if ( message . action === "waitForElements" ) {
133
133
console . log ( "Received element-ready scripts:" , message . scripts . length ) ;
134
134
135
135
message . scripts . forEach ( ( script ) => {
136
- // Skip if script was already executed
137
136
if ( executedScripts . has ( script . id ) ) {
138
137
return ;
139
138
}
@@ -142,7 +141,6 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
142
141
checkForElement (
143
142
script . waitForSelector ,
144
143
( ) => {
145
- // Mark as executed before sending message to prevent race conditions
146
144
executedScripts . add ( script . id ) ;
147
145
chrome . runtime . sendMessage ( {
148
146
action : "elementFound" ,
@@ -168,7 +166,7 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
168
166
return true ;
169
167
} ) ;
170
168
171
- // Notify the background script when the content script is loaded
169
+ // Notif
172
170
chrome . runtime . sendMessage ( {
173
171
action : "contentScriptReady" ,
174
172
url : window . location . href ,
0 commit comments