Hi there! I'm currently developing a chrome extension similar to "OneTab" and "Better…
- User
Hi there! I'm currently developing a chrome extension similar to "OneTab" and "Better OneTab". I want you to understand the source code of the extension and help me make changes to it. Here is the code:
"""manifest.json { "manifest_version": 3, "name": "Tab Manager Extension", "version": "1.0", "description": "Manage and organize your open tabs.", "permissions": [ "tabs", "storage", "contextMenus" ], "background": { "service_worker": "background.js" }, "action": { "default_icon": { "16": "icons/icon16.png", "32": "icons/icon32.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } } } """
"""background.js // Function to generate a unique ID function generateUUID() { return crypto.randomUUID(); }
// Open extension page when its icon is clicked chrome.action.onClicked.addListener(() => { chrome.tabs.create({ url: 'tabs.html' }); });
// Create context menu items when the extension is installed or updated chrome.runtime.onInstalled.addListener(() => { // Menu items chrome.contextMenus.create({ id: 'saveTabsOnLeft', title: 'Save tabs on the left', contexts: ['action'] });
chrome.contextMenus.create({ id: 'saveTabsOnRight', title: 'Save tabs on the right', contexts: ['action'] });
chrome.contextMenus.create({ id: 'saveAllTabs', title: 'Save all tabs', contexts: ['action'] });
chrome.contextMenus.create({ id: 'saveAllTabsExceptThis', title: 'Save all tabs except this', contexts: ['action'] }); });
// Listen for clicks on context menu items chrome.contextMenus.onClicked.addListener((info, tab) => { if (info.menuItemId === 'saveTabsOnLeft') { saveTabsOnLeft(tab); } else if (info.menuItemId === 'saveTabsOnRight') { saveTabsOnRight(tab); } else if (info.menuItemId === 'saveAllTabs') { saveAllTabs(tab); } else if (info.menuItemId === 'saveAllTabsExceptThis') { saveAllTabsExceptThis(tab); } });
// Function to save tabs on the left function saveTabsOnLeft(currentTab) { chrome.tabs.query({ currentWindow: true }, (tabs) => { saveTabs(tabs.filter(tab => (tab.index < currentTab.index) && tab.url.startsWith('http'))); }); }
// Function to save tabs on the right function saveTabsOnRight(currentTab) { chrome.tabs.query({ currentWindow: true }, (tabs) => { saveTabs(tabs.filter(tab => (tab.index > currentTab.index) && tab.url.startsWith('http'))); }); }
// Function to save all tabs function saveAllTabs(currentTab) { chrome.tabs.query({ currentWindow: true }, (tabs) => { saveTabs(tabs.filter(tab => tab.url.startsWith('http'))); }); }
// Function to save all tabs except current function saveAllTabsExceptThis(currentTab) { chrome.tabs.query({ currentWindow: true }, (tabs) => { saveTabs(tabs.filter(tab => (tab.id !== currentTab.id) && tab.url.startsWith('http'))); }); }
// Generic function to save tabs function saveTabs(tabs) { // Check if there are any tabs to save if (tabs.length === 0) { console.log('No tabs to save'); return; }
// Map the filtered tabs to get their title and URL const tabsData = tabs.map(tab => ({ id: generateUUID(), title: tab.title, url: tab.url }));
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.