@global-savings-group/extension-serp
v2.0.3
Published
Browser Extension Search Engine Result Page
Downloads
102
Readme
Usage
Init Serp singleton object in Injection file with callback functions that renders the UI part.
import { Serp, Theme, SearchEngine, BadgeDataSet } from '@global-savings-group/extension-serp'
const renderUI = (
partnerLink: Element,
theme: Theme,
searchEngine: SearchEngine,
container: HTMLElement,
) => {
const customDomain = partnerLink.getAttribute("href");
chrome.runtime.sendMessage(
{
type: "check-partner",
param: { customDomain },
},
(partner: Partner) => {
if (!partner) {
return;
}
if (partner.vouchers.length > 0 || partner.deals.length > 0) {
const emptyElement = document.createElement("div");
emptyElement.dataset[BadgeDataSet.key] = BadgeDataSet.value;
render(
SERPBadge({
vouchersCount: partner.vouchers.length,
theme,
searchEngine,
}),
emptyElement
);
Serp.insertElementTo(container, emptyElement);
}
}
);
};
const sendAnalytics = (partnerName: string): void => {
sendMessage(MESSAGE_TYPE.SEND_GA, {
name: 'view_serp',
params: {
retailer_name: partnerName,
},
});
};
const EXTENSION_NAME = 'Extension Name';
const getSERPSettings = () =>
chrome.runtime.sendMessage({ type: "get-serp-settings" });
getSERPSettings().then((SERPSettings: iSERPSettings) => {
if (SERPSettings.enabled) {
Serp.init(renderBadgePartner, sendAnalytics, EXTENSION_NAME);
}
});