LocalCDN-Firefox-Chrome-Brave/modules/internal/wrappers.js

111 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-02-27 13:45:29 +01:00
/**
* Internal API Wrapper Module
* Belongs to LocalCDN.
2020-02-27 13:45:29 +01:00
*
* @author Thomas Rientjes
* @since 2017-12-03
* @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
*/
var wrappers = {};
2021-02-17 07:01:08 +01:00
2020-02-27 13:45:29 +01:00
/**
* Public Methods
*/
wrappers.setBadgeBackgroundColor = function (details) {
if (chrome.browserAction.setBadgeBackgroundColor !== undefined) {
chrome.browserAction.setBadgeBackgroundColor(details);
storageManager.type.set({
[Setting.BADGE_COLOR]: details.color
});
2020-02-27 13:45:29 +01:00
}
};
wrappers.setBadgeText = function (details) {
if (chrome.browserAction.setBadgeText !== undefined) {
chrome.browserAction.setBadgeText(details);
}
};
wrappers.setBadgeTextColor = function (details) {
if (chrome.browserAction.setBadgeTextColor !== undefined) {
chrome.browserAction.setBadgeTextColor(details);
storageManager.type.set({
[Setting.BADGE_TEXT_COLOR]: details.color
});
2020-02-27 13:45:29 +01:00
}
};
wrappers.setIcon = function (details, type) {
2020-07-12 09:57:14 +02:00
if (chrome.browserAction.setIcon) {
details.path = IconType[details.path][type];
chrome.browserAction.setIcon(details);
2020-02-27 13:45:29 +01:00
}
};
2021-03-13 06:55:20 +01:00
wrappers.setBadgeMissing = function (tabIdentifier, counter) {
chrome.browserAction.setBadgeText({
'tabId': tabIdentifier,
'text': `${counter}`,
});
if (BrowserType.FIREFOX) {
chrome.browserAction.setBadgeTextColor({
'tabId': tabIdentifier,
'color': 'black',
});
chrome.browserAction.setBadgeBackgroundColor({
'tabId': tabIdentifier,
'color': 'yellow',
});
} else {
chrome.browserAction.setBadgeBackgroundColor({
'tabId': tabIdentifier,
'color': 'red',
});
}
2021-03-13 06:55:20 +01:00
};
wrappers.defaultBadge = function (tabIdentifier, counter) {
chrome.browserAction.setBadgeText({
'tabId': tabIdentifier,
'text': `${counter}`,
});
if (BrowserType.FIREFOX) {
chrome.browserAction.setBadgeTextColor({
'tabId': tabIdentifier,
'color': wrappers.textColor
});
}
2021-03-13 06:55:20 +01:00
chrome.browserAction.setBadgeBackgroundColor({
'tabId': tabIdentifier,
'color': wrappers.backgroundColor
});
};
storageManager.type.get([Setting.BADGE_COLOR, Setting.BADGE_TEXT_COLOR], function (items) {
wrappers.textColor = items.badgeTextColor || '#FFFFFF';
wrappers.backgroundColor = items.badgeColor || '#4A826C';
2021-02-17 07:01:08 +01:00
wrappers.setBadgeTextColor({'color': wrappers.textColor});
wrappers.setBadgeBackgroundColor({'color': wrappers.backgroundColor});
});