From 436937ac1aec1c866c579c0abdfc1b83eeec3273 Mon Sep 17 00:00:00 2001 From: Gerben Date: Mon, 18 Nov 2019 17:55:03 +0100 Subject: [PATCH] Refactor context menu --- app/create-bookmarks/contentscript.js | 29 +++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/create-bookmarks/contentscript.js b/app/create-bookmarks/contentscript.js index 4d7bb06..f765a81 100644 --- a/app/create-bookmarks/contentscript.js +++ b/app/create-bookmarks/contentscript.js @@ -53,26 +53,39 @@ export default async function init(playlist) { start = Math.round(Math.max(0, start) * 100) / 100; if (end !== undefined) end = Math.round(Math.max(0, end) * 100) / 100; - async function createBookmark() { + function preciseUrl() { const fileUrl = document.URL; const selector = describeMediaFragment({ start, end }); - const bookmarkUrl = createPreciseUrl(fileUrl, selector); - await remoteFunction('createBookmark')({ url: bookmarkUrl, start, end, trackDuration }); + const preciseUrl = createPreciseUrl(fileUrl, selector); + return preciseUrl; } + const menuItems = [ + { + title: browser.i18n.getMessage(end !== undefined + ? 'bookmarkSelectionContextMenuItemForFragment' + : 'bookmarkSelectionContextMenuItemForSingleMoment' + ), + async action() { + await remoteFunction('createBookmark')({ url: preciseUrl(), start, end, trackDuration }); + }, + }, + ]; + hideMenu(); + menuEl = html` `; + document.body.appendChild(menuEl); }