From d7870b17015df9235f5055b5099589072138f92c Mon Sep 17 00:00:00 2001 From: amysteam Date: Mon, 13 Mar 2023 14:31:55 -0500 Subject: [PATCH 01/10] First draft --- api-samples/action/demo/index.html | 1 - .../tutorial.omnibox-api/content.css | 20 ++++ .../tutorial.omnibox-api/content.js | 28 +++++ .../tutorial.omnibox-api/icon-128.png | Bin 0 -> 7057 bytes .../tutorial.omnibox-api/icon-16.png | Bin 0 -> 7057 bytes .../tutorial.omnibox-api/manifest.json | 26 +++++ .../tutorial.omnibox-api/sw-api-list.js | 106 ++++++++++++++++++ .../tutorial.omnibox-api/sw-omnibox.js | 39 +++++++ .../tutorial.omnibox-api/sw-tips.js | 28 +++++ functional-samples/tutorial.omnibox-api/sw.js | 2 + 10 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 functional-samples/tutorial.omnibox-api/content.css create mode 100644 functional-samples/tutorial.omnibox-api/content.js create mode 100644 functional-samples/tutorial.omnibox-api/icon-128.png create mode 100644 functional-samples/tutorial.omnibox-api/icon-16.png create mode 100644 functional-samples/tutorial.omnibox-api/manifest.json create mode 100644 functional-samples/tutorial.omnibox-api/sw-api-list.js create mode 100644 functional-samples/tutorial.omnibox-api/sw-omnibox.js create mode 100644 functional-samples/tutorial.omnibox-api/sw-tips.js create mode 100644 functional-samples/tutorial.omnibox-api/sw.js diff --git a/api-samples/action/demo/index.html b/api-samples/action/demo/index.html index 287e8d56dd..f577a33803 100644 --- a/api-samples/action/demo/index.html +++ b/api-samples/action/demo/index.html @@ -173,7 +173,6 @@

Badge Text Color

-
diff --git a/functional-samples/tutorial.omnibox-api/content.css b/functional-samples/tutorial.omnibox-api/content.css new file mode 100644 index 0000000000..4a399bd46c --- /dev/null +++ b/functional-samples/tutorial.omnibox-api/content.css @@ -0,0 +1,20 @@ +#tip-popover { + color:blue; +} + +/* [popover] { + --hide: 1; + transition: transform 0.2s; + transform: translateY(calc(var(--hide) * -100vh)) + scale(calc(1 - var(--hide))); +} + +[popover]::backdrop { + transition: opacity 0.2s; + opacity: calc(1 - var(--hide, 1)); +} + +[popover]:open, +[popover]:open::backdrop { + --hide: 0; +} */ \ No newline at end of file diff --git a/functional-samples/tutorial.omnibox-api/content.js b/functional-samples/tutorial.omnibox-api/content.js new file mode 100644 index 0000000000..5a1276344b --- /dev/null +++ b/functional-samples/tutorial.omnibox-api/content.js @@ -0,0 +1,28 @@ +// Popover API https://chromestatus.com/feature/5463833265045504 + +const nav = document.querySelector('.navigation-rail__links'); + +chrome.runtime.sendMessage({ greeting: 'tip' }).then(({ tip }) => { + const tipWidget = createDomElement(` + + + + Tip + + `); + + const popover = createDomElement(` +
${tip}
+ `); + + document.body.append(popover); + nav.append(tipWidget); +}); + +function createDomElement(html) { + const dom = new DOMParser().parseFromString(html, 'text/html'); + return dom.body.firstElementChild; +} diff --git a/functional-samples/tutorial.omnibox-api/icon-128.png b/functional-samples/tutorial.omnibox-api/icon-128.png new file mode 100644 index 0000000000000000000000000000000000000000..8fb1368633a771bf1adc750fb74ddaf67a98f407 GIT binary patch literal 7057 zcmb7JbzD{3wq6@HE#1APL15Fd>F!1)g-vfsVIv^jf+(Ssw9*ZV2$Is>jkJWcbU!%f z+wW`Y3JTMfF4l!@}s908fA|FUn_0U13x6_s1<=?b%g$;-&= zC@b;X^C}v`ghcr{pTcVq=AMy%+lGB8*b%nVa@I7=yI0{5ch=LnvT{;IKXmy;XgpF#c+N8Z}a(iP!?L^wM^?&88N zoZXQU3=DUP{yF~KClX=vuS`yEf0cDxAoOkp%FE3I{ckjDPsIO0yIc7`X}4$e&$9k4 znJ3)kPtqTU@#h}J?{)w))U|eVc5uI|MN(8q{Euz@oAX~q{Yj8>c64#Ic5}NU2>ylt zyYD~o2LCO=-<^LW+!Y6V=w|JD8_?0(2`TyiXf1K*|6>0w^6kmMv$KQb zf4v*x(Eo(}M+6OLD};@gJRE5)d3TMtcy3=o{eN7eKk0wN{KXcB-ZjbJn&!`r{KI?O zl9JfB#DBE6B=(bvCcGW65)g*b)EggK8U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Z+IF zVQ6bRL04Bcn}4BZs;33j4GK1{7(!xy z6nt&?fl4pB=6Sf0Nd)>iwc#cWIyu+k*A4{ga@%tZs&iG^}IxiH>)HW0`8*`>8Gag(%3rpX6Ye@2hjr!weN z-;M`KfF6!_th+sK1J^lzhpiGnN3qLfq~W_Tj74ZKw9DRv!h90A^)9#Fyk3%yRUEsYq`s-e zGe*1ln(@o=jHGW}(VIGseGU{K&n`r>)d>%$8rfTH^G6q#uyD_mmTSfpv>I+GXO(>q zdca$}?OI9`dy4IfH6s8*se1>d9l2z;!t+?HzEknvDUrU?<^Jw|({RIR@q#xLn z4UMrQtU0PaRCDU*fXlhWYib&*(~dh4F|18IBTF|R7JiHVquH>5yT3&$3YzkzvgSem E1324-?*IS* literal 0 HcmV?d00001 diff --git a/functional-samples/tutorial.omnibox-api/icon-16.png b/functional-samples/tutorial.omnibox-api/icon-16.png new file mode 100644 index 0000000000000000000000000000000000000000..4537f9d574bc8ccd0fa7e756e664630cc3b3f9d1 GIT binary patch literal 7057 zcmb7JbzD{3wq6@HE#1APL15Fd>F!1)g-vfsVIv^jf+(Ssw9*ZV2$Is>jkJWcbU!%f z+wW`Y3JTMfF4l!@}s908fA|FUn_0U13x6_s1<=?b%g$;-&= zC@b;X^C}v`ghcr{pTc}gF}$Toq*yW z;86nrDhQ!(fHcrhhgmv1a>K2hEv&gc9bN7+0pgypThq}R35R$(Iykw(JS7Zu;>cUOS-K)zkO*fd$X#5x zg|jK(LcwZ`$Qsa{*}qe?XR+K3xwXSKzX@&p#P0#?TPq5Xm>0BC++r({#n+) zCG&*4{7L%bF#g=5_}va*hPu{n&JON(wMdEziT|;!e{=q;s6PpE&WlPAcXoD= z{I7RI9QvQI|A?UBY=yA#l7}O$CGV~g7tif0sQ-^^^e6pqn7`QK(7Pu2Thsj6k$-q^ zTT&AHmiUkMmc*u}&AA5v{dT?QuNqE{sON*sr1WEM?$M)Pwg@Br ztO5hg@jl*Ppw8MN-F(G5nEna8zPV}t3i;bqdt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00ZNqQP&H^I#^*!Dxm<{B}x|rxh#!hX&8Za9M(oSvI@dz1(FK$mbAfb=82~ixyF);Q6? z!-3XpJp}l!`GpP|>_)}-Qs}2(xnfTVeSL>cbSwLa42B#DI<}U3>he3;bNzfi2prN6 zH&h>1MJCNNbrK-ZK;@pE;jU|HJNr}^Z?Tgyw1oxn+mC+{X`~0O@D8j0$YR1zHckpm zJq&GaC+OOXbBdG6(7097Ii-eX4NMwcDAR~vlReVq#5F_yG|U|jc7<$vkwY+e6GKSs zkAklaKTzpK*E|n5GKoMxr#9TAK_};0d|dFF>to5ZH-7)a&l#WWL`Sx95`Ulwq{4!y z1)nfExmp~lbd)x$`cwv; z>f7-k3DCpwj&--kZQwe`@32+k=O}iWj5K@~hOr3kg?8DSazz~VXLdB{E9AcuFvhFX zv@P@LoDG1IU=r$`N7qAL^;u^f?;BfC@sQ{-M4!jM)d-10_XFSrsg-?a=|aGGap;LY zVDsc^p`(-IRd?T9F;OOVJ9fN)hbgA0caiaB2v%lG*rS;plxLjHm)A?uv5I5&lhil0 zc*bZqUo(C=o{{veD|%DMvCo0xy%~<*c&r zK@WI~w_QtVg0CPLLD$+7oWgWtfzObQNV1BZq7}D$v}H*7+@>y}y9Ki1Y)S zvY|0{gf&OihiXp!9B?_8cuh@1b=q+!B8IhzXJqLH#KLdUe>595aQC-JML|=(RMtG` Fe*nUEgvbB@ literal 0 HcmV?d00001 diff --git a/functional-samples/tutorial.omnibox-api/manifest.json b/functional-samples/tutorial.omnibox-api/manifest.json new file mode 100644 index 0000000000..646363c987 --- /dev/null +++ b/functional-samples/tutorial.omnibox-api/manifest.json @@ -0,0 +1,26 @@ +{ + "manifest_version": 3, + "name": "Open extension API docs", + "version": "1.0.0", + "icons": { + "16": "icon-16.png", + "128": "icon-128.png" + }, + "background": { + "service_worker": "sw.js", + "type": "module" + }, + "content_scripts": [ + { + "matches": ["https://developer.chrome.com/docs/extensions/*"], + "js": ["content.js"], + "css": ["content.css"] + } + ], + "minimum_chrome_version": "102", + "omnibox": { + "keyword": "api" + }, + "permissions": ["alarms", "storage"], + "host_permissions": ["https://extension-tips.glitch.me/*"] +} diff --git a/functional-samples/tutorial.omnibox-api/sw-api-list.js b/functional-samples/tutorial.omnibox-api/sw-api-list.js new file mode 100644 index 0000000000..27b0095f17 --- /dev/null +++ b/functional-samples/tutorial.omnibox-api/sw-api-list.js @@ -0,0 +1,106 @@ +const apiList = [ + { + content: 'commands', + description: + 'Use the Commands API to add a keyboard shortcuts.' + }, + { + content: 'contextmenus', + description: + "Use the ContextMenus API to add a custom item to Chrome's context menu." + }, + { + content: 'declarativeNetRequest', + description: + 'Use the DeclarativeNetRequest API to block or modify network requests.' + }, + { + content: 'downloads', + description: + 'Use the Downloads API to programmatically manipulate downloads.' + }, + { + content: 'i18n', + description: 'Use the i18n API to localize your extension' + }, + { + content: 'identity', + description: + 'Use the Identity API to get OAuth2 access tokens.' + }, + { + content: 'notifications', + description: + 'Use the Notifications API show notifications to users in the system tray.' + }, + { + content: 'offscreen', + description: + 'Use the Offscreen API to create and manage offscreen documents.' + }, + { + content: 'omnibox', + description: + "Use the Omnibox API to register a keyword with Chrome's address bar." + }, + { + content: 'permissions', + description: + 'Use the Permissions API to request optional permissions at run time.' + }, + { + content: 'runtime', + description: + 'Use the Runtime API pass messages, manage extension lifecycle, and access other helper utils.' + }, + { + content: 'scripting', + description: + 'Use the Scripting API to execute scripts in different contexts.' + }, + { + content: 'storage', + description: + 'Use the Storage API to store, retrieve, and track changes to user data.' + }, + { + content: 'tabs', + description: + 'Use the Tabs API to create, update and manipulate tabs.' + }, + { + content: 'topSites', + description: + 'Use the TopSites API to access the most visited sites that are displayed on the new tab page.' + }, + { + content: 'webNavigation', + description: + 'Use the WebNavigation API to receive notifications about the status of navigation requests in-flight.' + } +]; + +export async function getAPIsuggestions(input) { + const result = []; + for (const api of apiList) { + if (api.content.startsWith(input)) { + result.push(api); + console.log('pushing api', api); + } + } + + if (result.length) { + await chrome.omnibox.setDefaultSuggestion({ + description: 'Matching Chrome APIs' + }); + console.log('result', result); + return result; + } else { + await chrome.omnibox.setDefaultSuggestion({ + description: 'No matches found. Choose from past searches' + }); + // get defaults if no match + const { apiSugg } = await chrome.storage.local.get('apiSugg'); + return apiList.filter((item) => apiSugg.includes(item.content)); + } +} diff --git a/functional-samples/tutorial.omnibox-api/sw-omnibox.js b/functional-samples/tutorial.omnibox-api/sw-omnibox.js new file mode 100644 index 0000000000..69691c0f86 --- /dev/null +++ b/functional-samples/tutorial.omnibox-api/sw-omnibox.js @@ -0,0 +1,39 @@ +import { getAPIsuggestions } from './sw-api-list.js'; + +console.log('sw-omnibox.js'); + +// Save default API suggestions +chrome.runtime.onInstalled.addListener(({ reason }) => { + if (reason === 'install') { + chrome.storage.local.set({ apiSugg: ['tabs', 'storage', 'scripting'] }); + } +}); + +// OMNIBOX LOGIC +const chromeURL = 'https://developer.chrome.com/docs/extensions/reference/'; + +chrome.omnibox.onInputChanged.addListener(async (input, suggest) => { + const suggestions = await getAPIsuggestions(input); + console.log('suggestions', suggestions); + suggest(suggestions); +}); + +/* + Set omnibox to make suggestions of top APIs + when user selects one or types one open URLs +*/ +chrome.omnibox.onInputEntered.addListener(async (input) => { + await chrome.tabs.create({ url: chromeURL + input }); + updateHistory(input); +}); + +async function updateHistory(input) { + try { + const { apiSugg } = await chrome.storage.local.get('apiSugg'); + apiSugg.unshift(input); + apiSugg.splice(4); + await chrome.storage.local.set({ apiSugg }); + } catch (error) { + console.error(error); + } +} diff --git a/functional-samples/tutorial.omnibox-api/sw-tips.js b/functional-samples/tutorial.omnibox-api/sw-tips.js new file mode 100644 index 0000000000..3fe7a249e1 --- /dev/null +++ b/functional-samples/tutorial.omnibox-api/sw-tips.js @@ -0,0 +1,28 @@ +console.log('sw-tips.js'); + +// Fetch tip & save in storage +const updateTip = async () => { + const response = await fetch('https://extension-tips.glitch.me/tips.json'); + const tips = await response.json(); + const index = Math.floor(Math.random() * tips.length); + await chrome.storage.local.set({ tip: tips[index] }); +}; + +// Create a daily alarm to retrieve a new tip +chrome.runtime.onInstalled.addListener(({ reason }) => { + if (reason === 'install') { + chrome.alarms.create({ delayInMinutes: 1, periodInMinutes: 1440 }); + updateTip(); + } +}); + +// TIP OF THE DAY +chrome.alarms.onAlarm.addListener(updateTip); + +// LISTEN FOR TIP REQUEST +chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { + if (message.greeting === 'tip') { + chrome.storage.local.get('tip').then(sendResponse); + return true; + } +}); diff --git a/functional-samples/tutorial.omnibox-api/sw.js b/functional-samples/tutorial.omnibox-api/sw.js new file mode 100644 index 0000000000..1af54df209 --- /dev/null +++ b/functional-samples/tutorial.omnibox-api/sw.js @@ -0,0 +1,2 @@ +import './sw-omnibox.js'; +import './sw-tips.js'; From d02fb15c8a980b0a128e504fd33eda5980d141ed Mon Sep 17 00:00:00 2001 From: amysteam Date: Tue, 14 Mar 2023 14:16:01 -0500 Subject: [PATCH 02/10] Rename folder --- .../tutorial.omnibox-api/content.css | 20 ------------------ .../content.js | 0 .../icon-128.png | Bin .../icon-16.png | Bin .../manifest.json | 13 ++++++------ .../sw-api-list.js | 2 +- .../sw-omnibox.js | 0 .../sw-tips.js | 0 .../sw.js | 0 9 files changed, 7 insertions(+), 28 deletions(-) delete mode 100644 functional-samples/tutorial.omnibox-api/content.css rename functional-samples/{tutorial.omnibox-api => tutorial.open-api-reference}/content.js (100%) rename functional-samples/{tutorial.omnibox-api => tutorial.open-api-reference}/icon-128.png (100%) rename functional-samples/{tutorial.omnibox-api => tutorial.open-api-reference}/icon-16.png (100%) rename functional-samples/{tutorial.omnibox-api => tutorial.open-api-reference}/manifest.json (89%) rename functional-samples/{tutorial.omnibox-api => tutorial.open-api-reference}/sw-api-list.js (98%) rename functional-samples/{tutorial.omnibox-api => tutorial.open-api-reference}/sw-omnibox.js (100%) rename functional-samples/{tutorial.omnibox-api => tutorial.open-api-reference}/sw-tips.js (100%) rename functional-samples/{tutorial.omnibox-api => tutorial.open-api-reference}/sw.js (100%) diff --git a/functional-samples/tutorial.omnibox-api/content.css b/functional-samples/tutorial.omnibox-api/content.css deleted file mode 100644 index 4a399bd46c..0000000000 --- a/functional-samples/tutorial.omnibox-api/content.css +++ /dev/null @@ -1,20 +0,0 @@ -#tip-popover { - color:blue; -} - -/* [popover] { - --hide: 1; - transition: transform 0.2s; - transform: translateY(calc(var(--hide) * -100vh)) - scale(calc(1 - var(--hide))); -} - -[popover]::backdrop { - transition: opacity 0.2s; - opacity: calc(1 - var(--hide, 1)); -} - -[popover]:open, -[popover]:open::backdrop { - --hide: 0; -} */ \ No newline at end of file diff --git a/functional-samples/tutorial.omnibox-api/content.js b/functional-samples/tutorial.open-api-reference/content.js similarity index 100% rename from functional-samples/tutorial.omnibox-api/content.js rename to functional-samples/tutorial.open-api-reference/content.js diff --git a/functional-samples/tutorial.omnibox-api/icon-128.png b/functional-samples/tutorial.open-api-reference/icon-128.png similarity index 100% rename from functional-samples/tutorial.omnibox-api/icon-128.png rename to functional-samples/tutorial.open-api-reference/icon-128.png diff --git a/functional-samples/tutorial.omnibox-api/icon-16.png b/functional-samples/tutorial.open-api-reference/icon-16.png similarity index 100% rename from functional-samples/tutorial.omnibox-api/icon-16.png rename to functional-samples/tutorial.open-api-reference/icon-16.png diff --git a/functional-samples/tutorial.omnibox-api/manifest.json b/functional-samples/tutorial.open-api-reference/manifest.json similarity index 89% rename from functional-samples/tutorial.omnibox-api/manifest.json rename to functional-samples/tutorial.open-api-reference/manifest.json index 646363c987..8db381e6e9 100644 --- a/functional-samples/tutorial.omnibox-api/manifest.json +++ b/functional-samples/tutorial.open-api-reference/manifest.json @@ -10,17 +10,16 @@ "service_worker": "sw.js", "type": "module" }, - "content_scripts": [ - { - "matches": ["https://developer.chrome.com/docs/extensions/*"], - "js": ["content.js"], - "css": ["content.css"] - } - ], "minimum_chrome_version": "102", "omnibox": { "keyword": "api" }, "permissions": ["alarms", "storage"], + "content_scripts": [ + { + "matches": ["https://developer.chrome.com/docs/extensions/reference/*"], + "js": ["content.js"] + } + ], "host_permissions": ["https://extension-tips.glitch.me/*"] } diff --git a/functional-samples/tutorial.omnibox-api/sw-api-list.js b/functional-samples/tutorial.open-api-reference/sw-api-list.js similarity index 98% rename from functional-samples/tutorial.omnibox-api/sw-api-list.js rename to functional-samples/tutorial.open-api-reference/sw-api-list.js index 27b0095f17..5cb71ea15d 100644 --- a/functional-samples/tutorial.omnibox-api/sw-api-list.js +++ b/functional-samples/tutorial.open-api-reference/sw-api-list.js @@ -99,7 +99,7 @@ export async function getAPIsuggestions(input) { await chrome.omnibox.setDefaultSuggestion({ description: 'No matches found. Choose from past searches' }); - // get defaults if no match + // Retrieve defaults if keyword has no matches const { apiSugg } = await chrome.storage.local.get('apiSugg'); return apiList.filter((item) => apiSugg.includes(item.content)); } diff --git a/functional-samples/tutorial.omnibox-api/sw-omnibox.js b/functional-samples/tutorial.open-api-reference/sw-omnibox.js similarity index 100% rename from functional-samples/tutorial.omnibox-api/sw-omnibox.js rename to functional-samples/tutorial.open-api-reference/sw-omnibox.js diff --git a/functional-samples/tutorial.omnibox-api/sw-tips.js b/functional-samples/tutorial.open-api-reference/sw-tips.js similarity index 100% rename from functional-samples/tutorial.omnibox-api/sw-tips.js rename to functional-samples/tutorial.open-api-reference/sw-tips.js diff --git a/functional-samples/tutorial.omnibox-api/sw.js b/functional-samples/tutorial.open-api-reference/sw.js similarity index 100% rename from functional-samples/tutorial.omnibox-api/sw.js rename to functional-samples/tutorial.open-api-reference/sw.js From e1f7e31ba424713c06e32ea9ca96d22e9ee19c5a Mon Sep 17 00:00:00 2001 From: amysteam Date: Tue, 14 Mar 2023 14:26:21 -0500 Subject: [PATCH 03/10] Tweak comments --- .../tutorial.open-api-reference/sw-omnibox.js | 9 +++------ .../tutorial.open-api-reference/sw-tips.js | 6 +++--- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/functional-samples/tutorial.open-api-reference/sw-omnibox.js b/functional-samples/tutorial.open-api-reference/sw-omnibox.js index 69691c0f86..fa7d33e3f4 100644 --- a/functional-samples/tutorial.open-api-reference/sw-omnibox.js +++ b/functional-samples/tutorial.open-api-reference/sw-omnibox.js @@ -9,21 +9,18 @@ chrome.runtime.onInstalled.addListener(({ reason }) => { } }); -// OMNIBOX LOGIC const chromeURL = 'https://developer.chrome.com/docs/extensions/reference/'; +// Displays the suggestions after user starts typing chrome.omnibox.onInputChanged.addListener(async (input, suggest) => { const suggestions = await getAPIsuggestions(input); - console.log('suggestions', suggestions); suggest(suggestions); }); -/* - Set omnibox to make suggestions of top APIs - when user selects one or types one open URLs -*/ +// Opens the reference page of the chosen API chrome.omnibox.onInputEntered.addListener(async (input) => { await chrome.tabs.create({ url: chromeURL + input }); + // Saves the latest keyword updateHistory(input); }); diff --git a/functional-samples/tutorial.open-api-reference/sw-tips.js b/functional-samples/tutorial.open-api-reference/sw-tips.js index 3fe7a249e1..6ff9f44062 100644 --- a/functional-samples/tutorial.open-api-reference/sw-tips.js +++ b/functional-samples/tutorial.open-api-reference/sw-tips.js @@ -8,7 +8,7 @@ const updateTip = async () => { await chrome.storage.local.set({ tip: tips[index] }); }; -// Create a daily alarm to retrieve a new tip +// Create a daily alarm and retrieves the first tip when extension is installed. chrome.runtime.onInstalled.addListener(({ reason }) => { if (reason === 'install') { chrome.alarms.create({ delayInMinutes: 1, periodInMinutes: 1440 }); @@ -16,10 +16,10 @@ chrome.runtime.onInstalled.addListener(({ reason }) => { } }); -// TIP OF THE DAY +// Retrieve tip of the day chrome.alarms.onAlarm.addListener(updateTip); -// LISTEN FOR TIP REQUEST +// Send tip to content script via messaging chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.greeting === 'tip') { chrome.storage.local.get('tip').then(sendResponse); From 00b7667ceee9ea0f439ec8bc15e21292dcf349f5 Mon Sep 17 00:00:00 2001 From: amysteamdev <37001393+AmySteam@users.noreply.github.com> Date: Tue, 14 Mar 2023 14:49:38 -0500 Subject: [PATCH 04/10] Update index.html --- api-samples/action/demo/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/api-samples/action/demo/index.html b/api-samples/action/demo/index.html index f577a33803..287e8d56dd 100644 --- a/api-samples/action/demo/index.html +++ b/api-samples/action/demo/index.html @@ -173,6 +173,7 @@

Badge Text Color

+
From ceb4e80ad1c1c2e548900a591f139777f1451d83 Mon Sep 17 00:00:00 2001 From: amysteam Date: Tue, 14 Mar 2023 14:51:17 -0500 Subject: [PATCH 05/10] remove extra closing div --- functional-samples/tutorial.open-api-reference/content.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functional-samples/tutorial.open-api-reference/content.js b/functional-samples/tutorial.open-api-reference/content.js index 5a1276344b..566abd5f60 100644 --- a/functional-samples/tutorial.open-api-reference/content.js +++ b/functional-samples/tutorial.open-api-reference/content.js @@ -8,7 +8,7 @@ chrome.runtime.sendMessage({ greeting: 'tip' }).then(({ tip }) => { + Tip From f058253b68141349c43909cccdcb36dc0feb1c89 Mon Sep 17 00:00:00 2001 From: amysteam Date: Wed, 15 Mar 2023 10:38:20 -0500 Subject: [PATCH 06/10] Rename sw file --- functional-samples/tutorial.open-api-reference/manifest.json | 4 ++-- .../tutorial.open-api-reference/{sw.js => service-worker.js} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename functional-samples/tutorial.open-api-reference/{sw.js => service-worker.js} (100%) diff --git a/functional-samples/tutorial.open-api-reference/manifest.json b/functional-samples/tutorial.open-api-reference/manifest.json index 8db381e6e9..e88d16a118 100644 --- a/functional-samples/tutorial.open-api-reference/manifest.json +++ b/functional-samples/tutorial.open-api-reference/manifest.json @@ -1,13 +1,13 @@ { "manifest_version": 3, - "name": "Open extension API docs", + "name": "Open extension API reference", "version": "1.0.0", "icons": { "16": "icon-16.png", "128": "icon-128.png" }, "background": { - "service_worker": "sw.js", + "service_worker": "service-worker.js", "type": "module" }, "minimum_chrome_version": "102", diff --git a/functional-samples/tutorial.open-api-reference/sw.js b/functional-samples/tutorial.open-api-reference/service-worker.js similarity index 100% rename from functional-samples/tutorial.open-api-reference/sw.js rename to functional-samples/tutorial.open-api-reference/service-worker.js From 8b3c991327e5811474a0f04e41f8f4257dce0ccb Mon Sep 17 00:00:00 2001 From: amysteam Date: Wed, 15 Mar 2023 14:56:59 -0500 Subject: [PATCH 07/10] Apply first round of @sebastianbenz suggestions --- .../{sw-api-list.js => api-list.js} | 27 +---------------- .../tutorial.open-api-reference/content.js | 30 ++++++++++--------- .../tutorial.open-api-reference/sw-omnibox.js | 28 ++++++++--------- .../sw-suggestions.js | 24 +++++++++++++++ .../tutorial.open-api-reference/sw-tips.js | 4 +-- 5 files changed, 56 insertions(+), 57 deletions(-) rename functional-samples/tutorial.open-api-reference/{sw-api-list.js => api-list.js} (75%) create mode 100644 functional-samples/tutorial.open-api-reference/sw-suggestions.js diff --git a/functional-samples/tutorial.open-api-reference/sw-api-list.js b/functional-samples/tutorial.open-api-reference/api-list.js similarity index 75% rename from functional-samples/tutorial.open-api-reference/sw-api-list.js rename to functional-samples/tutorial.open-api-reference/api-list.js index 5cb71ea15d..72554e9c8a 100644 --- a/functional-samples/tutorial.open-api-reference/sw-api-list.js +++ b/functional-samples/tutorial.open-api-reference/api-list.js @@ -1,4 +1,4 @@ -const apiList = [ +export default [ { content: 'commands', description: @@ -79,28 +79,3 @@ const apiList = [ 'Use the WebNavigation API to receive notifications about the status of navigation requests in-flight.' } ]; - -export async function getAPIsuggestions(input) { - const result = []; - for (const api of apiList) { - if (api.content.startsWith(input)) { - result.push(api); - console.log('pushing api', api); - } - } - - if (result.length) { - await chrome.omnibox.setDefaultSuggestion({ - description: 'Matching Chrome APIs' - }); - console.log('result', result); - return result; - } else { - await chrome.omnibox.setDefaultSuggestion({ - description: 'No matches found. Choose from past searches' - }); - // Retrieve defaults if keyword has no matches - const { apiSugg } = await chrome.storage.local.get('apiSugg'); - return apiList.filter((item) => apiSugg.includes(item.content)); - } -} diff --git a/functional-samples/tutorial.open-api-reference/content.js b/functional-samples/tutorial.open-api-reference/content.js index 566abd5f60..c7c82bb67e 100644 --- a/functional-samples/tutorial.open-api-reference/content.js +++ b/functional-samples/tutorial.open-api-reference/content.js @@ -1,26 +1,28 @@ // Popover API https://chromestatus.com/feature/5463833265045504 -const nav = document.querySelector('.navigation-rail__links'); +(async () => { + const nav = document.querySelector('.navigation-rail__links'); + + const { tip } = await chrome.runtime.sendMessage({ greeting: 'tip' }); -chrome.runtime.sendMessage({ greeting: 'tip' }).then(({ tip }) => { const tipWidget = createDomElement(` - - - Tip - + + + Tip + `); - const popover = createDomElement(` -
${tip}
- `); + const popover = createDomElement( + `
${tip}
` + ); document.body.append(popover); nav.append(tipWidget); -}); +})(); function createDomElement(html) { const dom = new DOMParser().parseFromString(html, 'text/html'); diff --git a/functional-samples/tutorial.open-api-reference/sw-omnibox.js b/functional-samples/tutorial.open-api-reference/sw-omnibox.js index fa7d33e3f4..cea1c04167 100644 --- a/functional-samples/tutorial.open-api-reference/sw-omnibox.js +++ b/functional-samples/tutorial.open-api-reference/sw-omnibox.js @@ -1,36 +1,34 @@ -import { getAPIsuggestions } from './sw-api-list.js'; - -console.log('sw-omnibox.js'); +import { getApiSuggestions } from './sw-suggestions'; // Save default API suggestions chrome.runtime.onInstalled.addListener(({ reason }) => { if (reason === 'install') { - chrome.storage.local.set({ apiSugg: ['tabs', 'storage', 'scripting'] }); + chrome.storage.local.set({ + apiSuggestions: ['tabs', 'storage', 'scripting'] + }); } }); const chromeURL = 'https://developer.chrome.com/docs/extensions/reference/'; +const NUMBER_OF_PREVIOUS_SEARCHES = 4; // Displays the suggestions after user starts typing chrome.omnibox.onInputChanged.addListener(async (input, suggest) => { - const suggestions = await getAPIsuggestions(input); + const { description, suggestions } = await getApiSuggestions(input); + await chrome.omnibox.setDefaultSuggestion({ description }); suggest(suggestions); }); // Opens the reference page of the chosen API -chrome.omnibox.onInputEntered.addListener(async (input) => { - await chrome.tabs.create({ url: chromeURL + input }); +chrome.omnibox.onInputEntered.addListener((input) => { + chrome.tabs.create({ url: chromeURL + input }); // Saves the latest keyword updateHistory(input); }); async function updateHistory(input) { - try { - const { apiSugg } = await chrome.storage.local.get('apiSugg'); - apiSugg.unshift(input); - apiSugg.splice(4); - await chrome.storage.local.set({ apiSugg }); - } catch (error) { - console.error(error); - } + const { apiSuggestions } = await chrome.storage.local.get('apiSuggestions'); + apiSuggestions.unshift(input); + apiSuggestions.splice(NUMBER_OF_PREVIOUS_SEARCHES); + await chrome.storage.local.set({ apiSuggestions }); } diff --git a/functional-samples/tutorial.open-api-reference/sw-suggestions.js b/functional-samples/tutorial.open-api-reference/sw-suggestions.js new file mode 100644 index 0000000000..2e44408651 --- /dev/null +++ b/functional-samples/tutorial.open-api-reference/sw-suggestions.js @@ -0,0 +1,24 @@ +import apiList from './api-list.js'; + +/** + * Returns a list of suggestions and a description for the default suggestion + */ +export async function getApiSuggestions(input) { + const filtered = apiList.filter((api) => api.content.startsWith(input)); + console.log('filtered', filtered); + + // return suggestions if any exist + if (filtered.length) { + return { + description: 'Matching Chrome APIs', + suggestions: filtered + }; + } + + // return past searches if no match was found + const { apiSuggestions } = await chrome.storage.local.get('apiSuggestions'); + return { + description: 'No matches found. Choose from past searches', + suggestions: apiList.filter((item) => apiSuggestions.includes(item.content)) + }; +} diff --git a/functional-samples/tutorial.open-api-reference/sw-tips.js b/functional-samples/tutorial.open-api-reference/sw-tips.js index 6ff9f44062..912d236dd3 100644 --- a/functional-samples/tutorial.open-api-reference/sw-tips.js +++ b/functional-samples/tutorial.open-api-reference/sw-tips.js @@ -4,8 +4,8 @@ console.log('sw-tips.js'); const updateTip = async () => { const response = await fetch('https://extension-tips.glitch.me/tips.json'); const tips = await response.json(); - const index = Math.floor(Math.random() * tips.length); - await chrome.storage.local.set({ tip: tips[index] }); + const randomIndex = Math.floor(Math.random() * tips.length); + await chrome.storage.local.set({ tip: tips[randomIndex] }); }; // Create a daily alarm and retrieves the first tip when extension is installed. From 5f378716c16fb60ce74639f523b56f57a5468166 Mon Sep 17 00:00:00 2001 From: amysteam Date: Wed, 15 Mar 2023 16:50:23 -0500 Subject: [PATCH 08/10] Fix import --- functional-samples/tutorial.open-api-reference/sw-omnibox.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/functional-samples/tutorial.open-api-reference/sw-omnibox.js b/functional-samples/tutorial.open-api-reference/sw-omnibox.js index cea1c04167..6517272202 100644 --- a/functional-samples/tutorial.open-api-reference/sw-omnibox.js +++ b/functional-samples/tutorial.open-api-reference/sw-omnibox.js @@ -1,4 +1,6 @@ -import { getApiSuggestions } from './sw-suggestions'; +import { getApiSuggestions } from './sw-suggestions.js'; + +console.log('sw-omnibox.js'); // Save default API suggestions chrome.runtime.onInstalled.addListener(({ reason }) => { From 48f8772f529c60cb209d6b5460d3b6d9d036b3d1 Mon Sep 17 00:00:00 2001 From: amysteam Date: Thu, 16 Mar 2023 14:22:20 -0500 Subject: [PATCH 09/10] Update popover --- functional-samples/tutorial.open-api-reference/content.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/functional-samples/tutorial.open-api-reference/content.js b/functional-samples/tutorial.open-api-reference/content.js index c7c82bb67e..1a5f65d449 100644 --- a/functional-samples/tutorial.open-api-reference/content.js +++ b/functional-samples/tutorial.open-api-reference/content.js @@ -6,14 +6,14 @@ const { tip } = await chrome.runtime.sendMessage({ greeting: 'tip' }); const tipWidget = createDomElement(` - + `); const popover = createDomElement( From 6b13a54641e8562bbca398eea4c936f8c53f765c Mon Sep 17 00:00:00 2001 From: amysteam Date: Fri, 17 Mar 2023 09:33:26 -0500 Subject: [PATCH 10/10] Second tech review round --- .../tutorial.open-api-reference/sw-omnibox.js | 7 ++++--- .../tutorial.open-api-reference/sw-suggestions.js | 7 +++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/functional-samples/tutorial.open-api-reference/sw-omnibox.js b/functional-samples/tutorial.open-api-reference/sw-omnibox.js index 6517272202..005869bf40 100644 --- a/functional-samples/tutorial.open-api-reference/sw-omnibox.js +++ b/functional-samples/tutorial.open-api-reference/sw-omnibox.js @@ -2,7 +2,7 @@ import { getApiSuggestions } from './sw-suggestions.js'; console.log('sw-omnibox.js'); -// Save default API suggestions +// Initialize default API suggestions chrome.runtime.onInstalled.addListener(({ reason }) => { if (reason === 'install') { chrome.storage.local.set({ @@ -11,7 +11,8 @@ chrome.runtime.onInstalled.addListener(({ reason }) => { } }); -const chromeURL = 'https://developer.chrome.com/docs/extensions/reference/'; +const URL_CHROME_EXTENSIONS_DOC = + 'https://developer.chrome.com/docs/extensions/reference/'; const NUMBER_OF_PREVIOUS_SEARCHES = 4; // Displays the suggestions after user starts typing @@ -23,7 +24,7 @@ chrome.omnibox.onInputChanged.addListener(async (input, suggest) => { // Opens the reference page of the chosen API chrome.omnibox.onInputEntered.addListener((input) => { - chrome.tabs.create({ url: chromeURL + input }); + chrome.tabs.create({ url: URL_CHROME_EXTENSIONS_DOC + input }); // Saves the latest keyword updateHistory(input); }); diff --git a/functional-samples/tutorial.open-api-reference/sw-suggestions.js b/functional-samples/tutorial.open-api-reference/sw-suggestions.js index 2e44408651..42dd477a9d 100644 --- a/functional-samples/tutorial.open-api-reference/sw-suggestions.js +++ b/functional-samples/tutorial.open-api-reference/sw-suggestions.js @@ -4,14 +4,13 @@ import apiList from './api-list.js'; * Returns a list of suggestions and a description for the default suggestion */ export async function getApiSuggestions(input) { - const filtered = apiList.filter((api) => api.content.startsWith(input)); - console.log('filtered', filtered); + const suggestions = apiList.filter((api) => api.content.startsWith(input)); // return suggestions if any exist - if (filtered.length) { + if (suggestions.length) { return { description: 'Matching Chrome APIs', - suggestions: filtered + suggestions: suggestions }; }