base on this edge & chrome extension code ,manifest.json "{ "manifestversion": 3,…
- User
base on this edge & chrome extension code ,manifest.json "{ "manifest_version": 3, "name": "Auto Close and Auto Pause Media", "version": "4.3", "description": "Stops Autoplay, Closes Tabs After Media Ends, One-Click Stop All Media, Plays One Media at a Time", "permissions": [ "tabs", "scripting", "webNavigation" ], "host_permissions": [ "<all_urls>" ], "content_scripts": [ { "matches": [ "<all_urls>" ], "js": ["content.js"], "run_at": "document_idle", "all_frames": true } ], "background": { "service_worker": "background.js" }, "action": { "default_icon": { "16": "icon.png", "48": "icon.png", "128": "icon.png" }, "default_title": "Auto Close and Auto Pause Media" }, "icons": { "16": "icon.png", "48": "icon.png", "128": "icon.png" } }" , background.js "let currentlyPlayingTabId = null; const closeTimers = {}; const closeDuration = 10000; // 10 seconds const videoTabs = new Set();
// Listener for the extension icon click to pause all media chrome.action.onClicked.addListener(() => { videoTabs.forEach((tabId) => { chrome.tabs.sendMessage(tabId, { action: 'pauseAllMedia' }); }); });
// Updates the red progress bar and closes the tab when complete const updateRedBarProgress = (tabId) => { const timerData = closeTimers[tabId]; if (!timerData) return;
const { closeStartTime } = timerData; const elapsedTime = Date.now() - closeStartTime; const progress = Math.min((elapsedTime / closeDuration) * 100, 100);
chrome.tabs.sendMessage(tabId, { action: 'updateRedBarProgress', progress: progress });
if (progress < 100) { timerData.closeTimerId = setTimeout(() => updateRedBarProgress(tabId), 100); // Update every 100ms } else { clearTimeout(timerData.closeTimerId); chrome.tabs.remove(tabId, () => { if (chrome.runtime.lastError) { console.error(
Error closing tab: ${chrome.runtime.lastError.message}); } }); delete closeTimers[tabId]; videoTabs.delete(tabId); } };// Message handler from content scripts chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { const tabId = sender.tab.id; switch (request.action) { case 'mediaStartedPlaying': videoTabs.add(tabId);
if (currentlyPlayingTabId && currentlyPlayingTabId !== tabId) { chrome.tabs.sendMessage(currentlyPlayingTabId, { action: 'pauseAllMedia' }); } currentlyPlayingTabId = tabId; break; case 'mediaStoppedPlaying': videoTabs.delete(tabId); if (tabId === currentlyPlayingTabId) { currentlyPlayingTabId = null; } break; case 'startCloseTimer': if (closeTimers[tabId]) { clearTimeout(closeTimers[tabId].closeTimerId); } closeTimers[tabId] = { closeStartTime: Date.now(), closeTimerId: null, }; updateRedBarProgress(tabId); break; case 'cancelCloseTimer': if (closeTimers[tabId]) { clearTimeout(closeTimers[tabId].closeTimerId); delete closeTimers[tabId]; } break;} sendResponse({ status: 'Message received' }); return true; });
// Listen for webNavigation events to inject content script into dynamically added iframes chrome.webNavigation.onCompleted.addListener(async (details) => { if (details.frameId !== 0) { // It's an iframe try { await chrome.scripting.executeScript({ target: { tabId: details.tabId, frameIds: [details.frameId] }, files: ['content.js'], }); } catch (e) { // Ignore injection failures for cross-origin iframes } } }, { url: [{ schemes: ['http', 'https'] }] });" , content.js "let currentlyPlaying = null; let lastUserInteractionTime = 0; let mediaElements = new WeakSet(); let lastTitle = document.title; const mediaEventHandlers = new WeakMap();
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.