From 15de6776a959c0b267b6f601417caf1f973b3b38 Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 22 Mar 2019 17:51:06 -0300 Subject: Initial commit --- extension/background.js | 42 ++++++++++++++++++++++++++++++++++++++++++ extension/borderify.js | 3 +++ extension/icons/beasts-32.png | Bin 0 -> 1093 bytes extension/manifest.json | 36 ++++++++++++++++++++++++++++++++++++ extension/popup/index.html | 1 + 5 files changed, 82 insertions(+) create mode 100644 extension/background.js create mode 100644 extension/borderify.js create mode 100644 extension/icons/beasts-32.png create mode 100644 extension/manifest.json create mode 100644 extension/popup/index.html (limited to 'extension') diff --git a/extension/background.js b/extension/background.js new file mode 100644 index 0000000..b23c38b --- /dev/null +++ b/extension/background.js @@ -0,0 +1,42 @@ +console.log('Start'); + +const port = browser.runtime.connectNative('interactive_bgm'); + +browser.browserAction.onClicked.addListener(() => { + console.log('Hello??'); + // port.postMessage('[{"track": "mantis", "volume": 100}]\n'); +}); + +console.log('Hi', port); + +port.postMessage('[{"track": "mantis", "volume": 100}]\n'); + +port.onMessage.addListener(msg => { + console.log('Nyoom', msg); +}); + +/* +setTimeout(() => { + port.disconnect(); +}, 4000); +*/ + +port.onDisconnect.addListener(() => { + console.log('Disconnected'); +}); + +browser.runtime.onMessage.addListener(({hostname}) => { + const map = { + 'scratch.mit.edu': ['mantis'], + 'stackoverflow.com': ['bass', 'main'] + }; + + const mode = map[hostname]; + + if (mode) { + console.log('BGM:', mode); + port.postMessage(mode.map(track => ({track, volume: 100}))); + } else { + console.log('No BGM found for ' + location.hostname); + } +}); diff --git a/extension/borderify.js b/extension/borderify.js new file mode 100644 index 0000000..032dc19 --- /dev/null +++ b/extension/borderify.js @@ -0,0 +1,3 @@ +window.addEventListener('focus', () => { + browser.runtime.sendMessage({hostname: location.hostname}); +}); diff --git a/extension/icons/beasts-32.png b/extension/icons/beasts-32.png new file mode 100644 index 0000000..89863cc Binary files /dev/null and b/extension/icons/beasts-32.png differ diff --git a/extension/manifest.json b/extension/manifest.json new file mode 100644 index 0000000..27cafda --- /dev/null +++ b/extension/manifest.json @@ -0,0 +1,36 @@ +{ + "manifest_version": 2, + "name": "Interactive BGM", + "version": "1.0", + + "description": "Adds a red border to all webpages matching mozilla.org.", + + "permissions": [ + "activeTab", + "nativeMessaging" + ], + + "applications": { + "gecko": { + "id": "interactive_bgm@florrie.ed1.club", + "strict_min_version": "50.0" + } + }, + + "browser_action": { + "default_icon": "icons/beasts-32.png", + "default_title": "Interactive BGM", + "default_popup": "popup/index.html" + }, + + "content_scripts": [ + { + "matches": [""], + "js": ["borderify.js"] + } + ], + + "background": { + "scripts": ["background.js"] + } +} diff --git a/extension/popup/index.html b/extension/popup/index.html new file mode 100644 index 0000000..e6cf5e5 --- /dev/null +++ b/extension/popup/index.html @@ -0,0 +1 @@ +

Nice.

-- cgit 1.3.0-6-gf8a5