affiliate
Version:
A platform agnostic tool to quickly add affiliate links onto your website
36 lines • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const AUTO_CONFIG_SYNTAX_REGEX = /WHERE (.+?) SET (.+?)\s*(?:AND|$)/g;
/* Setup automatic configuration */
const AutoConfig = () => {
var _a;
const scriptNode = document.getElementById('aff-js');
if (typeof scriptNode === 'object' && scriptNode) {
const nodeData = (_a = scriptNode === null || scriptNode === void 0 ? void 0 : scriptNode.dataset) === null || _a === void 0 ? void 0 : _a.autoAffiliate;
if (typeof nodeData === 'string') {
const tags = [];
const expressions = nodeData.match(AUTO_CONFIG_SYNTAX_REGEX);
if (!expressions)
return;
Object.values(expressions).forEach((expression) => {
const components = AUTO_CONFIG_SYNTAX_REGEX.exec(expression);
if (!components || components.length !== 3)
return;
const hosts = components[1];
const queries = components[2];
tags.push({
hosts: hosts.split(',').map((host) => host.trim()),
query: queries.split(',').reduce((a, b) => {
const [key, value] = b.split('=');
if (key && value)
a[key.trim()] = value.trim();
return a;
}, {}),
});
});
return { tags };
}
}
};
exports.default = AutoConfig;
//# sourceMappingURL=autoConfig.js.map