1
0
mirror of https://codeberg.org/nobody/LocalCDN.git synced 2024-12-22 08:04:10 +01:00
LocalCDN-Firefox-Chrome-Brave/modules/internal/wrappers.js

104 lines
2.9 KiB
JavaScript

/**
* Internal API Wrapper Module
* Belongs to LocalCDN.
*
* @author Thomas Rientjes
* @since 2017-12-03
* @author nobody
* @since 2020-07-09
* @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';
/**
* Wrappers
*/
var wrappers = {};
/**
* Public Methods
*/
wrappers.setBadgeBackgroundColor = function (details) {
if (chrome.browserAction.setBadgeBackgroundColor === undefined) {
return;
}
if (details.type === 'default') {
storageManager.type.set({[Setting.BADGE_DEFAULT_BACKGROUND_COLOR]: details.color});
wrappers.badgeDefaultBackgroundColor = details.color;
} else if (details.type === 'html-filter') {
storageManager.type.set({[Setting.BADGE_HTML_FILTER_BACKGROUND_COLOR]: details.color});
wrappers.badgeColorHTMLfilter = details.color;
}
};
wrappers.setBadgeTextColor = function (details) {
if (chrome.browserAction.setBadgeTextColor === undefined) {
return;
}
if (details.type === 'default') {
storageManager.type.set({[Setting.BADGE_DEFAULT_TEXT_COLOR]: details.color});
wrappers.badgeDefaultTextColor = details.color;
} else if (details.type === 'html-filter') {
storageManager.type.set({[Setting.BADGE_HTML_FILTER_TEXT_COLOR]: details.color});
wrappers.badgeDefaultTextColorHTMLfilter = details.color;
}
};
wrappers.setBadgeText = function (tabId, text) {
if (chrome.browserAction.setBadgeText !== undefined) {
chrome.browserAction.setBadgeText({
'tabId': tabId,
'text': `${text}`
});
}
};
wrappers.setIcon = function (details, type) {
if (chrome.browserAction.setIcon) {
details.path = IconType[details.path][type];
chrome.browserAction.setIcon(details);
}
};
wrappers.setBadgeColoring = function (tabId, value) {
let textColor, backgroundColor;
if (chrome.browserAction.setBadgeBackgroundColor === undefined ||
chrome.browserAction.setBadgeTextColor === undefined) {
return;
}
if (value === 'htmlFilterOn') {
textColor = wrappers.badgeHTMLfilterTextColor;
backgroundColor = wrappers.badgeHTMLFilterBackgroundColor;
} else if (value === 'default') {
textColor = wrappers.badgeDefaultTextColor;
backgroundColor = wrappers.badgeDefaultBackgroundColor;
} else if (value === 'missing') {
textColor = 'white';
backgroundColor = 'blue';
} else {
return;
}
chrome.browserAction.setBadgeTextColor({
'tabId': tabId,
'color': textColor
});
chrome.browserAction.setBadgeBackgroundColor({
'tabId': tabId,
'color': backgroundColor
});
};