Skip to content

Commit f67aef0

Browse files
committed
feat(CSS): add Firefox only css check
1 parent 0b63020 commit f67aef0

3 files changed

Lines changed: 41 additions & 9 deletions

File tree

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Adjusts options page for mobile (Android) compatibility.
2+
* Adjusts options page for browser or system (mobile/Android) compatibility.
33
*
44
* Notice: You can include this asyncronously even when the whole DOM is not parsed yet.
55
* It only accesses the body tag and that is very likely available as it's likely one of
@@ -16,14 +16,26 @@
1616
* Returns whether the current runtime is a mobile one (true) or not (false).
1717
*
1818
* @private
19-
* @returns {Promise} with Boolean
19+
* @returns {Promise<bool>}
2020
*/
2121
async function isMobile() {
2222
const platformInfo = await browser.runtime.getPlatformInfo();
2323

2424
return platformInfo.os === "android";
2525
}
2626

27+
/**
28+
* Returns whether the current browser is Firefox.
29+
*
30+
* @private
31+
* @returns {Promise<bool>}
32+
*/
33+
async function isFirefox() {
34+
const browserInfo = await browser.runtime.getBrowserInfo();
35+
36+
return browserInfo.name === "Firefox";
37+
}
38+
2739
/**
2840
* Initalize this module.
2941
*
@@ -33,10 +45,19 @@ async function isMobile() {
3345
* @public
3446
* @returns {Promise}
3547
*/
36-
export async function init() {
37-
if (!(await isMobile())) {
38-
return;
39-
}
48+
export function init() {
49+
isMobile.then((isCurrentlyMobile) => {
50+
if (!isCurrentlyMobile) {
51+
return;
52+
}
53+
document.querySelector("body").classList.add("mobile");
54+
});
55+
isFirefox.then((isCurrentlyFirefox) => {
56+
if (!isCurrentlyFirefox) {
57+
return;
58+
}
59+
document.querySelector("body").classList.add("firefox");
60+
});
4061

41-
document.querySelector("body").classList.add("mobile");
62+
return Promise.all([isMobile, isFirefox]);
4263
}

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Doc is TODO…
215215

216216
## CSS
217217

218-
In the file [`css/photonOptions.css`], there is a style for
218+
In the file [`css/photonOptions.css`], there is a style for a Firefox/[Photon](https://design.firefox.com/photon/)-style appearance of the settings.
219219

220220
Here is the corresponding HTML, if you want to use it:
221221
```html
@@ -257,6 +257,14 @@ Here is the corresponding HTML, if you want to use it:
257257

258258
```
259259

260+
## Automatically disabling options
261+
262+
To automatically disable options depending on the environment, load the `EnvironmentalOptions.js` module and run `MobileOptions.init();`. You can even do that asynchronously with the `async` attribute at the `script` tag.
263+
264+
If you do so, you can use two CSS classes:
265+
* You can use the CSS class `.mobile-incompatible` to mark options that are not compatible with Android/mobile devices.
266+
* You can use the CSS class `.firefox-only` to mark options that are only compatible with the Mozilla Firefox browser.
267+
260268
## API note
261269

262270
Everything in the `internal` dir is considered to be an internal module/file and thus not be considered to be an API under _semantic versioning_. That means the API there can change at any time, do _not_ import anything from there!

css/photonOptions.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ body.mobile {
1414
font-size: 14px;
1515
}
1616

17-
/* disable all options incomaptible with mobile devices */
17+
/* disable all options incomaptible with current device/browser */
1818
body.mobile .mobile-incompatible {
1919
display: none;
2020
}
21+
body.firefox .firefox-only {
22+
display: none;
23+
}
2124

2225
/* https://design.firefox.com/photon/patterns/inactive.html */
2326
[disabled],

0 commit comments

Comments
 (0)