diff --git a/background.js b/background.js index e69de29..9fa68db 100644 --- a/background.js +++ b/background.js @@ -0,0 +1,4 @@ +chrome.runtime.onInstalled.addListener(() => { + console.log("Reject Cookies extension installed."); + }); + \ No newline at end of file diff --git a/content.js b/content.js index a3387fe..5510aaa 100644 --- a/content.js +++ b/content.js @@ -1,17 +1,26 @@ -const selectors = [ - 'button[aria-label="reject"]', - 'button[data-testid="reject"]', - 'button[class*="reject"]', - ]; +chrome.storage.sync.get('selectors', (data) => { + const selectors = data.selectors || [ + 'button[aria-label="reject"]', + 'button[data-testid="reject"]', + 'button[class*="reject"]' + ]; - function clickButton(selector) { - const button = document.querySelector(selector); - if (button) { - button.click(); + function clickButton(selector) { + try { + const button = document.querySelector(selector); + if (button) { + console.log(`Clicked button with selector: ${selector}`); + button.click(); + // Notify user + new Notification("Reject Cookies", { body: `Rejected cookies with selector: ${selector}` }); + } + } catch (error) { + console.error(`Error clicking button with selector: ${selector}`, error); + } } - } - selectors.forEach(selector => { - clickButton(selector); + selectors.forEach(selector => { + clickButton(selector); + }); }); \ No newline at end of file diff --git a/images/icon128.png b/images/icon128.png new file mode 100644 index 0000000..df64851 Binary files /dev/null and b/images/icon128.png differ diff --git a/images/icon16.png b/images/icon16.png new file mode 100644 index 0000000..b6568e5 Binary files /dev/null and b/images/icon16.png differ diff --git a/images/icon48.png b/images/icon48.png new file mode 100644 index 0000000..c94ed10 Binary files /dev/null and b/images/icon48.png differ diff --git a/manifest.json b/manifest.json index 456f0de..fe3c5ce 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "name": "Reject Cookies", "version": "1.0", "description": "Automatically reject all cookie popups.", - "permissions": ["activeTab", "scripting"], + "permissions": ["activeTab", "storage", "scripting"], "background": { "service_worker": "background.js" }, @@ -13,6 +13,14 @@ "js": ["content.js"], "run_at": "document_end" } - ] + ], + "action": { + "default_popup": "popup.html", + "default_icon": { + "16": "images/icon16.png", + "48": "images/icon48.png", + "128": "images/icon128.png" + } + } } \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..77e727f --- /dev/null +++ b/popup.html @@ -0,0 +1,78 @@ + + + + Reject Cookies Settings + + + +
+

Reject Cookies Settings

+

+ Enter CSS selectors for cookie rejection buttons. One per line. +
For example: button[aria-label="reject"] +

+ + +

+
+

Current Selectors:

+ +
+
+ + + diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..252b23e --- /dev/null +++ b/popup.js @@ -0,0 +1,38 @@ +document.addEventListener('DOMContentLoaded', () => { + const textarea = document.getElementById('selectors'); + const saveButton = document.getElementById('save'); + const status = document.getElementById('status'); + const selectorsList = document.getElementById('selectors-list'); + + // Load existing selectors + chrome.storage.sync.get('selectors', (data) => { + const selectors = data.selectors || []; + textarea.value = selectors.join('\n'); + updateSelectorsList(selectors); + }); + + // Save button click event + saveButton.addEventListener('click', () => { + const selectors = textarea.value.split('\n').map(s => s.trim()).filter(s => s.length > 0); + + // Simple validation for selectors + if (selectors.length === 0) { + status.textContent = 'Please enter at least one selector.'; + status.style.color = 'red'; + return; + } + + chrome.storage.sync.set({ selectors: selectors }, () => { + status.textContent = 'Selectors saved!'; + status.style.color = '#28a745'; + updateSelectorsList(selectors); + setTimeout(() => status.textContent = '', 2000); + }); + }); + + // Update the list of selectors in the popup + function updateSelectorsList(selectors) { + selectorsList.innerHTML = selectors.map(selector => `
  • ${selector}
  • `).join(''); + } + }); + \ No newline at end of file