CanvasBlocker/lib/mobile.js

51 lines
1.4 KiB
JavaScript

/* 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");
scope.isMobile = function isMobile(){
// todo: proper mobile check (e.g. over browser.runtime.getBrowserInfo()) and no feature check
return Promise.resolve(
!browser.pageAction ||
!browser.pageAction.show ||
!browser.pageAction.openPopup
);
};
scope.ifMobile = function ifMobile(ifCallback, elseCallback){
return scope.isMobile().then(function(isMobile){
if (isMobile){
return ifCallback();
}
else if (elseCallback){
return elseCallback();
}
else {
return false;
}
});
};
scope.applyMobileDefaults = function applyMobileDefaults(storage = false){
return Promise.all(settingDefinitions.filter(function(definition){
return definition.hasOwnProperty("mobileDefaultValue") && (
!storage ||
!storage.hasOwnProperty(definition.name)
);
}).map(function(definition){
return settings.set(definition.name, definition.mobileDefaultValue);
}));
};
}());