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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -132,7 +132,7 @@ function simulateButtonPress() {
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) => {
@@ -142,7 +142,7 @@ function monitorImageSrcChanges() {
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
  });
@@ -150,6 +150,7 @@ function monitorImageSrcChanges() {
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
  });
@@ -171,6 +172,7 @@ function monitorImageSrcChanges() {
171
  mutations.forEach(mutation => {
172
  if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
173
  console.log('Image src changed:', img.src);
 
174
  }
175
  });
176
  });
@@ -178,6 +180,17 @@ function monitorImageSrcChanges() {
178
  // Start observing src attribute changes of the image
179
  srcObserver.observe(img, { attributes: true, attributeFilter: ['src'] });
180
  }
 
 
 
 
 
 
 
 
 
 
 
181
  }
182
 
183
  window.addEventListener('load', () => {
 
132
  console.log('Button Pressed!');
133
  }
134
 
135
+ // Function to monitor image src changes and automatically download the image
136
  function monitorImageSrcChanges() {
137
  // Create a MutationObserver instance
138
  const observer = new MutationObserver((mutationsList, observer) => {
 
142
  if (mutation.type === 'childList') {
143
  mutation.addedNodes.forEach(node => {
144
  if (node.nodeName === 'IMG') {
145
+ // New image added, monitor its src and download it
146
  observeImageSrc(node);
147
  }
148
  });
 
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
+ downloadImage(mutation.target.src);
154
  }
155
  });
156
  });
 
172
  mutations.forEach(mutation => {
173
  if (mutation.type === 'attributes' && mutation.attributeName === 'src') {
174
  console.log('Image src changed:', img.src);
175
+ downloadImage(img.src);
176
  }
177
  });
178
  });
 
180
  // Start observing src attribute changes of the image
181
  srcObserver.observe(img, { attributes: true, attributeFilter: ['src'] });
182
  }
183
+
184
+ // Function to download an image automatically
185
+ function downloadImage(src) {
186
+ const link = document.createElement('a');
187
+ link.href = src;
188
+ link.download = src.split('/').pop(); // Use the file name from the URL (last part of the src)
189
+ link.style.display = 'none'; // Hide the link
190
+ document.body.appendChild(link);
191
+ link.click(); // Trigger the download
192
+ document.body.removeChild(link); // Clean up the DOM by removing the link after download
193
+ }
194
  }
195
 
196
  window.addEventListener('load', () => {