export function isAdBlockInUse()

in src/lib/detect-ad-blocker.ts [40:72]


export function isAdBlockInUse(): Promise<boolean> {
	if (adBlockInUse !== undefined) {
		return Promise.resolve(adBlockInUse);
	}

	if (typeof window.getComputedStyle !== 'function') {
		// Old browsers not supporting getComputedStyle most likely won't have adBlockers
		adBlockInUse = false;
		return Promise.resolve(adBlockInUse);
	}

	return new Promise((resolve) => {
		window.requestAnimationFrame(() => {
			// create a fake ad element and append it to the document
			const ad = document.createElement('div');
			ad.setAttribute(
				'class',
				'ad_unit pub_300x250 pub_300x250m pub_728x90 text-ad textAd text_ad text_ads text-ads text-ad-links ad-text adSense adBlock adContent adBanner',
			);
			ad.setAttribute(
				'style',
				'width: 1px !important; height: 1px !important; position: absolute !important; left: -10000px !important; top: -1000px !important;',
			);
			document.body.appendChild(ad);

			// avoid a forced layout
			window.requestAnimationFrame(() => {
				// if the ad element has been hidden, an ad blocker is enabled.
				resolve(adElementBlocked(ad));
			});
		});
	});
}