aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/context.js
diff options
context:
space:
mode:
authorAlex Yatskov <alex@foosoft.net>2019-10-20 11:23:20 -0700
committerAlex Yatskov <alex@foosoft.net>2019-10-20 11:23:20 -0700
commit438498435227cfa59cf9ed3430045b288cd2a7c0 (patch)
tree6a05520e5d6fa8d26d372673a9ed3e5d2da7e3fd /ext/bg/js/context.js
parent06d7713189be9eb51669d3842b78278371e6cfa4 (diff)
parentd32fd1381b6cd5141a21c22f9ef639b2fe9774fb (diff)
Merge branch 'master' into testing
Diffstat (limited to 'ext/bg/js/context.js')
-rw-r--r--ext/bg/js/context.js47
1 files changed, 44 insertions, 3 deletions
diff --git a/ext/bg/js/context.js b/ext/bg/js/context.js
index 0f88e9c0..8e1dbce6 100644
--- a/ext/bg/js/context.js
+++ b/ext/bg/js/context.js
@@ -17,10 +17,47 @@
*/
+function showExtensionInfo() {
+ const node = document.getElementById('extension-info');
+ if (node === null) { return; }
+
+ const manifest = chrome.runtime.getManifest();
+ node.textContent = `${manifest.name} v${manifest.version}`;
+}
+
+function setupButtonEvents(selector, command, url) {
+ const node = $(selector);
+ node.on('click', (e) => {
+ if (e.button !== 0) { return; }
+ apiCommandExec(command, {newTab: e.ctrlKey});
+ e.preventDefault();
+ })
+ .on('auxclick', (e) => {
+ if (e.button !== 1) { return; }
+ apiCommandExec(command, {newTab: true});
+ e.preventDefault();
+ });
+
+ if (typeof url === 'string') {
+ node.attr('href', url);
+ node.attr('target', '_blank');
+ node.attr('rel', 'noopener');
+ }
+}
+
$(document).ready(utilAsync(() => {
- $('#open-search').click(() => apiCommandExec('search'));
- $('#open-options').click(() => apiCommandExec('options'));
- $('#open-help').click(() => apiCommandExec('help'));
+ showExtensionInfo();
+
+ apiGetEnvironmentInfo().then(({browser}) => {
+ // Firefox mobile opens this page as a full webpage.
+ document.documentElement.dataset.mode = (browser === 'firefox-mobile' ? 'full' : 'mini');
+ });
+
+ const manifest = chrome.runtime.getManifest();
+
+ setupButtonEvents('.action-open-search', 'search', chrome.extension.getURL('/bg/search.html'));
+ setupButtonEvents('.action-open-options', 'options', chrome.extension.getURL(manifest.options_ui.page));
+ setupButtonEvents('.action-open-help', 'help');
const optionsContext = {
depth: 0,
@@ -31,5 +68,9 @@ $(document).ready(utilAsync(() => {
toggle.prop('checked', options.general.enable).change();
toggle.bootstrapToggle();
toggle.change(() => apiCommandExec('toggle'));
+
+ const toggle2 = $('#enable-search2');
+ toggle2.prop('checked', options.general.enable).change();
+ toggle2.change(() => apiCommandExec('toggle'));
});
}));