From 5fe31ac703c0509b54de21548540d26aaf4f204d Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Sun, 18 Apr 2021 02:32:56 +1000 Subject: [PATCH] bugfix tab management for menu, transfer to mod folder, start menu mockup --- extension/content-loader.js | 7 - extension/{src => }/helpers.js | 105 ++++++++++-- extension/launcher.js | 20 +++ extension/manifest.json | 4 +- .../client.css | 2 +- .../client.js | 21 +++ .../menu.css | 147 ++++++++++++++++ .../menu.html | 159 ++++++++++++++++++ .../menu.js | 34 ++++ .../mod.json | 22 +++ extension/repo/registry.json | 2 +- .../client.css | 2 +- .../mod.json | 5 +- .../variables.css | 2 +- extension/src/gui.html | 9 - extension/src/launcher.js | 36 ---- extension/worker.js | 52 ++++-- 17 files changed, 539 insertions(+), 90 deletions(-) delete mode 100644 extension/content-loader.js rename extension/{src => }/helpers.js (74%) create mode 100644 extension/launcher.js rename extension/{src => repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e}/client.css (97%) create mode 100644 extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.js create mode 100644 extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.css create mode 100644 extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.html create mode 100644 extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.js create mode 100644 extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/mod.json delete mode 100644 extension/src/gui.html delete mode 100644 extension/src/launcher.js diff --git a/extension/content-loader.js b/extension/content-loader.js deleted file mode 100644 index 42971d7..0000000 --- a/extension/content-loader.js +++ /dev/null @@ -1,7 +0,0 @@ -/* - * notion-enhancer - * (c) 2021 dragonwocky (https://dragonwocky.me/) - * (https://notion-enhancer.github.io/) under the MIT license - */ - -import(chrome.runtime.getURL('src/launcher.js')).then((launcher) => launcher.default()); diff --git a/extension/src/helpers.js b/extension/helpers.js similarity index 74% rename from extension/src/helpers.js rename to extension/helpers.js index 32f421c..2dbfb56 100644 --- a/extension/src/helpers.js +++ b/extension/helpers.js @@ -5,9 +5,15 @@ */ 'use strict'; -const ERROR = Symbol(); +export const ERROR = Symbol(); + +export const env = {}; +env.name = 'browser'; + +env.openEnhancerMenu = () => chrome.runtime.sendMessage({ type: 'enhancerMenu.open' }); + +export const web = {}; -const web = {}; web.whenReady = (selectors = [], callback = () => {}) => { return new Promise((res, rej) => { function onLoad() { @@ -29,11 +35,20 @@ web.whenReady = (selectors = [], callback = () => {}) => { } else onLoad(); }); }; + +/** + * @param {string} html + * @returns HTMLElement + */ web.createElement = (html) => { const template = document.createElement('template'); template.innerHTML = html.trim(); return template.content.firstElementChild; }; + +/** + * @param {string} sheet + */ web.loadStyleset = (sheet) => { document.head.appendChild( web.createElement(``) @@ -41,25 +56,53 @@ web.loadStyleset = (sheet) => { return true; }; -// +/** + * @param {array} keys + * @param {function} callback + */ +web.hotkeyListener = (keys, callback) => { + if (!web._hotkeyListener) { + web._hotkeys = []; + web._hotkeyListener = document.addEventListener('keyup', (event) => { + for (let hotkey of web._hotkeys) { + const matchesEvent = hotkey.keys.every((key) => { + const modifiers = { + altKey: 'alt', + ctrlKey: 'ctrl', + metaKey: 'meta', + shiftKey: 'shift', + }; + for (let modifier in modifiers) { + if (key.toLowerCase() === modifiers[modifier] && event[modifier]) return true; + } + const pressedKeycode = [event.key.toLowerCase(), event.code.toLowerCase()]; + if (pressedKeycode.includes(key.toLowerCase())) return true; + }); + if (matchesEvent) hotkey.callback(); + } + }); + } + web._hotkeys.push({ keys, callback }); +}; -const fs = {}; +export const fs = {}; +/** + * @param {string} path + */ fs.getJSON = (path) => fetch(chrome.runtime.getURL(path)).then((res) => res.json()); fs.getText = (path) => fetch(chrome.runtime.getURL(path)).then((res) => res.text()); fs.isFile = async (path) => { try { - await fetch(chrome.runtime.getURL(`/repo/${path}`)); + await fetch(chrome.runtime.getURL(`repo/${path}`)); return true; } catch { return false; } }; -// - -const regexers = { +export const regexers = { uuid(str) { const match = str.match(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i); if (match && match.length) return true; @@ -92,9 +135,7 @@ const regexers = { }, }; -// - -const registry = {}; +export const registry = {}; registry.validate = async (mod, err, check) => Promise.all( @@ -135,7 +176,7 @@ registry.validate = async (mod, err, check) => ).then((css) => { if (css === ERROR) return ERROR; if (!css) return undefined; - return ['frame', 'client', 'gui'] + return ['frame', 'client', 'menu'] .filter((dest) => css[dest]) .map(async (dest) => check(`css.${dest}`, css[dest], Array.isArray(css[dest])).then((files) => @@ -208,7 +249,7 @@ registry.validate = async (mod, err, check) => if (filepath === ERROR) return ERROR; if (!filepath) return undefined; try { - const options = await fs.getJSON(`/repo/${mod._dir}/${mod.options}`); + const options = await fs.getJSON(`repo/${mod._dir}/${mod.options}`); // todo: validate options } catch { err(`invalid options ${filepath}`); @@ -220,10 +261,10 @@ registry.validate = async (mod, err, check) => registry.get = async (callback = () => {}) => { registry._list = []; if (!registry._errors) registry._errors = []; - for (const dir of await fs.getJSON('/repo/registry.json')) { + for (const dir of await fs.getJSON('repo/registry.json')) { const err = (message) => [registry._errors.push({ source: dir, message }), ERROR][1]; try { - const mod = await fs.getJSON(`/repo/${dir}/mod.json`); + const mod = await fs.getJSON(`repo/${dir}/mod.json`); mod._dir = dir; mod.tags = mod.tags ?? []; mod.css = mod.css ?? []; @@ -247,4 +288,36 @@ registry.errors = async (callback = () => {}) => { return registry._errors; }; -export { web, fs, regexers, registry }; +export const markdown = {}; + +markdown.simple = (string) => + string + .split('\n') + .map((line) => + line + .trim() + .replace(/\s+/g, ' ') + // > quote + .replace(/^>\s+(.+)$/g, '
$1
') + // ~~strikethrough~~ + .replace(/([^\\])?~~((?:(?!~~).)*[^\\])~~/g, '$1$2') + // __underline__ + .replace(/([^\\])?__((?:(?!__).)*[^\\])__/g, '$1$2') + // **bold** + .replace(/([^\\])?\*\*((?:(?!\*\*).)*[^\\])\*\*/g, '$1$2') + // *italic* + .replace(/([^\\])?\*([^*]*[^\\*])\*/g, '$1$2') + // _italic_ + .replace(/([^\\])?_([^_]*[^\\_])_/g, '$1$2') + // `code` + .replace(/([^\\])?`([^`]*[^\\`])`/g, '$1$2') + // ![image_title](source) + .replace( + /([^\\])?\!\[([^\]]*[^\\\]]?)\]\(([^)]*[^\\)])\)/g, + `$1$2` + ) + // [link](destination) + .replace(/([^\\])?\[([^\]]*[^\\\]]?)\]\(([^)]*[^\\)])\)/g, '$1$2') + ) + .map((line) => (line.startsWith('
') ? line : `

${line}

`)) + .join(''); diff --git a/extension/launcher.js b/extension/launcher.js new file mode 100644 index 0000000..5a716c4 --- /dev/null +++ b/extension/launcher.js @@ -0,0 +1,20 @@ +/* + * notion-enhancer + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +'use strict'; + +import(chrome.runtime.getURL('helpers.js')).then(({ web, registry }) => { + web.whenReady([], async () => { + for (let mod of await registry.get()) { + for (let sheet of mod.css?.client || []) { + web.loadStyleset(`repo/${mod._dir}/${sheet}`); + } + for (let script of mod.js?.client || []) { + import(chrome.runtime.getURL(`repo/${mod._dir}/${script}`)); + } + } + }); +}); diff --git a/extension/manifest.json b/extension/manifest.json index 7740325..d8c8acb 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -17,14 +17,14 @@ }, "web_accessible_resources": [ { - "resources": ["icons/*", "src/*", "repo/*"], + "resources": ["icons/*", "repo/*", "helpers.js"], "matches": ["https://*.notion.so/*"] } ], "content_scripts": [ { "matches": ["https://*.notion.so/*"], - "js": ["content-loader.js"] + "js": ["launcher.js"] } ], "host_permissions": ["https://*.notion.so/*"] diff --git a/extension/src/client.css b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.css similarity index 97% rename from extension/src/client.css rename to extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.css index 2e4ecc7..e5f03a1 100644 --- a/extension/src/client.css +++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.css @@ -1,5 +1,5 @@ /* - * notion-enhancer + * notion-enhancer core: menu * (c) 2021 dragonwocky (https://dragonwocky.me/) * (https://notion-enhancer.github.io/) under the MIT license */ diff --git a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.js b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.js new file mode 100644 index 0000000..308c806 --- /dev/null +++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/client.js @@ -0,0 +1,21 @@ +/* + * notion-enhancer core: menu + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +'use strict'; + +import { web, fs, env } from '../../helpers.js'; + +const sidebarSelector = + '#notion-app > div > div.notion-cursor-listener > div.notion-sidebar-container > div > div > div > div:nth-child(4)'; +web.whenReady([sidebarSelector], async () => { + const enhancerIcon = await fs.getText('icons/colour.svg'), + enhancerSidebarElement = web.createElement( + `
${enhancerIcon}
notion-enhancer
` + ); + enhancerSidebarElement.addEventListener('click', env.openEnhancerMenu); + document.querySelector(sidebarSelector).appendChild(enhancerSidebarElement); +}); +web.hotkeyListener(['Ctrl', 'Alt', 'E'], env.openEnhancerMenu); diff --git a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.css b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.css new file mode 100644 index 0000000..8f73b7b --- /dev/null +++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.css @@ -0,0 +1,147 @@ +/* + * notion-enhancer core: menu + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +* { + box-sizing: border-box; + word-break: break-word; + text-size-adjust: 100%; + font-family: var(--theme--font_sans); + color: var(--theme--text); +} + +body { + padding: 1.5rem; + background: var(--theme--sidebar); +} + +header { + display: flex; + margin-bottom: 1.25rem; +} +header > * { + margin: 0 1.25rem 0 0; + font-size: 1.25rem; +} +header img { + height: 100%; + width: 24px; +} +header h1 a:not([data-active]) { + text-decoration: none; +} + +main section[data-container='library'] { + display: grid; + grid-gap: 1.25em; + grid-template-columns: 1fr 1fr 1fr; +} +main section[data-container='library'] article { + border-radius: 5px; + box-shadow: rgb(0 0 0 / 10%) 0px 20px 25px -5px, rgb(0 0 0 / 4%) 0px 10px 10px -5px; + border: 1px solid var(--theme--divider); + background: var(--theme--page); +} +main section[data-container='library'] article > img { + max-width: 100%; + border-bottom: 1px solid var(--theme--divider); +} +main section[data-container='library'] article > div { + padding: 1em; + border-bottom: 1px solid var(--theme--divider); +} +.library--title { + margin: 0; +} +.library--version { + font-weight: normal; + font-size: 0.8rem; + border-radius: 5px; + padding: 0.125rem 0.25rem; + background: var(--theme--tag_default); + color: var(--theme--tag_default-text); +} +.library--toggle_label { + align-items: center; + display: flex; + cursor: pointer; +} +.library--toggle { + position: relative; + margin-left: auto; +} +.library--toggle { + width: 2rem; + height: 1.25rem; + display: block; + border-radius: 9999px; + background: var(--theme--toggle_off); +} +.library--toggle::after { + content: ''; + transition: transform 200ms ease-out 0s, background 200ms ease-out 0s; + height: 0.85rem; + width: 0.8rem; + left: 0.18rem; + top: 0.175rem; + position: absolute; + border-radius: 9999px; + background: var(--theme--toggle_dot); +} +.library--toggle_label input[type='checkbox']:checked ~ .library--toggle { + background: var(--theme--toggle_on); +} +.library--toggle_label input[type='checkbox']:checked ~ .library--toggle::after { + transform: translateX(100%); +} +.library--toggle_label input[type='checkbox'] { + position: absolute; + width: 1px; + height: 1px; + padding: 0; + margin: -1px; + overflow: hidden; + clip: rect(0, 0, 0, 0); + white-space: nowrap; + border-width: 0; +} +.library--description { + font-size: 0.8rem; +} +.library--tags, +.library--authors { + padding: 0; + list-style-type: none; + display: flex; + margin: 0.5em 0; +} +.library--tags li { + margin: 0 0.5rem 0 0; + opacity: 0.7; +} +.library--authors li { + margin: 0 0.5rem 0 0; +} +.library--authors a { + font-size: 0.8rem; + text-decoration: none; + border-radius: 5px; + padding: 0.125rem 0.25rem 0.25rem 0.25rem; + background: var(--theme--tag_default); + color: var(--theme--tag_default-text); +} +.library--authors img { + height: 1em; + width: 1em; + margin-bottom: 0.15625em; + display: inline-block; + vertical-align: middle; + border-radius: 50%; + object-fit: cover; +} + +main section:not([data-active]) { + display: none; +} diff --git a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.html b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.html new file mode 100644 index 0000000..1d9a768 --- /dev/null +++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.html @@ -0,0 +1,159 @@ + + + + + + + notion-enhancer + + +
+

+

library

+

alerts

+

documentation

+
+
+
+
+
+ +
    +
  • #core
  • +
  • #extension
  • +
  • #customisation
  • +
+

+ link files for small client-side tweaks. (not sure how to do something? check out + the + tweaks + collection.) +

+ +
+
+
+ +
+ +
    +
  • #core
  • +
  • #theme
  • +
  • #dark
  • +
+

a vivid-colour near-black theme

+ +
+
+
+
+ +
    +
  • #core
  • +
  • #extension
  • +
  • #customisation
  • +
+

+ link files for small client-side tweaks. (not sure how to do something? check out + the + tweaks + collection.) +

+ +
+
+
+
+ +
    +
  • #core
  • +
  • #extension
  • +
  • #customisation
  • +
+

+ link files for small client-side tweaks. (not sure how to do something? check out + the + tweaks + collection.) +

+ +
+
+
+
+
documentation
+
+ + + diff --git a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.js b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.js new file mode 100644 index 0000000..ef25fe8 --- /dev/null +++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.js @@ -0,0 +1,34 @@ +/* + * notion-enhancer core: menu + * (c) 2021 dragonwocky (https://dragonwocky.me/) + * (https://notion-enhancer.github.io/) under the MIT license + */ + +'use strict'; + +import { web, fs, registry } from '../../helpers.js'; + +for (let mod of await registry.get()) { + for (let sheet of mod.css?.menu || []) { + web.loadStyleset(`repo/${mod._dir}/${sheet}`); + } +} + +const tabs = ['library', 'alerts', 'documentation'].map((tab) => ({ + title: document.querySelector(`header [data-target="${tab}"]`), + container: document.querySelector(`main [data-container="${tab}"]`), +})); +tabs.forEach((tab) => { + tab.title.addEventListener('click', (event) => { + tabs.forEach((_tab) => { + _tab.title.removeAttribute('data-active'); + _tab.container.removeAttribute('data-active'); + }); + tab.title.dataset.active = true; + tab.container.dataset.active = true; + }); +}); + +// registry.errors().then((err) => { +// document.querySelector('[data-section="alerts"]').innerHTML = JSON.stringify(err); +// }); diff --git a/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/mod.json b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/mod.json new file mode 100644 index 0000000..867a13f --- /dev/null +++ b/extension/repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/mod.json @@ -0,0 +1,22 @@ +{ + "name": "menu", + "id": "a6621988-551d-495a-97d8-3c568bca2e9e", + "description": "the enhancer's graphical menu, related buttons and shortcuts.", + "version": "0.11.0", + "tags": ["core"], + "authors": [ + { + "name": "dragonwocky", + "email": "thedragonring.bod@gmail.com", + "url": "https://dragonwocky.me/", + "icon": "https://dragonwocky.me/avatar.jpg" + } + ], + "css": { + "client": ["client.css"], + "menu": ["menu.css"] + }, + "js": { + "client": ["client.js"] + } +} diff --git a/extension/repo/registry.json b/extension/repo/registry.json index 8e458ec..3a9ca07 100644 --- a/extension/repo/registry.json +++ b/extension/repo/registry.json @@ -1 +1 @@ -["theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082"] +["menu@a6621988-551d-495a-97d8-3c568bca2e9e", "theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082"] diff --git a/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/client.css b/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/client.css index de31a55..e95863a 100644 --- a/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/client.css +++ b/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/client.css @@ -1,5 +1,5 @@ /* - * notion-enhancer + * notion-enhancer core: theming * (c) 2021 dragonwocky (https://dragonwocky.me/) * (c) 2020 TarasokUA * (c) 2020 Arecsu diff --git a/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/mod.json b/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/mod.json index 462711d..18e169e 100644 --- a/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/mod.json +++ b/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/mod.json @@ -3,7 +3,7 @@ "id": "0f0bf8b6-eae6-4273-b307-8fc43f2ee082", "description": "the default theme variables, required by other themes & extensions.", "version": "0.11.0", - "tags": ["core", "theme"], + "tags": ["core"], "authors": [ { "name": "dragonwocky", @@ -13,6 +13,7 @@ } ], "css": { - "client": ["client.css"] + "client": ["client.css"], + "menu": ["variables.css"] } } diff --git a/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/variables.css b/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/variables.css index 94c959d..e943da0 100644 --- a/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/variables.css +++ b/extension/repo/theming@0f0bf8b6-eae6-4273-b307-8fc43f2ee082/variables.css @@ -1,5 +1,5 @@ /* - * notion-enhancer + * notion-enhancer core: theming * (c) 2021 dragonwocky (https://dragonwocky.me/) * (c) 2020 TarasokUA * (c) 2020 Arecsu diff --git a/extension/src/gui.html b/extension/src/gui.html deleted file mode 100644 index 9edc684..0000000 --- a/extension/src/gui.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - notion-enhancer - - -

Hello, World!

- - diff --git a/extension/src/launcher.js b/extension/src/launcher.js deleted file mode 100644 index ef576ef..0000000 --- a/extension/src/launcher.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * notion-enhancer - * (c) 2021 dragonwocky (https://dragonwocky.me/) - * (https://notion-enhancer.github.io/) under the MIT license - */ - -'use strict'; - -import { web, fs, registry } from './helpers.js'; - -export default () => { - web.whenReady([], async () => { - web.loadStyleset('/src/client.css'); - for (let mod of await registry.get()) { - for (let sheet of mod.css?.client || []) { - web.loadStyleset(`/repo/${mod._dir}/${sheet}`); - } - for (let script of mod.js?.client || []) { - import(chrome.runtime.getURL(`/repo/${mod._dir}/${script}`)); - } - } - }); - - const sidebarSelector = - '#notion-app > div > div.notion-cursor-listener > div.notion-sidebar-container > div > div > div > div:nth-child(4)'; - web.whenReady([sidebarSelector], async () => { - const enhancerIcon = await fs.getText('/icons/colour.svg'), - enhancerSidebarElement = web.createElement( - `
${enhancerIcon}
notion-enhancer
` - ); - enhancerSidebarElement.addEventListener('click', (event) => - chrome.runtime.sendMessage({ type: 'openEnhancerMenu' }) - ); - document.querySelector(sidebarSelector).appendChild(enhancerSidebarElement); - }); -}; diff --git a/extension/worker.js b/extension/worker.js index 1dca318..215b540 100644 --- a/extension/worker.js +++ b/extension/worker.js @@ -6,26 +6,50 @@ 'use strict'; -let _enhancerMenuTab; -async function openEnhancerMenu() { - if (!_enhancerMenuTab) { - _enhancerMenuTab = await new Promise((res, rej) => { +const enhancerMenu = { + _tab: {}, + highlight() { + return new Promise((res, rej) => + chrome.tabs.get(this._tab.id, async (tab) => { + if (chrome.runtime.lastError) { + chrome.tabs.highlight({ 'tabs': (await this.create()).index }); + } else { + chrome.tabs.highlight({ 'tabs': tab.index }); + } + res(this._tab); + }) + ); + }, + create() { + return new Promise((res, rej) => chrome.tabs.create( { - url: chrome.runtime.getURL('/src/gui.html'), + url: chrome.runtime.getURL( + 'repo/menu@a6621988-551d-495a-97d8-3c568bca2e9e/menu.html' + ), }, - res - ); - }); - } - chrome.tabs.highlight({ 'tabs': _enhancerMenuTab.index }, function () {}); -} -chrome.action.onClicked.addListener(openEnhancerMenu); + (tab) => { + this._tab = tab; + res(this._tab); + } + ) + ); + }, + async open() { + try { + await this.highlight(); + } catch { + await this.create(); + } + return this._tab; + }, +}; +chrome.action.onClicked.addListener(enhancerMenu.open); chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { switch (request.type) { - case 'openEnhancerMenu': - openEnhancerMenu(); + case 'enhancerMenu.open': + enhancerMenu.open(); break; } return true;