Browse Source

Refactor context menu

tags/v0.1.0
Gerben 4 years ago
parent
commit
436937ac1a
1 changed files with 21 additions and 8 deletions
  1. +21
    -8
      app/create-bookmarks/contentscript.js

+ 21
- 8
app/create-bookmarks/contentscript.js View File

@@ -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`
<ul class="context-menu" style="top: ${top}; left: ${left};">
${menuItems.map(({ title, action }) => html`
<li>
<button onclick=${() => { hideMenu(); createBookmark(); }}>
${browser.i18n.getMessage(end !== undefined
? 'bookmarkSelectionContextMenuItemForFragment'
: 'bookmarkSelectionContextMenuItemForSingleMoment'
)}
<button onclick=${event => { hideMenu(); action(event); }}>
${title}
</button>
</li>
`)}
</ul>
`;

document.body.appendChild(menuEl);
}



Loading…
Cancel
Save