Skip to content

Commit

Permalink
Migrated to manifest v3
Browse files Browse the repository at this point in the history
  • Loading branch information
gignupg committed Dec 29, 2023
1 parent 4d9f2f8 commit 4dc5716
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
4 changes: 2 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ chrome.runtime.onMessage.addListener(

// Shortcut (Alt + S by default)
chrome.commands.onCommand.addListener((command) => {
chrome.storage.sync.get(null, (storage) => {
chrome.storage.local.get((storage) => {
const extensionOn = storage.power ? storage.power.status : true;

if (extensionOn && command === 'focus-search-bar') {
Expand All @@ -29,7 +29,7 @@ chrome.commands.onCommand.addListener((command) => {
// On Tab Change
chrome.tabs.onActivated.addListener(() => {
chrome.tabs.query({ currentWindow: true, active: true }, function (tab) {
chrome.storage.sync.get(null, (storage) => {
chrome.storage.local.get((storage) => {
const extensionOn = storage.power ? storage.power.status : true;
const autofocus = storage.autofocus || {};
let thisSite = tab[0].url.replace(/^.*\/\//, "").replace(/\/.*/, "");
Expand Down
4 changes: 2 additions & 2 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Autofocus when loading a website
chrome.storage.sync.get(null, (storage) => {
chrome.storage.local.get((storage) => {
const extensionOn = storage.power ? storage.power.status : true;

// Autofocus on?
Expand All @@ -16,7 +16,7 @@ chrome.storage.sync.get(null, (storage) => {

// Listen for Tab Press
document.addEventListener("keydown", (e) => {
chrome.storage.sync.get(null, (storage) => {
chrome.storage.local.get((storage) => {
const extensionOn = storage.power ? storage.power.status : true;
const tabOn = storage.tabulation ? storage.tabulation.status : true;
const tabList = storage.tabList || {};
Expand Down
19 changes: 13 additions & 6 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Search Box Focus",
"version": "0.3.5",
"manifest_version": 2,
"manifest_version": 3,
"description": "Press Tab to quickly access the main search bar or search field of any website. No need to use your mouse! Autofocus available!",
"icons": {
"16": "icons/icons8-google-web-search-16.png",
Expand All @@ -15,7 +15,7 @@
"js": ["content.js"]
}
],
"browser_action": {
"action": {
"default_icon": {
"16": "icons/icons8-google-web-search-16.png",
"48": "icons/icons8-google-web-search-48.png",
Expand All @@ -24,8 +24,7 @@
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"],
"persistent": false
"service_worker": "background.js"
},
"commands": {
"focus-search-bar": {
Expand All @@ -35,6 +34,14 @@
"description": "Search Box Focus"
}
},
"content_security_policy": "script-src 'self'; object-src 'self'",
"web_accessible_resources": ["icons/*.png"]
"content_security_policy": {
"script-src": "self",
"object-src": "self"
},
"web_accessible_resources": [
{
"resources": ["/images/icon.png"],
"matches": ["<all_urls>"]
}
]
}
12 changes: 6 additions & 6 deletions popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ $("#logo").addEventListener("click", () => {
chrome.tabs.create({ active: true, url: "https://chrome.google.com/webstore/detail/search-box-focus-hit-tab/amgmdnojamodmpfjaokfgpijhpcednjm" });
});

chrome.storage.sync.get(null, (storage) => {
chrome.storage.local.get((storage) => {
extensionOn = storage.power ? storage.power.status : true;
tabOn = storage.tabulation ? storage.tabulation.status : true;
tabList = storage.tabList || {};
Expand All @@ -45,7 +45,7 @@ chrome.storage.sync.get(null, (storage) => {

function updatePopup() {
const suffix = `${extensionOn ? "" : "_disabled"}.png`;
chrome.browserAction.setIcon({
chrome.action.setIcon({
path: {
"16": "icons/icons8-google-web-search-16" + suffix,
"48": "icons/icons8-google-web-search-48" + suffix,
Expand Down Expand Up @@ -143,13 +143,13 @@ function updateAutofocusList() {
}

// Update chrome storage
chrome.storage.sync.set({ autofocus: autofocus });
chrome.storage.local.set({ autofocus: autofocus });
}

function toggleExtensionOnOff() {
extensionOn = !extensionOn;
updatePopup();
chrome.storage.sync.set({ power: { status: extensionOn } });
chrome.storage.local.set({ power: { status: extensionOn } });
}

function tabPermanentlyOnOff() {
Expand All @@ -169,7 +169,7 @@ function tabPermanentlyOnOff() {
}

updateDisplayedShortcuts();
chrome.storage.sync.set({ tabulation: { status: tabOn } });
chrome.storage.local.set({ tabulation: { status: tabOn } });
}

function toggleTabOnOff() {
Expand All @@ -183,7 +183,7 @@ function toggleTabOnOff() {
}

updateDisplayedShortcuts();
chrome.storage.sync.set({ tabList: tabList });
chrome.storage.local.set({ tabList: tabList });
}

function $(selector, multiple = false) {
Expand Down

0 comments on commit 4dc5716

Please sign in to comment.