2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Internal API Wrapper Module
|
2020-09-25 07:34:59 +02:00
|
|
|
* Belongs to LocalCDN.
|
2020-02-27 13:45:29 +01:00
|
|
|
*
|
|
|
|
* @author Thomas Rientjes
|
|
|
|
* @since 2017-12-03
|
2020-09-25 07:34:59 +02:00
|
|
|
|
|
|
|
* @author nobody
|
|
|
|
* @since 2020-07-09
|
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
* @license MPL 2.0
|
|
|
|
*
|
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Wrappers
|
|
|
|
*/
|
|
|
|
|
2024-04-28 07:18:40 +02:00
|
|
|
let wrappers = {};
|
2020-02-27 13:45:29 +01:00
|
|
|
|
2021-02-17 07:01:08 +01:00
|
|
|
|
2020-02-27 13:45:29 +01:00
|
|
|
/**
|
|
|
|
* Public Methods
|
|
|
|
*/
|
|
|
|
|
|
|
|
wrappers.setBadgeBackgroundColor = function (details) {
|
2021-08-11 06:29:09 +02:00
|
|
|
if (chrome.browserAction.setBadgeBackgroundColor === undefined) {
|
|
|
|
return;
|
2020-02-27 13:45:29 +01:00
|
|
|
}
|
2021-08-12 06:37:45 +02:00
|
|
|
|
|
|
|
if (details.type === BadgeSetting.TYPE) {
|
2021-08-11 06:29:09 +02:00
|
|
|
storageManager.type.set({[Setting.BADGE_DEFAULT_BACKGROUND_COLOR]: details.color});
|
|
|
|
wrappers.badgeDefaultBackgroundColor = details.color;
|
2021-08-12 06:37:45 +02:00
|
|
|
} else if (details.type === BadgeSettingHTMLFilter.TYPE) {
|
2021-08-11 06:29:09 +02:00
|
|
|
storageManager.type.set({[Setting.BADGE_HTML_FILTER_BACKGROUND_COLOR]: details.color});
|
|
|
|
wrappers.badgeColorHTMLfilter = details.color;
|
2021-08-12 06:37:45 +02:00
|
|
|
} else if (details.type === BadgeSettingMissingResource.TYPE) {
|
|
|
|
storageManager.type.set({[Setting.BADGE_MISSING_RESOURCE_BACKGROUND_COLOR]: details.color});
|
|
|
|
wrappers.badgeMissingResourceBackgroundColor = details.color;
|
2020-02-27 13:45:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
wrappers.setBadgeTextColor = function (details) {
|
2021-08-11 06:29:09 +02:00
|
|
|
if (chrome.browserAction.setBadgeTextColor === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2021-08-12 06:37:45 +02:00
|
|
|
|
|
|
|
if (details.type === BadgeSetting.TYPE) {
|
2021-08-11 06:29:09 +02:00
|
|
|
storageManager.type.set({[Setting.BADGE_DEFAULT_TEXT_COLOR]: details.color});
|
|
|
|
wrappers.badgeDefaultTextColor = details.color;
|
2021-08-12 06:37:45 +02:00
|
|
|
} else if (details.type === BadgeSettingHTMLFilter.TYPE) {
|
2021-08-11 06:29:09 +02:00
|
|
|
storageManager.type.set({[Setting.BADGE_HTML_FILTER_TEXT_COLOR]: details.color});
|
|
|
|
wrappers.badgeDefaultTextColorHTMLfilter = details.color;
|
2021-08-12 06:37:45 +02:00
|
|
|
} else if (details.type === BadgeSettingMissingResource.TYPE) {
|
|
|
|
storageManager.type.set({[Setting.BADGE_MISSING_RESOURCE_TEXT_COLOR]: details.color});
|
|
|
|
wrappers.badgeMissingResourceTextColor = details.color;
|
2021-08-11 06:29:09 +02:00
|
|
|
}
|
|
|
|
};
|
2020-09-25 07:34:59 +02:00
|
|
|
|
2021-08-11 06:29:09 +02:00
|
|
|
wrappers.setBadgeText = function (tabId, text) {
|
|
|
|
if (chrome.browserAction.setBadgeText !== undefined) {
|
|
|
|
chrome.browserAction.setBadgeText({
|
|
|
|
'tabId': tabId,
|
|
|
|
'text': `${text}`
|
2020-09-25 07:34:59 +02:00
|
|
|
});
|
2020-02-27 13:45:29 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-07-09 20:58:18 +02:00
|
|
|
wrappers.setIcon = function (details, type) {
|
2020-07-12 09:57:14 +02:00
|
|
|
if (chrome.browserAction.setIcon) {
|
2020-07-09 20:58:18 +02:00
|
|
|
details.path = IconType[details.path][type];
|
2020-09-27 11:46:32 +02:00
|
|
|
chrome.browserAction.setIcon(details);
|
2020-02-27 13:45:29 +01:00
|
|
|
}
|
|
|
|
};
|
2020-09-25 07:34:59 +02:00
|
|
|
|
2021-08-11 06:29:09 +02:00
|
|
|
wrappers.setBadgeColoring = function (tabId, value) {
|
|
|
|
let textColor, backgroundColor;
|
|
|
|
|
2021-08-12 06:37:45 +02:00
|
|
|
if (value === BadgeSettingHTMLFilter.TYPE) {
|
2021-08-11 06:29:09 +02:00
|
|
|
textColor = wrappers.badgeHTMLfilterTextColor;
|
|
|
|
backgroundColor = wrappers.badgeHTMLFilterBackgroundColor;
|
2021-08-12 06:37:45 +02:00
|
|
|
} else if (value === BadgeSetting.TYPE) {
|
2021-08-11 06:29:09 +02:00
|
|
|
textColor = wrappers.badgeDefaultTextColor;
|
|
|
|
backgroundColor = wrappers.badgeDefaultBackgroundColor;
|
2021-08-12 06:37:45 +02:00
|
|
|
} else if (value === BadgeSettingMissingResource.TYPE) {
|
|
|
|
textColor = wrappers.badgeMissingResourceTextColor;
|
|
|
|
backgroundColor = wrappers.badgeMissingResourceBackgroundColor;
|
2021-03-21 08:08:03 +01:00
|
|
|
} else {
|
2021-08-11 06:29:09 +02:00
|
|
|
return;
|
2021-03-21 08:08:03 +01:00
|
|
|
}
|
2021-03-13 06:55:20 +01:00
|
|
|
|
2022-07-22 18:55:48 +02:00
|
|
|
if (chrome.browserAction.setBadgeTextColor !== undefined) {
|
|
|
|
chrome.browserAction.setBadgeTextColor({
|
|
|
|
'tabId': tabId,
|
|
|
|
'color': textColor
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chrome.browserAction.setBadgeBackgroundColor !== undefined) {
|
|
|
|
chrome.browserAction.setBadgeBackgroundColor({
|
|
|
|
'tabId': tabId,
|
|
|
|
'color': backgroundColor
|
|
|
|
});
|
|
|
|
}
|
2021-03-13 06:55:20 +01:00
|
|
|
};
|