From 0d031ab7856f7066b5fd950519c3654647ccdad6 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Mon, 8 Feb 2021 17:53:22 -0500 Subject: Improve context page display on mobile (#1359) --- ext/bg/js/context-main.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'ext/bg') 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}) { -- cgit v1.2.3