From 35c26bf9160c1fb0e9c25e2cdc939887acfeb0f8 Mon Sep 17 00:00:00 2001 From: Jakob Linskeseder Date: Mon, 8 Jul 2019 16:25:43 +0200 Subject: [PATCH] Auto-detect embedded media links Resolves #7 --- src/_locales/de/messages.json | 9 ++++--- src/_locales/en/messages.json | 15 ++++++----- src/modules/Options.js | 5 +++- src/modules/plugins/EmbeddedMediaLink.js | 32 ++++++++++++++++++++++++ src/modules/views/main/options.js | 22 ++++++++++++++-- src/pages/popup/main.css | 2 +- 6 files changed, 72 insertions(+), 13 deletions(-) create mode 100644 src/modules/plugins/EmbeddedMediaLink.js diff --git a/src/_locales/de/messages.json b/src/_locales/de/messages.json index d0f1af4..32134d4 100644 --- a/src/_locales/de/messages.json +++ b/src/_locales/de/messages.json @@ -83,15 +83,18 @@ "optionsReplayNotifications": { "message": "Wiederholungsbenachrichtigung" }, + "optionsAutoDetectEmbeddedMediaLinks": { + "message": "Eingebettete Media-Links automatisch erkennen" + }, + "optionsExperimental": { + "message": "Experimentell" + }, "optionsReloadInfo": { "message": "Es kann sein, dass du die Extension neu laden musst, wenn du Einstellungen geändert hast:" }, "optionsReloadButton": { "message": "Extension neu laden" }, - "optionsExperimental": { - "message": "Experimentell" - }, "menuPlay": { "message": "► Abspielen" }, diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 010749e..c35907f 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -68,12 +68,12 @@ "footerOptions": { "message": "Options" }, - "optionsUser": { - "message": "User" - }, "optionsDeviceName": { "message": "Device name" }, + "optionsUser": { + "message": "User" + }, "optionsPassword": { "message": "Password" }, @@ -83,15 +83,18 @@ "optionsReplayNotifications": { "message": "Replay notification" }, + "optionsAutoDetectEmbeddedMediaLinks": { + "message": "Auto-detect embedded media links" + }, "optionsExperimental": { + "message": "Experimental" + }, + "optionsReloadInfo": { "message": "You may have to reload the extension if you changed a setting:" }, "optionsReloadButton": { "message": "Reload extension" }, - "optionsFirefoxBug": { - "message": "Experimental" - }, "menuPlay": { "message": "► Play" }, diff --git a/src/modules/Options.js b/src/modules/Options.js index 59ce4a3..38f2953 100644 --- a/src/modules/Options.js +++ b/src/modules/Options.js @@ -16,6 +16,7 @@ export default class Options { }, ]; this.replayNotification = false; // Opt-in (requires optional permission) + this.autoDetectEmbeddedMediaLinks = true; } async getFormStorage() { @@ -27,7 +28,8 @@ export default class Options { this.devices[0].port = options.devices[0].port || WEBSOCKET_DEFAULT_PORT; this.devices[0].user = options.devices[0].user || ''; this.devices[0].password = options.devices[0].password || ''; - this.replayNotification = options.replayNotification; + this.replayNotification = options.replayNotification || false; + this.autoDetectEmbeddedMediaLinks = options.autoDetectEmbeddedMediaLinks || true; } catch (e) { // There are no options set yet. // Since we provide default `null` values this is okay. @@ -39,6 +41,7 @@ export default class Options { options: { devices: this.devices, replayNotification: this.replayNotification, + autoDetectEmbeddedMediaLinks: this.autoDetectEmbeddedMediaLinks, }, }); diff --git a/src/modules/plugins/EmbeddedMediaLink.js b/src/modules/plugins/EmbeddedMediaLink.js new file mode 100644 index 0000000..a7a19b7 --- /dev/null +++ b/src/modules/plugins/EmbeddedMediaLink.js @@ -0,0 +1,32 @@ +import WebPlugin from './WebPlugin.js'; +import { executeScriptInActiveTab } from './../utils/tabs.js'; + +/** + * TODO Integrate this as part of a UI change? + * Maybe we can auto-detect all mp3s and other streams and then + * add them to a new tab in the extension pop-up. Or we could + * add found links to the "Play"-button drop-down menu. + * Adding this as a part of the normal plugins-logic makes + * existing things way too complicated. (I tried it...) + */ +class EmbeddedMediaLink extends WebPlugin { + constructor() { + super(); + + this.domains = ['.*']; + } + + async getPluginPath({ url }) { + const links = await this.searchMediaLinks(); + console.debug(links); + return links; + } + + async searchMediaLinks() { + return await executeScriptInActiveTab( + `try { document.querySelector('a[href$=".mp3"]').getAttribute('href'); } catch (e) {}` + ); + } +} + +export default EmbeddedMediaLink; diff --git a/src/modules/views/main/options.js b/src/modules/views/main/options.js index 3d4d681..d4e2440 100644 --- a/src/modules/views/main/options.js +++ b/src/modules/views/main/options.js @@ -8,16 +8,34 @@ export default (store, i18n) => { return html`
+ + + + +
+ + ${i18n.getMessage('optionsExperimental')} + + +
${i18n.getMessage('optionsExperimental')} -