@global-savings-group/extension-utils
v0.3.0
Published
Utilities for browser extensions
Downloads
256
Readme
Browser extension utilities
AffiliateNetworkService
import { AffiliateNetworkService } from '@global-savings-group/extension-utils';
const affiliateNetworkService = new AffiliateNetworkService();
async function activateAffiliateNetwork() {
...
try {
await affiliateNetworkService.activate(affiliateLink);
} catch (e){
console.error('Cannot activate affiliate network', e);
}
};
// subscribe to tab update events to close tab after activating affiliate network
chrome.tabs.onUpdated.addListener((tabId: number, changeInfo: chrome.tabs.TabChangeInfo) => {
if (affiliateNetworkService.isActivationTab(tabId)) {
affiliateNetworkService.onUpdated(tabId, changeInfo);
return;
}
// other code/logic
});
RemoteConfigService
import { RemoteConfigService } from '@global-savings-group/extension-utils';
/**
* {TIMESTAMP} is optional placeholder to be replaced with current timestamp, rounded down to cache duration
*/
const remoteConfigService = new RemoteConfigService('https://api.service.com/config.json?z={TIMESTAMP}');
const config = await remoteConfigService.get(); // returns remote config or undefined
console.log(config);