diff options
author | Florrie <towerofnix@gmail.com> | 2019-03-22 17:51:06 -0300 |
---|---|---|
committer | Florrie <towerofnix@gmail.com> | 2019-03-22 17:51:06 -0300 |
commit | 15de6776a959c0b267b6f601417caf1f973b3b38 (patch) | |
tree | 538671ce2333c85349d451d8d73edcafe118232d /extension |
Initial commit
Diffstat (limited to 'extension')
-rw-r--r-- | extension/background.js | 42 | ||||
-rw-r--r-- | extension/borderify.js | 3 | ||||
-rw-r--r-- | extension/icons/beasts-32.png | bin | 0 -> 1093 bytes | |||
-rw-r--r-- | extension/manifest.json | 36 | ||||
-rw-r--r-- | extension/popup/index.html | 1 |
5 files changed, 82 insertions, 0 deletions
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 --- /dev/null +++ b/extension/icons/beasts-32.png Binary files differdiff --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": ["<all_urls>"], + "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 @@ +<p>Nice.</p> |