From 6dbe57d978780df063b578dde15cf7b279bfed9d Mon Sep 17 00:00:00 2001 From: Alyssa X Date: Tue, 11 Jan 2022 16:13:08 +0000 Subject: [PATCH] Add Omni on install without reloading --- src/background.js | 28 ++++++++++++++++++++++++++++ src/manifest.json | 4 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/background.js b/src/background.js index 97196a2..cf62644 100644 --- a/src/background.js +++ b/src/background.js @@ -1,5 +1,33 @@ var actions = []; +// Inject Omni on install +chrome.manifest = chrome.runtime.getManifest(); +var injectIntoTab = function (tab) { + var scripts = chrome.manifest.content_scripts[0].js; + var i = 0, s = scripts.length; + for( ; i < s; i++ ) { + chrome.scripting.executeScript({ + target: {tabId: tab.id}, + files: [scripts[i]] + }); + } +} + +// Get all windows +chrome.windows.getAll({ + populate: true +}, function (windows) { + var i = 0, w = windows.length, currentWindow; + for( ; i < w; i++ ) { + currentWindow = windows[i]; + var j = 0, t = currentWindow.tabs.length, currentTab; + for( ; j < t; j++ ) { + currentTab = currentWindow.tabs[j]; + injectIntoTab(currentTab); + } + } +}); + // Clear actions and append default ones function clearActions() { getCurrentTab().then((response) => { diff --git a/src/manifest.json b/src/manifest.json index 00bbe05..dacc7cc 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "name": "Omni", "description": "Supercharge Chrome with commands, shortcuts, and more", "offline_enabled": true, - "version": "1.0.1", + "version": "1.0.2", "manifest_version": 3, "action": { "icons": { @@ -45,7 +45,7 @@ } ], "permissions": [ - "tabs", "activeTab", "bookmarks", "browsingData", "history" + "tabs", "activeTab", "bookmarks", "browsingData", "history", "scripting" ], "host_permissions": [ "https://www.googleapis.com/*", "https://gstatic.com/*", "*://*/*"