diff --git a/Readme.md b/Readme.md index f9456cb..b8e2769 100644 --- a/Readme.md +++ b/Readme.md @@ -1,6 +1,6 @@ # 🔀 Random GitHub Notification -**Firefox add-on which adds a toolbar button to open a random GitHub notification of yours!** +**Chrome extension which adds a toolbar button to open a random GitHub notification of yours!** Very useful to catch up and work through notifications – with the excitement of randomness. diff --git a/background.js b/background.js index 7b90088..727c75f 100644 --- a/background.js +++ b/background.js @@ -1,20 +1,29 @@ -chrome.browserAction.onClicked.addListener(() => { - chrome.tabs.query({ url: "https://github.com/notifications*" }, (tabs) => { +chrome.action.onClicked.addListener(async (tab) => { + try { + const tabs = await chrome.tabs.query({ url: "https://github.com/notifications*" }); + if (tabs.length > 0) { - const tab = tabs[0]; - chrome.tabs.update(tab.id, { active: true }); - chrome.tabs.executeScript(tab.id, { code: `(${startNotificationRandomizer.toString()})()` }); + const notificationTab = tabs[0]; + await chrome.tabs.update(notificationTab.id, { active: true }); + await chrome.scripting.executeScript({ + target: { tabId: notificationTab.id }, + func: startNotificationRandomizer + }); } else { - chrome.tabs.create({ url: "https://github.com/notifications" }, (newTab) => { - chrome.tabs.onUpdated.addListener(function listener(tabId, changeInfo) { - if (tabId === newTab.id && changeInfo.status === 'complete') { - chrome.tabs.onUpdated.removeListener(listener); - chrome.tabs.executeScript(tabId, { code: `(${startNotificationRandomizer.toString()})()` }); - } - }); + const newTab = await chrome.tabs.create({ url: "https://github.com/notifications" }); + chrome.tabs.onUpdated.addListener(function listener(tabId, changeInfo) { + if (tabId === newTab.id && changeInfo.status === 'complete') { + chrome.tabs.onUpdated.removeListener(listener); + chrome.scripting.executeScript({ + target: { tabId: tabId }, + func: startNotificationRandomizer + }); + } }); } - }); + } catch (error) { + console.error('Error in extension:', error); + } }); function startNotificationRandomizer() { diff --git a/icon.svg b/icon.svg deleted file mode 100644 index 5268176..0000000 --- a/icon.svg +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - image/svg+xml - - - - - - - - - - - - diff --git a/icon128.png b/icon128.png new file mode 100644 index 0000000..14b68cc Binary files /dev/null and b/icon128.png differ diff --git a/icon16.png b/icon16.png new file mode 100644 index 0000000..a038533 Binary files /dev/null and b/icon16.png differ diff --git a/icon32.png b/icon32.png new file mode 100644 index 0000000..4191a76 Binary files /dev/null and b/icon32.png differ diff --git a/icon48.png b/icon48.png new file mode 100644 index 0000000..bb9fae4 Binary files /dev/null and b/icon48.png differ diff --git a/manifest.json b/manifest.json index 17cf951..16274d4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,22 +1,23 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "Random GitHub Notification", "version": "1.0", - "permissions": ["tabs", "activeTab", "https://github.com/*"], - "browser_action": { + "permissions": ["tabs", "activeTab", "scripting"], + "host_permissions": ["https://github.com/*"], + "action": { "default_icon": { - "48": "icon.svg" + "16": "icon16.png", + "32": "icon32.png", + "48": "icon48.png" } }, "background": { - "scripts": ["background.js"] + "service_worker": "background.js" }, "icons": { - "48": "icon.svg" - }, - "browser_specific_settings": { - "gecko": { - "id": "random-github-notification@keeporsweep.net" - } + "16": "icon16.png", + "32": "icon32.png", + "48": "icon48.png", + "128": "icon128.png" } }