base on this edge & chrome extension code ,manifest v3 ,background.js "let…
- User
base on this edge & chrome extension code ,manifest v3 ,background.js "let currentlyPlayingTabId = null; let closeTimerId = null; let closeStartTime = null; const closeDuration = 10000; // 10 seconds
chrome.action.onClicked.addListener((tab) => { chrome.tabs.query({}, (tabs) => { tabs.forEach((tab) => { chrome.tabs.sendMessage(tab.id, { action: "pauseAllVideos" }); }); }); });
const updateRedBarProgress = (tabId) => { if (closeStartTime === null) return;
const elapsedTime = Date.now() - closeStartTime; const progress = Math.min((elapsedTime / closeDuration) * 100, 100);
chrome.tabs.sendMessage(tabId, { action: "updateRedBarProgress", progress: progress });
if (progress < 100) { closeTimerId = setTimeout(() => updateRedBarProgress(tabId), 100); // Update every 100ms } else { chrome.tabs.remove(tabId, () => { if (chrome.runtime.lastError) { console.error(
Error closing tab: ${chrome.runtime.lastError.message}); } }); } };chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { switch (request.action) { case "videoStartedPlaying": if (currentlyPlayingTabId && currentlyPlayingTabId !== sender.tab.id) { chrome.tabs.sendMessage(currentlyPlayingTabId, { action: "pauseAllVideos" }); } currentlyPlayingTabId = sender.tab.id; break; case "videoStoppedPlaying": if (sender.tab.id === currentlyPlayingTabId) { currentlyPlayingTabId = null; } break; case "startCloseTimer": clearTimeout(closeTimerId); closeStartTime = Date.now(); if (sender.tab.url.includes('youtube.com')) { updateRedBarProgress(sender.tab.id); } break; case "cancelCloseTimer": clearTimeout(closeTimerId); closeStartTime = null; break; } sendResponse({ status: "Message received" }); return true; });" ,content.js "let currentlyPlaying = null; let lastUserInteractionTime = 0; let videoElements = new WeakSet(); let lastTitle = document.title;
const clearRedBarAndTimer = () => { const redBar = document.getElementById('extension-red-bar'); if (redBar) { redBar.remove(); } if (chrome.runtime && chrome.runtime.sendMessage) { chrome.runtime.sendMessage({ action: "cancelCloseTimer" }); } };
const showRedBar = () => { clearRedBarAndTimer(); if (location.hostname.includes('youtube.com')) { const redBar = document.createElement('div'); redBar.id = 'extension-red-bar'; redBar.style.cssText =
position: fixed; top: 0; left: 0; width: 0%; height: 5px; background: red; z-index: 9999; transition: width 0.1s linear;; document.body.appendChild(redBar);if (chrome.runtime && chrome.runtime.sendMessage) { chrome.runtime.sendMessage({ action: "startCloseTimer" }); }} };
const updateRedBarProgress = (progress) => { const redBar = document.getElementById('extension-red-bar'); if (redBar) { redBar.style.width =
${progress}%; } };const pauseAllVideos = () => { for (const video of document.querySelectorAll('video')) { if (videoElements.has(video)) { video.pause(); } } currentlyPlaying = null; clearRedBarAndTimer(); if (chrome.runtime && chrome.runtime.sendMessage) { chrome.runtime.sendMessage({ action: "videoStoppedPlaying" }); } };
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.