Make me a brave extension that instantly delete the browsing history of a specific website whenever i leave it. There will will be a interface that allow me to add URLs of websites that i want this feature to apply to. The extension will be named Incognito. Add an option to give the extension an icon. Make the interface big and add an option to add new websites ad infinum like A "add a new URL" Make a "save" button next to the box of each typing box to make sure it's saved. Make the interface look good and professional.
Assistant
Certainly! Below is a complete guide to creating a Brave browser extension named Incognito. This extension will automatically delete the browsing history of specified websites whenever you leave them. It includes a user-friendly interface where you can add URLs of the websites you want this feature to apply to. The interface is designed to be professional and allows you to add new websites indefinitely with an "Add a New URL" button and a "Save" button next to each input field.
Extension Overview
The extension consists of the following files:
manifest.json - Describes the extension and its permissions.
background.js - Handles background tasks like monitoring tab activity.
options.html - The options page for adding and managing URLs.
options.js - JavaScript for the options page functionality.
icon.png - The icon for the extension (you can use your own).
1. manifest.json
json
{
"manifest_version": 3,
"name": "Incognito",
"version": "1.0",
"description": "Automatically deletes browsing history of specified websites when you leave them.",
"permissions": [
"history",
"tabs",
"storage"
],
"background": {
"service_worker": "background.js"
},
"options_page": "options.html",
"icons": {
"128": "icon.png"
}
}
Explanation:
manifest_version: Specifies the version of the manifest format.
name: The name of the extension.
version: The version number of the extension.
description: A brief description of what the extension does.
permissions: Permissions the extension requires (history, tabs, storage).
background: Points to the background service worker script.
options_page: The HTML file for the options page.
icons: Specifies the icon file for the extension.
2. background.js
javascript
// background.js
// Monitor tab updates (e.g., when the URL changes)
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete') {
checkAndDeleteHistory(tab);
}
});
// Monitor tab removal (when a tab is closed)
chrome.tabs.onRemoved.addListener((tabId, removeInfo) => {
chrome.storage.local.get(['tabsInfo'], (result) => {
const tabsInfo = result.tabsInfo || {};
const url = tabsInfo[tabId];
if (url) {
deleteHistory(url);
delete tabsInfo[tabId];
chrome.storage.local.set({ tabsInfo });
}
});
});
function checkAndDeleteHistory(tab) {
chrome.storage.sync.get(['trackedUrls'], (data) => {
const trackedUrls = data.trackedUrls || [];
const currentUrl = tab.url;
const tabId = tab.id;
chrome.storage.local.get(['tabsInfo'], (result) => {
const tabsInfo = result.tabsInfo || {};
// Check if the current URL is a tracked URL
const isCurrentUrlTracked = trackedUrls.some((trackedUrl) =>
currentUrl.includes(trackedUrl)
);
// Get the previous URL for this tab
const previousUrl = tabsInfo[tabId];
// If we moved away from a tracked URL, delete its history
if (previousUrl && previousUrl !== currentUrl) {
const wasPreviousUrlTracked = trackedUrls.some((trackedUrl) =>
previousUrl.includes(trackedUrl)
);
if (wasPreviousUrlTracked && !currentUrl.includes(previousUrl)) {
deleteHistory(previousUrl);
}
}
// Update the stored URL for this tab
if (isCurrentUrlTracked) {
tabsInfo[tabId] = currentUrl;
} else {
delete tabsInfo[tabId];
}
chrome.storage.local.set({ tabsInfo });
});
});
}
function deleteHistory(urlPattern) {
chrome.history.search({ text: '', maxResults: 0 }, (historyItems) => {
historyItems.forEach((item) => {
if (item.url.includes(urlPattern)) {
chrome.history.deleteUrl({ url: item.url });
}
});
});
}
Explanation:
Tab Monitoring: Listens for tab updates and removals to track when you leave a tracked website.
tabsInfo Storage: Keeps track of the URLs open in each tab.
deleteHistory Function: Searches your history and deletes entries that match the specified URL pattern.
Layout: A clean and professional interface with a central heading.
URL List: A container for dynamically added URL input fields.
Add Button: Allows users to add new URL fields indefinitely.
4. options.js
javascript
// options.js
// Restore options when the page is loaded
document.addEventListener('DOMContentLoaded', restoreOptions);
// Add a new URL field when the 'Add a New URL' button is clicked
document.getElementById('addUrlButton').addEventListener('click', addNewUrlField);
function restoreOptions() {
chrome.storage.sync.get(['trackedUrls'], (data) => {
const trackedUrls = data.trackedUrls || [];
trackedUrls.forEach((url) => {
addUrlField(url);
});
});
}
function addNewUrlField() {
addUrlField('');
}
function addUrlField(value) {
const urlList = document.getElementById('urlList');
const urlItem = document.createElement('div');
urlItem.className = 'urlItem';
const inputField = document.createElement('input');
inputField.type = 'text';
inputField.value = value;
inputField.placeholder = 'Enter URL (e.g., example.com)';
const saveButton = document.createElement('button');
saveButton.textContent = 'Save';
saveButton.addEventListener('click', saveUrls);
const deleteButton = document.createElement('button');
deleteButton.textContent = 'Remove';
deleteButton.addEventListener('click', () => {
urlList.removeChild(urlItem);
saveUrls();
});
urlItem.appendChild(inputField);
urlItem.appendChild(saveButton);
urlItem.appendChild(deleteButton);
urlList.appendChild(urlItem);
}
function saveUrls() {
const inputs = document.querySelectorAll('#urlList input[type="text"]');
const urls = [];
inputs.forEach((input) => {
const url = input.value.trim();
if (url !== '') {
urls.push(url);
}
});
chrome.storage.sync.set({ trackedUrls: urls }, () => {
alert('URLs saved successfully.');
});
}
Explanation:
restoreOptions Function: Loads any previously saved URLs and adds input fields for them.
addUrlField Function: Dynamically adds a new input field for entering a URL.
saveUrls Function: Saves all entered URLs to Chrome's synchronized storage.
5. icon.png
Include an icon for your extension named icon.png in the extension's root directory. The icon should be 128x128 pixels for optimal display. You can create your own icon or use an online tool to design one.
Steps to Install and Use the Extension
1. Prepare the Extension Files:
Create a new folder on your computer for the extension (e.g., incognito-extension).
Save all the files (manifest.json, background.js, options.html, options.js, and icon.png) in this folder.
2. Load the Extension in Brave Browser:
Open Brave browser.
Navigate to brave://extensions/ by entering it in the address bar.
Enable Developer mode by toggling the switch in the top-right corner.
Click on the Load unpacked button.
Select the folder where you saved the extension files.
3. Access the Extension Options:
Once loaded, the extension will appear in your list of extensions.
Click on Details under the Incognito extension.
Click on Extension options to open the options page.
4. Configure Your Tracked Websites:
On the options page, click Add a New URL to add a new input field.
Enter the URL of the website you want to track (e.g., example.com).
Click Save next to the input field to save the URL.
Repeat this process to add as many websites as you like.
5. Using the Extension:
Browse to any of the websites you've added.
When you navigate away or close the tab, the extension will automatically delete the browsing history associated with that website.
Additional Notes
URL Matching: The extension uses simple substring matching. For example, entering example.com will match any URL that contains example.com.
Deleting History: The extension deletes history entries from the browser's history. Be cautious, as this action cannot be undone.
Data Storage: The list of URLs is stored using Chrome's sync storage, which can sync across devices if you're signed in.
Permissions: The extension requires certain permissions such as access to your browsing history (history), tabs (tabs), and storage (storage).
Enhancements and Customization
Customize the Interface: Feel free to modify the options.html and options.js files to change the appearance or add additional features to the options page.
Icon Design: Use a custom icon to personalize the extension. Ensure it represents the purpose of the extension and maintains a professional look.
Improve URL Matching: For more precise control, consider implementing regular expressions or using URL parsing to match specific domains or paths.
Feedback Mechanisms: Add notifications or visual feedback when history is deleted for transparency.
Disclaimer
Please use this extension responsibly. Deleting browsing history may have implications, especially if you rely on history entries for backtracking websites or for form autocomplete functionality. Make sure you understand the impact of automatically deleting history for the specified websites.
Feel free to reach out if you need any assistance or further customization!