Spaces:
No application file
No application file
Update content.js
#3
by
hotboxxgenn - opened
- content.js +18 -24
content.js
CHANGED
|
@@ -1,31 +1,25 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
'[data-price]',
|
| 8 |
-
'span:contains("$")',
|
| 9 |
-
'div:contains("USD")',
|
| 10 |
-
'p:contains("Buy") + *'
|
| 11 |
];
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
}
|
| 22 |
-
});
|
| 23 |
});
|
| 24 |
}
|
| 25 |
|
| 26 |
-
//
|
| 27 |
-
|
| 28 |
|
| 29 |
-
//
|
| 30 |
-
const observer = new MutationObserver(
|
| 31 |
observer.observe(document.body, { childList: true, subtree: true });
|
|
|
|
| 1 |
+
function scanAndModifyPrices() {
|
| 2 |
+
const pricePatterns = [
|
| 3 |
+
/\$\d+(\.\d{2})?/, // $10 or $10.99
|
| 4 |
+
/\d+(\.\d{2})?\s*USD/, // 10 USD or 10.99 USD
|
| 5 |
+
/Price:\s*\d+(\.\d{2})?/, // Price: 10.00
|
| 6 |
+
/\d+(\.\d{2})?\s*EUR/ // 10.99 EUR
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
];
|
| 8 |
|
| 9 |
+
const elements = document.querySelectorAll('span, div, p, h1, h2, h3, h4, h5, h6');
|
| 10 |
+
elements.forEach(el => {
|
| 11 |
+
const text = el.textContent;
|
| 12 |
+
if (pricePatterns.some(pattern => pattern.test(text))) {
|
| 13 |
+
el.textContent = '$0.00';
|
| 14 |
+
el.style.color = 'green'; // Visual cue for modification
|
| 15 |
+
el.setAttribute('data-price-zero', 'true');
|
| 16 |
+
}
|
|
|
|
|
|
|
| 17 |
});
|
| 18 |
}
|
| 19 |
|
| 20 |
+
// Initial scan
|
| 21 |
+
scanAndModifyPrices();
|
| 22 |
|
| 23 |
+
// Handle dynamic content
|
| 24 |
+
const observer = new MutationObserver(scanAndModifyPrices);
|
| 25 |
observer.observe(document.body, { childList: true, subtree: true });
|