affiliate
Version:
A platform agnostic tool to quickly add affiliate links onto your website
51 lines (50 loc) • 1.26 kB
TypeScript
import Log from './shared/log';
export interface AffiliateConfigTag {
hosts: string | string[];
query?: {
[key: string]: string;
};
replace?: {
to: string;
from: string;
}[];
modify?: (url: URL) => URL | string;
}
export interface AffiliateConfig {
tags: AffiliateConfigTag[];
log?: boolean;
}
/**
* Manages stateful affiliation
*/
declare class Affiliate {
state: {
attached: boolean;
config: AffiliateConfig;
hosts: string[];
};
observer: MutationObserver | undefined;
log: typeof Log;
constructor(config?: Partial<AffiliateConfig>);
/**
* Manual function to search the DOM for unaffiliated links
*/
traverse(nodeSet?: HTMLElement): Affiliate;
/**
* Modify the URL of a matching link while preserving the original link state
*/
modifyURL: (url: URL, node: HTMLAnchorElement) => void;
/**
* Modify a manually provided URL
*/
convert: (url: string | URL) => string;
/**
* Attach the mutation observer
*/
attach: () => Affiliate;
/**
* Detach the mutation observer
*/
detach: () => Affiliate;
}
export default Affiliate;