Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Here's a detailed guide on creating a Chrome extension to track website usage time:
1 2 3 4 5 6 7 8 9 10 11 | Project Structure: my-time-tracker/ ├── manifest.json ├── background.js ├── popup.html ├── popup.js ├── styles.css └── icons/ ├── icon16.png ├── icon48.png └── icon128.png |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | { "manifest_version": 3, "name": "Website Time Tracker", "version": "1.0", "description": "Track time spent on different websites", "permissions": [ "storage", "tabs", "activeTab", "alarms" ], "background": { "service_worker": "background.js" }, "action": { "default_popup": "popup.html", "default_icon": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } }, "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | let trackingData = {}; let currentUrl = ''; let startTime = null; // Initialize alarm for periodic saving chrome.alarms.create('saveData', { periodInMinutes: 1 }); // Track active tab changes chrome.tabs.onActivated.addListener(async (activeInfo) => { await updateTimeOnUrlChange(); }); // Track URL changes within the same tab chrome.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => { if (changeInfo.url) { await updateTimeOnUrlChange(); } }); // Handle alarm chrome.alarms.onAlarm.addListener((alarm) => { if (alarm.name === 'saveData') { updateTimeOnUrlChange(); } }); async function updateTimeOnUrlChange() { const tabs = await chrome.tabs.query({ active: true, currentWindow: true }); if (tabs.length === 0) return; const newUrl = new URL(tabs[0].url).hostname; // Update time for previous URL if (currentUrl && startTime) { const timeSpent = Date.now() - startTime; trackingData[currentUrl] = (trackingData[currentUrl] || 0) + timeSpent; // Save to storage chrome.storage.local.set({ timeData: trackingData }); } // Reset for new URL currentUrl = newUrl; startTime = Date.now(); } // Load saved data when extension starts chrome.storage.local.get(['timeData'], (result) => { if (result.timeData) { trackingData = result.timeData; } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <!DOCTYPE html> <html> <head> <title>Website Time Tracker</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="container"> <h1>Website Time Tracker</h1> <div id="stats"></div> <button id="resetStats">Reset Statistics</button> </div> <script src="popup.js"></script> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | document.addEventListener('DOMContentLoaded', async () => { // Load and display statistics const stats = document.getElementById('stats'); const { timeData = {} } = await chrome.storage.local.get(['timeData']); // Sort websites by time spent const sortedData = Object.entries(timeData) .sort(([, a], [, b]) => b - a); // Create HTML for statistics const statsHTML = sortedData.map(([domain, time]) => { const minutes = Math.round(time / 60000); // Convert ms to minutes const hours = Math.floor(minutes / 60); const remainingMinutes = minutes % 60; return ` <div class="stat-item"> <span class="domain">${domain}</span> <span class="time">${hours}h ${remainingMinutes}m</span> </div> `; }).join(''); stats.innerHTML = statsHTML || '<p>No data collected yet</p>'; // Reset button functionality document.getElementById('resetStats').addEventListener('click', async () => { await chrome.storage.local.set({ timeData: {} }); stats.innerHTML = '<p>No data collected yet</p>'; }); }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | body { width: 300px; padding: 10px; font-family: Arial, sans-serif; } .container { display: flex; flex-direction: column; gap: 10px; } h1 { font-size: 18px; margin: 0 0 10px 0; } .stat-item { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #eee; } .domain { font-weight: bold; } .time { color: #666; } #resetStats { margin-top: 10px; padding: 8px; background-color: #e74c3c; color: white; border: none; border-radius: 4px; cursor: pointer; } #resetStats:hover { background-color: #c0392b; } |
Testing if the previous output contains the string JavaScript
: False
Testing if the previous output contains the string background script
: True
Testing if the previous output contains the string manifest file
: True
Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Here's a detailed guide on creating a Chrome extension for website time tracking: # Chrome Time Tracking Extension Guide ## 1. Project Setup First, create a new directory for your project with the following structure:
1 2 3 4 5 6 7 8 9 10 | time-tracker/ ├── manifest.json ├── background.js ├── popup.html ├── popup.js ├── styles.css └── icons/ ├── icon16.png ├── icon48.png └── icon128.png |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | { "manifest_version": 3, "name": "Website Time Tracker", "version": "1.0", "description": "Track time spent on different websites", "permissions": [ "storage", "tabs", "activeTab" ], "background": { "service_worker": "background.js" }, "action": { "default_popup": "popup.html", "default_icon": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } }, "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | let timeData = {}; let startTime; let currentUrl; // Helper function to get domain from URL function getDomain(url) { const urlObj = new URL(url); return urlObj.hostname; } // Track active tab changes chrome.tabs.onActivated.addListener(async (activeInfo) => { const tab = await chrome.tabs.get(activeInfo.tabId); if (tab.url) { const domain = getDomain(tab.url); handleTabChange(domain); } }); // Track URL changes within the same tab chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (changeInfo.url) { const domain = getDomain(changeInfo.url); handleTabChange(domain); } }); function handleTabChange(newDomain) { const currentTime = Date.now(); if (currentUrl && startTime) { const timeSpent = Math.round((currentTime - startTime) / 1000); timeData[currentUrl] = (timeData[currentUrl] || 0) + timeSpent; // Save to storage chrome.storage.local.set({ timeData: timeData }); } currentUrl = newDomain; startTime = currentTime; } // Initialize data from storage chrome.storage.local.get(['timeData'], (result) => { if (result.timeData) { timeData = result.timeData; } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <!DOCTYPE html> <html> <head> <title>Website Time Tracker</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="container"> <h1>Time Spent Today</h1> <div id="stats"></div> <button id="resetBtn">Reset Stats</button> </div> <script src="popup.js"></script> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | document.addEventListener('DOMContentLoaded', () => { // Load and display stats updateStats(); // Reset button handler document.getElementById('resetBtn').addEventListener('click', resetStats); }); function updateStats() { chrome.storage.local.get(['timeData'], (result) => { const timeData = result.timeData || {}; const statsDiv = document.getElementById('stats'); statsDiv.innerHTML = ''; // Sort websites by time spent const sortedSites = Object.entries(timeData) .sort(([,a], [,b]) => b - a); for (const [domain, seconds] of sortedSites) { const row = document.createElement('div'); row.className = 'stat-row'; const time = formatTime(seconds); row.innerHTML = ` <span class="domain">${domain}</span> <span class="time">${time}</span> `; statsDiv.appendChild(row); } }); } function formatTime(seconds) { const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); const secs = seconds % 60; if (hours > 0) { return `${hours}h ${minutes}m`; } else if (minutes > 0) { return `${minutes}m ${secs}s`; } else { return `${secs}s`; } } function resetStats() { chrome.storage.local.set({ timeData: {} }, () => { updateStats(); }); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | body { width: 300px; padding: 15px; font-family: Arial, sans-serif; } .container { display: flex; flex-direction: column; gap: 10px; } h1 { font-size: 18px; margin: 0 0 15px 0; } .stat-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #eee; } .domain { font-weight: bold; } .time { color: #666; } #resetBtn { margin-top: 15px; padding: 8px; background-color: #e74c3c; color: white; border: none; border-radius: 4px; cursor: pointer; } #resetBtn:hover { background-color: #c0392b; } |
Testing if the previous output contains the string JavaScript
: False
Testing if the previous output contains the string background script
: False
Testing if the previous output contains the string manifest file
: False
Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Here's a detailed guide on creating a Chrome extension to track website usage time:
1 2 3 4 5 6 7 8 9 10 11 | Project Structure: my-time-tracker/ ├── manifest.json ├── background.js ├── popup.html ├── popup.js ├── styles.css └── icons/ ├── icon16.png ├── icon48.png └── icon128.png |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | { "manifest_version": 3, "name": "Website Time Tracker", "version": "1.0", "description": "Track time spent on different websites", "permissions": [ "storage", "tabs", "activeTab" ], "background": { "service_worker": "background.js" }, "action": { "default_popup": "popup.html", "default_icon": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } }, "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | let tracking = {}; let startTime; let currentUrl; // Initialize tracking when extension is installed chrome.runtime.onInstalled.addListener(() => { chrome.storage.local.set({ tracking: {} }); }); // Track active tab changes chrome.tabs.onActivated.addListener((activeInfo) => { chrome.tabs.get(activeInfo.tabId, (tab) => { updateTracking(tab); }); }); // Track URL changes within the same tab chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (changeInfo.url) { updateTracking(tab); } }); function updateTracking(tab) { const newUrl = new URL(tab.url).hostname; // Save time spent on previous site if (currentUrl && startTime) { const timeSpent = Math.round((Date.now() - startTime) / 1000); tracking[currentUrl] = (tracking[currentUrl] || 0) + timeSpent; // Save to storage chrome.storage.local.set({ tracking }); } // Start tracking new site currentUrl = newUrl; startTime = Date.now(); } // Update storage periodically (every minute) setInterval(() => { if (currentUrl && startTime) { const timeSpent = Math.round((Date.now() - startTime) / 1000); tracking[currentUrl] = (tracking[currentUrl] || 0) + timeSpent; chrome.storage.local.set({ tracking }); startTime = Date.now(); } }, 60000); |
1 2 3 4 5 6 7 8 9 10 11 12 13 | <!DOCTYPE html> <html> <head> <title>Website Time Tracker</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <h1>Time Spent on Websites</h1> <div id="stats"></div> <button id="reset">Reset Statistics</button> <script src="popup.js"></script> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | document.addEventListener('DOMContentLoaded', () => { updateStats(); document.getElementById('reset').addEventListener('click', () => { chrome.storage.local.set({ tracking: {} }, () => { updateStats(); }); }); }); function updateStats() { chrome.storage.local.get('tracking', (data) => { const tracking = data.tracking || {}; const statsDiv = document.getElementById('stats'); statsDiv.innerHTML = ''; // Sort websites by time spent const sortedSites = Object.entries(tracking) .sort(([, a], [, b]) => b - a); if (sortedSites.length === 0) { statsDiv.innerHTML = '<p>No data collected yet</p>'; return; } // Create table for statistics const table = document.createElement('table'); table.innerHTML = ` <tr> <th>Website</th> <th>Time Spent</th> </tr> `; sortedSites.forEach(([site, seconds]) => { const row = document.createElement('tr'); row.innerHTML = ` <td>${site}</td> <td>${formatTime(seconds)}</td> `; table.appendChild(row); }); statsDiv.appendChild(table); }); } function formatTime(seconds) { const hours = Math.floor(seconds / 3600); const minutes = Math.floor((seconds % 3600) / 60); const remainingSeconds = seconds % 60; const parts = []; if (hours > 0) parts.push(`${hours}h`); if (minutes > 0) parts.push(`${minutes}m`); if (remainingSeconds > 0 || parts.length === 0) parts.push(`${remainingSeconds}s`); return parts.join(' '); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | body { width: 300px; padding: 10px; font-family: Arial, sans-serif; } h1 { font-size: 16px; margin-bottom: 10px; } table { width: 100%; border-collapse: collapse; margin-bottom: 10px; } th, td { padding: 5px; text-align: left; border-bottom: 1px solid #ddd; } th { background-color: #f5f5f5; } button { width: 100%; padding: 8px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #45a049; } |
Testing if the previous output contains the string JavaScript
: False
Testing if the previous output contains the string background script
: False
Testing if the previous output contains the string manifest file
: False
Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Here's a detailed guide on creating a Chrome extension for website time tracking: ### 1. Create the Basic Extension Structure First, create a new directory for your extension with the following structure:
1 2 3 4 5 6 7 8 9 10 | time-tracker/ ├── manifest.json ├── background.js ├── popup.html ├── popup.js ├── styles.css └── icons/ ├── icon16.png ├── icon48.png └── icon128.png |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | { "manifest_version": 3, "name": "Website Time Tracker", "version": "1.0", "description": "Track time spent on different websites", "permissions": [ "storage", "tabs", "activeTab", "alarms" ], "background": { "service_worker": "background.js" }, "action": { "default_popup": "popup.html", "default_icon": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } }, "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | let activeTabId; let startTime; let tabData = {}; // Initialize tracking when a tab becomes active chrome.tabs.onActivated.addListener(async (activeInfo) => { const tab = await chrome.tabs.get(activeInfo.tabId); startTracking(tab); }); // Update tracking when a tab is updated chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (changeInfo.status === 'complete' && tab.active) { startTracking(tab); } }); function startTracking(tab) { // Stop tracking previous tab if (activeTabId) { updateTime(activeTabId); } // Start tracking new tab activeTabId = tab.id; startTime = Date.now(); const hostname = new URL(tab.url).hostname; if (!tabData[hostname]) { tabData[hostname] = 0; } } function updateTime(tabId) { if (startTime) { const endTime = Date.now(); const duration = endTime - startTime; chrome.tabs.get(tabId, (tab) => { if (tab && tab.url) { const hostname = new URL(tab.url).hostname; tabData[hostname] = (tabData[hostname] || 0) + duration; // Save data to storage chrome.storage.local.set({ timeData: tabData }); } }); } } // Save data periodically setInterval(() => { if (activeTabId) { updateTime(activeTabId); startTime = Date.now(); } }, 1000); |
1 2 3 4 5 6 7 8 9 10 11 12 13 | <!DOCTYPE html> <html> <head> <title>Website Time Tracker</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <h1>Time Spent on Websites</h1> <div id="stats"></div> <button id="reset">Reset Statistics</button> <script src="popup.js"></script> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | document.addEventListener('DOMContentLoaded', () => { displayStats(); document.getElementById('reset').addEventListener('click', () => { chrome.storage.local.set({ timeData: {} }, () => { displayStats(); }); }); }); function displayStats() { chrome.storage.local.get('timeData', (data) => { const timeData = data.timeData || {}; const statsDiv = document.getElementById('stats'); statsDiv.innerHTML = ''; // Sort websites by time spent const sortedSites = Object.entries(timeData) .sort(([, a], [, b]) => b - a); for (const [site, time] of sortedSites) { const div = document.createElement('div'); div.className = 'site-stat'; div.innerHTML = ` <span class="site-name">${site}</span> <span class="site-time">${formatTime(time)}</span> `; statsDiv.appendChild(div); } }); } function formatTime(ms) { const seconds = Math.floor(ms / 1000); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); if (hours > 0) { return `${hours}h ${minutes % 60}m`; } else if (minutes > 0) { return `${minutes}m ${seconds % 60}s`; } else { return `${seconds}s`; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | body { width: 300px; padding: 10px; font-family: Arial, sans-serif; } h1 { font-size: 16px; margin-bottom: 10px; } .site-stat { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #eee; } .site-name { font-weight: bold; } .site-time { color: #666; } button { margin-top: 10px; padding: 5px 10px; background-color: #4CAF50; color: white; border: none; border-radius: 3px; cursor: pointer; } button:hover { background-color: #45a049; } |
Testing if the previous output contains the string JavaScript
: False
Testing if the previous output contains the string background script
: False
Testing if the previous output contains the string manifest file
: False
Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Write a detailed guide on building a Chrome browser extension for Windows that monitors how much time I spend on different websites
Here's a detailed guide on building a Chrome extension to track website usage time:
1 2 3 4 5 6 7 8 9 10 11 | Project Structure: my-time-tracker/ ├── manifest.json ├── background.js ├── popup.html ├── popup.js ├── styles.css └── icons/ ├── icon16.png ├── icon48.png └── icon128.png |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | { "manifest_version": 3, "name": "Website Time Tracker", "version": "1.0", "description": "Track time spent on different websites", "permissions": [ "storage", "tabs", "activeTab" ], "background": { "service_worker": "background.js" }, "action": { "default_popup": "popup.html", "default_icon": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } }, "icons": { "16": "icons/icon16.png", "48": "icons/icon48.png", "128": "icons/icon128.png" } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | let startTime; let currentUrl; let timeData = {}; // Load saved data when extension starts chrome.storage.local.get(['timeData'], function(result) { if (result.timeData) { timeData = result.timeData; } }); // Track active tab changes chrome.tabs.onActivated.addListener(async (activeInfo) => { const tab = await chrome.tabs.get(activeInfo.tabId); handleTabChange(tab); }); // Track URL changes within the same tab chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { if (changeInfo.url) { handleTabChange(tab); } }); function handleTabChange(tab) { const newUrl = new URL(tab.url).hostname; if (currentUrl) { updateTime(currentUrl); } currentUrl = newUrl; startTime = new Date(); } function updateTime(url) { const endTime = new Date(); const timeSpent = endTime - startTime; if (!timeData[url]) { timeData[url] = 0; } timeData[url] += timeSpent; // Save to storage chrome.storage.local.set({ timeData: timeData }); } // Update time every minute for current tab setInterval(() => { if (currentUrl) { updateTime(currentUrl); startTime = new Date(); } }, 60000); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <!DOCTYPE html> <html> <head> <title>Website Time Tracker</title> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="container"> <h1>Time Spent on Websites</h1> <div id="stats"></div> <button id="reset">Reset Statistics</button> </div> <script src="popup.js"></script> </body> </html> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | .container { width: 300px; padding: 15px; } h1 { font-size: 18px; margin-bottom: 15px; } .site-stat { display: flex; justify-content: space-between; margin-bottom: 10px; padding: 5px; border-bottom: 1px solid #eee; } .site-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; } button { width: 100%; padding: 8px; margin-top: 15px; background-color: #f44336; color: white; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #d32f2f; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | document.addEventListener('DOMContentLoaded', function() { // Load and display statistics updateStats(); // Reset button handler document.getElementById('reset').addEventListener('click', function() { chrome.storage.local.set({ timeData: {} }, function() { updateStats(); }); }); }); function updateStats() { chrome.storage.local.get(['timeData'], function(result) { const timeData = result.timeData || {}; const statsDiv = document.getElementById('stats'); statsDiv.innerHTML = ''; // Sort websites by time spent const sortedSites = Object.entries(timeData) .sort(([,a], [,b]) => b - a); for (const [site, time] of sortedSites) { const siteDiv = document.createElement('div'); siteDiv.className = 'site-stat'; const siteName = document.createElement('span'); siteName.className = 'site-name'; siteName.textContent = site; const timeSpent = document.createElement('span'); timeSpent.className = 'time-spent'; timeSpent.textContent = formatTime(time); siteDiv.appendChild(siteName); siteDiv.appendChild(timeSpent); statsDiv.appendChild(siteDiv); } }); } function formatTime(ms) { const seconds = Math.floor(ms / 1000); const minutes = Math.floor(seconds / 60); const hours = Math.floor(minutes / 60); if (hours > 0) { return `${hours}h ${minutes % 60}m`; } else if (minutes > 0) { return `${minutes}m`; } else { return `${seconds}s`; } } |
Testing if the previous output contains the string JavaScript
: False
Testing if the previous output contains the string background script
: False
Testing if the previous output contains the string manifest file
: False