Uthar commited on
Commit
25b4b13
·
verified ·
1 Parent(s): a330c98

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -25
app.py CHANGED
@@ -132,37 +132,56 @@ function simulateButtonPress() {
132
  console.log('Button Pressed!');
133
  }
134
 
135
- // Function to observe image changes
136
- function observeImageChanges() {
137
- // Select all images with the 'ImgToMonitor' class
138
- // const images = document.querySelectorAll('.svelte-1pijsyv');
139
- const images = document.querySelectorAll('.ImgToMonitor');
140
-
141
- // Create a MutationObserver to watch for changes in the image src
142
- const observer = new MutationObserver((mutationsList, observer) => {
143
- mutationsList.forEach(mutation => {
144
- if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
145
- // If the image src changes, simulate button press
146
- console.log('Image changed!');
147
- simulateButtonPress();
148
- }
149
  });
 
 
 
 
 
150
  });
151
-
152
- // Observer options: observe changes to attributes (like src)
153
- const config = { attributes: true };
154
-
155
- // Start observing each image
156
- images.forEach(image => {
157
- observer.observe(image, config);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  });
159
- }
160
-
161
- // Start observing
162
 
 
 
 
 
163
 
164
  window.addEventListener('load', () => {
165
- observeImageChanges();
166
  console.log("Yo");
167
  });
168
 
 
132
  console.log('Button Pressed!');
133
  }
134
 
135
+ // Function to monitor image src changes
136
+ function monitorImageSrcChanges() {
137
+ // Create a MutationObserver instance
138
+ const observer = new MutationObserver((mutationsList, observer) => {
139
+ // Loop through all mutations
140
+ mutationsList.forEach(mutation => {
141
+ // Check if any new image tags were added
142
+ if (mutation.type === 'childList') {
143
+ mutation.addedNodes.forEach(node => {
144
+ if (node.nodeName === 'IMG') {
145
+ // New image added, monitor its src
146
+ observeImageSrc(node);
147
+ }
 
148
  });
149
+ }
150
+ // Check if an image src attribute has changed
151
+ if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
152
+ console.log('Image src changed:', mutation.target.src);
153
+ }
154
  });
155
+ });
156
+
157
+ // Options for the observer (what to monitor)
158
+ const config = { childList: true, attributes: true, subtree: true, attributeFilter: ['src'] };
159
+
160
+ // Start observing the document body (or any specific element)
161
+ observer.observe(document.body, config);
162
+
163
+ // Initial monitoring of images already in the DOM
164
+ document.querySelectorAll('img').forEach(img => {
165
+ observeImageSrc(img);
166
+ });
167
+
168
+ // Function to observe an image's src attribute changes
169
+ function observeImageSrc(img) {
170
+ const srcObserver = new MutationObserver(mutations => {
171
+ mutations.forEach(mutation => {
172
+ if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
173
+ console.log('Image src changed:', img.src);
174
+ }
175
+ });
176
  });
 
 
 
177
 
178
+ // Start observing src attribute changes of the image
179
+ srcObserver.observe(img, { attributes: true, attributeFilter: ['src'] });
180
+ }
181
+ }
182
 
183
  window.addEventListener('load', () => {
184
+ monitorImageSrcChanges();
185
  console.log("Yo");
186
  });
187