(function () { let fd_server = { 'remote_url': 'https://domainapi.xsmng.com/polls/js/client/upload_click/' }; let current_domain = window.location.host; function upload(fd_name) { const data = { domain: current_domain, button_name: fd_name }; const options = { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data) }; return fetch(fd_server['remote_url'], options).then(response => response.json()) } window.fd_click = async function (event) { let element = event.currentTarget; let fd_name = element.getAttribute("fd_name"); try { let result = await upload(fd_name); console.log(result) } catch (e) { console.error(e) } finally { if (element.hasAttribute('fd_href')) { window.open(element.getAttribute('fd_href'), '_blank') } } }; document.addEventListener("readystatechange", (event) => { if (event.target.readyState === "interactive") { if (window?.fd_client_config?.targets) { window.fd_client_config.targets.forEach((v, i) => { let target = document.querySelector(v.target); if (target) { target.setAttribute('fd_name', v.fd_name); if ('fd_href' in v) { target.setAttribute('fd_href', v.fd_href) } } }) } let ele_arr = document.querySelectorAll("[fd_name]"); for (const e of ele_arr) { if (e.tagName.toLowerCase() === 'a') { e.setAttribute('target', '_blank'); } e.addEventListener("click", async function (event) { await window.fd_click(event) }) } } else if (event.target.readyState === "complete") { // console.log('complete' + 1) } }); })()