mirror of
https://github.com/kkapsner/CanvasBlocker
synced 2024-11-01 02:48:44 +01:00
49 lines
1.3 KiB
JavaScript
49 lines
1.3 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 = async function isMobile(){
|
|
// todo: proper mobile check (e.g. over browser.runtime.getBrowserInfo()) and no feature check
|
|
return !browser.pageAction ||
|
|
!browser.pageAction.show ||
|
|
!browser.pageAction.openPopup
|
|
;
|
|
};
|
|
|
|
scope.ifMobile = async function ifMobile(ifCallback, elseCallback){
|
|
const isMobile = await scope.isMobile();
|
|
if (isMobile){
|
|
return ifCallback();
|
|
}
|
|
else if (elseCallback){
|
|
return elseCallback();
|
|
}
|
|
else {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
scope.applyMobileDefaults = async function applyMobileDefaults(storage = false){
|
|
await 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);
|
|
}));
|
|
};
|
|
}()); |