| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- (function() {
- console.log('Content script loaded');
-
- /**
- * Check if the current URL matches the pattern
- * @param {string} urlPattern - URL pattern to match
- * @returns {boolean} - Whether the current URL matches the pattern
- */
- function matchesUrlPattern(urlPattern) {
- const regex = new RegExp(urlPattern);
- return regex.test(window.location.href);
- }
- /**
- * Function to inject and execute custom code on the page
- */
- function injectCustomCode() {
- console.log('Custom code injected into the page');
-
- // Example: Add a banner to the top of the page
- const banner = document.createElement('div');
- banner.textContent = 'This page has been modified by My Firefox Extension';
- banner.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; background: #ffcc00; padding: 10px; text-align: center; z-index: 9999;';
- document.body.prepend(banner);
-
- // You can add more functionality here
- }
- // Listen for messages from the popup or background script
- browser.runtime.onMessage.addListener((message) => {
- if (message.command === 'injectCode') {
- injectCustomCode();
- return Promise.resolve({status: 'Injection completed'});
- }
- });
-
- // Check if we should automatically inject code based on URL
- if (matchesUrlPattern('example\\.com')) {
- injectCustomCode();
- }
- })();
|