Browse Source

Avoid global variable

tags/v0.1.0
Gerben 5 years ago
parent
commit
bf4aafb452
3 changed files with 11 additions and 15 deletions
  1. +1
    -6
      app/audio-player/contentscript.js
  2. +1
    -7
      app/create-bookmarks/contentscript.js
  3. +9
    -2
      app/scripts/contentscript.js

+ 1
- 6
app/audio-player/contentscript.js View File

@@ -4,7 +4,7 @@ import html from 'nanohtml'

import { parseMediaFragmentIdentifier } from '../util/media-fragment-identifier.js';

async function init() {
export default async function init() {
document.body.innerHTML = '';

const mainEl = html`
@@ -88,8 +88,3 @@ async function init() {

return playlist;
}

init().then(playlist => {
// Store playlist as a shared global variable.
self.playlist = playlist;
});

+ 1
- 7
app/create-bookmarks/contentscript.js View File

@@ -27,7 +27,7 @@ function describeMediaFragment({ start, end }) {
return selector;
}

async function init() {
export default async function init(playlist) {
let menuEl;

function hideMenu() {
@@ -41,10 +41,6 @@ async function init() {
const left = event.pageX;
const top = event.pageY;

const playlist = self.playlist;
if (!playlist) {
throw new Error('Player has not been initialised.');
}
const trackDuration = playlist.duration;
let { start, end } = playlist.getTimeSelection();
if (start === undefined) return;
@@ -84,5 +80,3 @@ async function init() {

document.addEventListener('click', event => { hideMenu(); });
}

init();

+ 9
- 2
app/scripts/contentscript.js View File

@@ -1,2 +1,9 @@
import '../audio-player/contentscript.js'
import '../create-bookmarks/contentscript.js'
import initAudioPlayer from '../audio-player/contentscript.js';
import initCreateBookmarks from '../create-bookmarks/contentscript.js';

async function init() {
const playlist = await initAudioPlayer();
await initCreateBookmarks(playlist);
}

init();

Loading…
Cancel
Save