1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-11-11 15:48:51 +01:00
CanvasBlocker/lib/mobile.js

49 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-12-02 19:16:32 +01:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
(function(){
"use strict";
let scope;
if ((typeof exports) !== "undefined"){
scope = exports;
}
else {
scope = require.register("./mobile", {});
}
const settings = require("./settings");
const settingDefinitions = require("./settingDefinitions");
2019-12-28 23:23:55 +01:00
scope.isMobile = async function isMobile(){
2019-12-02 19:16:32 +01:00
// todo: proper mobile check (e.g. over browser.runtime.getBrowserInfo()) and no feature check
2019-12-28 23:23:55 +01:00
return !browser.pageAction ||
2019-12-02 19:16:32 +01:00
!browser.pageAction.show ||
!browser.pageAction.openPopup
2019-12-28 23:23:55 +01:00
;
2019-12-02 19:16:32 +01:00
};
2019-12-28 23:23:55 +01:00
scope.ifMobile = async function ifMobile(ifCallback, elseCallback){
const isMobile = await scope.isMobile();
if (isMobile){
return ifCallback();
}
else if (elseCallback){
return elseCallback();
}
else {
return false;
}
2019-12-02 19:16:32 +01:00
};
2019-12-28 23:23:55 +01:00
scope.applyMobileDefaults = async function applyMobileDefaults(storage = false){
await Promise.all(settingDefinitions.filter(function(definition){
2019-12-02 19:16:32 +01:00
return definition.hasOwnProperty("mobileDefaultValue") && (
!storage ||
!storage.hasOwnProperty(definition.name)
);
}).map(function(definition){
return settings.set(definition.name, definition.mobileDefaultValue);
}));
};
}());