From 57ab98c0b6fda595e1659ef75345f3175b982d60 Mon Sep 17 00:00:00 2001 From: howanghk Date: Thu, 28 Jul 2022 19:43:12 +0800 Subject: [PATCH] - migrate to manifest_version 3 --- LICENSE.md | 2 +- README.md | 6 +++--- background.js | 29 +++++++++++++++++++++++++++++ eventPage.js | 17 ----------------- manifest.json | 14 +++++++------- 5 files changed, 40 insertions(+), 28 deletions(-) create mode 100644 background.js delete mode 100644 eventPage.js diff --git a/LICENSE.md b/LICENSE.md index 33497fe..6ca4cbe 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,4 +1,4 @@ -Copyright (c) 2015 howang +Copyright (c) 2015-2022 howanghk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/README.md b/README.md index 03188b0..6845615 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ Refresh Active Frame ==================== -This extension let you refresh a frame with keyborad shoutcut (Cmd+Ctrl+R on Mac, Alt+Shift+R otherwise), if no frame is active it will fallback to refresh the whole page. +This extension let you refresh a frame with keyboard shortcut (Cmd+Ctrl+R on Mac, Alt+Shift+R otherwise), if no frame is active it will fallback to refresh the whole page. Install ------- -[![available in the chrome web store](https://developer.chrome.com/webstore/images/ChromeWebStore_BadgeWBorder_v2_206x58.png)](https://chrome.google.com/webstore/detail/refresh-active-frame/imcfppeifknphfhaibbbidhnjecmfohi) +[![available in the chrome web store](https://storage.googleapis.com/web-dev-uploads/image/WlD8wC6g8khYWPJUsQceQkhXSlv1/UV4C4ybeBTsZt43U4xis.png)](https://chrome.google.com/webstore/detail/refresh-active-frame/imcfppeifknphfhaibbbidhnjecmfohi) Manual Install -------------- @@ -17,7 +17,7 @@ Manual Install License ------- -Copyright (c) 2015 howang <howanghk at gmail dot com> +Copyright (c) 2015-2022 howanghk Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/background.js b/background.js new file mode 100644 index 0000000..385e3c5 --- /dev/null +++ b/background.js @@ -0,0 +1,29 @@ + +// ref: https://developer.chrome.com/docs/extensions/reference/tabs/#get-the-current-tab +async function getCurrentTab() { + let queryOptions = { active: true, lastFocusedWindow: true }; + // `tab` will either be a `tabs.Tab` instance or `undefined`. + let [tab] = await chrome.tabs.query(queryOptions); + return tab; +} + +function refreshActiveFrameInTab(tab) { + chrome.scripting.executeScript({ + target: { tabId: tab.id }, + files: ['refresh_active_frame.js'] + }); +} + +chrome.action.onClicked.addListener((tab) => { + refreshActiveFrameInTab(tab); +}); + +chrome.commands.onCommand.addListener(async (cmd) => { + if (cmd == 'refresh-active-frame') { + let tab = await getCurrentTab(); + if (!tab) { + return; + } + refreshActiveFrameInTab(tab); + } +}); diff --git a/eventPage.js b/eventPage.js deleted file mode 100644 index a599041..0000000 --- a/eventPage.js +++ /dev/null @@ -1,17 +0,0 @@ - -var refreshActiveFrameInCurrentTab = function () { - chrome.tabs.executeScript({ - file: 'refresh_active_frame.js' - }); -}; - -chrome.browserAction.onClicked.addListener(function(tab) { - refreshActiveFrameInCurrentTab(); -}); - -chrome.commands.onCommand.addListener(function(cmd) { - if (cmd == 'refresh-active-frame') - { - refreshActiveFrameInCurrentTab(); - } -}); diff --git a/manifest.json b/manifest.json index f18b4d2..3c0e560 100644 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,9 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "Refresh Active Frame", - "description": "This extension let you refresh a frame with keyborad shoutcut (Cmd+Ctrl+R on Mac, Alt+Shift+R otherwise), if no frame is active it will fallback to refresh the whole page", - "version": "1.0", + "description": "Refresh active frame or ifrmae with keyboard shortcut, fallback to refresh page if active element is not a frame", + "version": "1.1", "icons": { "128": "icon-128.png" }, @@ -11,11 +11,10 @@ "homepage_url": "https://www.howang.hk/", "background": { - "scripts": ["eventPage.js"], - "persistent": false + "service_worker": "background.js" }, - "browser_action": { + "action": { "default_icon": "icon-19.png", "default_title": "Refresh Active Frame" }, @@ -31,6 +30,7 @@ }, "permissions": [ - "activeTab" + "activeTab", + "scripting" ] }