mirror of
https://gh.wpcy.net/https://github.com/elementor/one-click-accessibility.git
synced 2026-04-21 07:09:20 +08:00
31 lines
826 B
JavaScript
31 lines
826 B
JavaScript
const load = async () => {
|
|
return new Promise((resolve, reject) => {
|
|
const { scannerUrl, planData } = window?.ea11yScannerData;
|
|
|
|
const scriptSrc = `${scannerUrl}?api_key=${planData?.public_api_key}`;
|
|
|
|
// Check if script already exists
|
|
if (document.querySelector(`script[src="${scriptSrc}"]`)) {
|
|
return resolve(true); // Already loaded, resolve immediately
|
|
}
|
|
|
|
const script = document.createElement('script');
|
|
script.src = scriptSrc;
|
|
script.referrerPolicy = 'strict-origin-when-cross-origin';
|
|
script.async = true;
|
|
|
|
script.onload = () => {
|
|
return resolve(true); // Resolve the promise
|
|
};
|
|
|
|
script.onerror = () => {
|
|
return reject(new Error(`Failed to load script: ${scannerUrl}`)); // Reject the promise
|
|
};
|
|
|
|
document.body.appendChild(script);
|
|
});
|
|
};
|
|
|
|
export const scannerWizard = {
|
|
load,
|
|
};
|