aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/context-main.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-02-08 17:53:22 -0500
committerGitHub <noreply@github.com>2021-02-08 17:53:22 -0500
commit0d031ab7856f7066b5fd950519c3654647ccdad6 (patch)
tree3eaf987a6106794babe03c5aa9e381e9c89ae2ea /ext/bg/js/context-main.js
parente386599872ed4549b9279fe8386cd902eb96d5fe (diff)
Improve context page display on mobile (#1359)
Diffstat (limited to 'ext/bg/js/context-main.js')
-rw-r--r--ext/bg/js/context-main.js36
1 files changed, 33 insertions, 3 deletions
diff --git a/ext/bg/js/context-main.js b/ext/bg/js/context-main.js
index e9833687..3d9c90ab 100644
--- a/ext/bg/js/context-main.js
+++ b/ext/bg/js/context-main.js
@@ -88,9 +88,39 @@ class DisplayController {
}
async _setupEnvironment() {
- // Firefox mobile opens this page as a full webpage.
- const {browser} = await api.getEnvironmentInfo();
- document.documentElement.dataset.mode = (browser === 'firefox-mobile' ? 'full' : 'mini');
+ const urlSearchParams = new URLSearchParams(location.search);
+ let mode = urlSearchParams.get('mode');
+ switch (mode) {
+ case 'full':
+ case 'mini':
+ break;
+ default:
+ {
+ let tab;
+ try {
+ tab = await this._getCurrentTab();
+ } catch (e) {
+ // NOP
+ }
+ mode = (tab ? 'full' : 'mini');
+ }
+ break;
+ }
+
+ document.documentElement.dataset.mode = mode;
+ }
+
+ _getCurrentTab() {
+ return new Promise((resolve, reject) => {
+ chrome.tabs.getCurrent((result) => {
+ const e = chrome.runtime.lastError;
+ if (e) {
+ reject(new Error(e.message));
+ } else {
+ resolve(result);
+ }
+ });
+ });
}
_setupOptions({options}) {