Merge pull request #1 from ahmedrmusa/feature/configure-selectors
add configurable selectors
This commit is contained in:
commit
bfab38c306
|
|
@ -0,0 +1,4 @@
|
||||||
|
chrome.runtime.onInstalled.addListener(() => {
|
||||||
|
console.log("Reject Cookies extension installed.");
|
||||||
|
});
|
||||||
|
|
||||||
13
content.js
13
content.js
|
|
@ -1,17 +1,26 @@
|
||||||
const selectors = [
|
chrome.storage.sync.get('selectors', (data) => {
|
||||||
|
const selectors = data.selectors || [
|
||||||
'button[aria-label="reject"]',
|
'button[aria-label="reject"]',
|
||||||
'button[data-testid="reject"]',
|
'button[data-testid="reject"]',
|
||||||
'button[class*="reject"]',
|
'button[class*="reject"]'
|
||||||
];
|
];
|
||||||
|
|
||||||
function clickButton(selector) {
|
function clickButton(selector) {
|
||||||
|
try {
|
||||||
const button = document.querySelector(selector);
|
const button = document.querySelector(selector);
|
||||||
if (button) {
|
if (button) {
|
||||||
|
console.log(`Clicked button with selector: ${selector}`);
|
||||||
button.click();
|
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 => {
|
selectors.forEach(selector => {
|
||||||
clickButton(selector);
|
clickButton(selector);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 4.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 555 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
|
|
@ -3,7 +3,7 @@
|
||||||
"name": "Reject Cookies",
|
"name": "Reject Cookies",
|
||||||
"version": "1.0",
|
"version": "1.0",
|
||||||
"description": "Automatically reject all cookie popups.",
|
"description": "Automatically reject all cookie popups.",
|
||||||
"permissions": ["activeTab", "scripting"],
|
"permissions": ["activeTab", "storage", "scripting"],
|
||||||
"background": {
|
"background": {
|
||||||
"service_worker": "background.js"
|
"service_worker": "background.js"
|
||||||
},
|
},
|
||||||
|
|
@ -13,6 +13,14 @@
|
||||||
"js": ["content.js"],
|
"js": ["content.js"],
|
||||||
"run_at": "document_end"
|
"run_at": "document_end"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"action": {
|
||||||
|
"default_popup": "popup.html",
|
||||||
|
"default_icon": {
|
||||||
|
"16": "images/icon16.png",
|
||||||
|
"48": "images/icon48.png",
|
||||||
|
"128": "images/icon128.png"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,78 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Reject Cookies Settings</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
width: 300px;
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
padding: 10px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
h2 {
|
||||||
|
font-size: 18px;
|
||||||
|
margin: 0;
|
||||||
|
padding-bottom: 10px;
|
||||||
|
border-bottom: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
textarea {
|
||||||
|
width: calc(100% - 20px);
|
||||||
|
height: 100px;
|
||||||
|
padding: 10px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
margin-top: 10px;
|
||||||
|
padding: 10px;
|
||||||
|
border: none;
|
||||||
|
background-color: #007bff;
|
||||||
|
color: white;
|
||||||
|
border-radius: 4px;
|
||||||
|
cursor: pointer;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background-color: #0056b3;
|
||||||
|
}
|
||||||
|
.status {
|
||||||
|
margin-top: 10px;
|
||||||
|
color: #28a745;
|
||||||
|
}
|
||||||
|
.instructions {
|
||||||
|
font-size: 14px;
|
||||||
|
color: #555;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
.selectors-list {
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
.selectors-list ul {
|
||||||
|
list-style-type: none;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.selectors-list li {
|
||||||
|
padding: 5px;
|
||||||
|
border-bottom: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h2>Reject Cookies Settings</h2>
|
||||||
|
<p class="instructions">
|
||||||
|
Enter CSS selectors for cookie rejection buttons. One per line.
|
||||||
|
<br>For example: <code>button[aria-label="reject"]</code>
|
||||||
|
</p>
|
||||||
|
<textarea id="selectors"></textarea>
|
||||||
|
<button id="save">Save</button>
|
||||||
|
<p id="status" class="status"></p>
|
||||||
|
<div class="selectors-list">
|
||||||
|
<h3>Current Selectors:</h3>
|
||||||
|
<ul id="selectors-list"></ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script src="popup.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
@ -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 => `<li>${selector}</li>`).join('');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
Loading…
Reference in New Issue