(function () {
async function fetchShortcodeData() {
try {
const request = new Request("{-- replaced with url --}", {
headers: (() => {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
return headers;
})(),
method: 'POST',
body: JSON.stringify('{-- replaced with object --}'),
});
const response = await fetch(request);
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return await response.text();
} catch (error) {
console.error('Fetch failed:', error);
return '';
}
}
function reScript(helper) {
for (const node of helper.childNodes) {
if (node.hasChildNodes()) {
reScript(node);
}
if (node.nodeName === 'SCRIPT') {
const script = document.createElement('script');
script.type = 'text/javascript';
script.textContent = node.textContent;
node.replaceWith(script);
}
}
}
(async () => {
const currentScript = document.currentScript;
const content = await fetchShortcodeData();
const helper = document.createElement('div');
helper.id = 'helper';
helper.innerHTML = content;
reScript(helper);
currentScript.after(...helper.childNodes);
currentScript.remove();
})();
})();