(() => { const SCRIPT_ELEMENT = document.currentScript; const SCRIPT_URL = new URL(SCRIPT_ELEMENT.src); const params_input_func = { 'width': (value) => (isNumberParam(value) ? Number(value) : 300), 'height': (value) => (isNumberParam(value) ? Number(value) : 250), 'spot_id': (value) => (isNumberParam(value) ? Number(value) : undefined) }; const isNumberParam = (value) => ( !isNaN(Number(value)) && ((typeof value === 'string' && value.trim() !== '') || typeof value === 'number') ); const getParams = () => { let get_params = {}; const SCRIPT_URL_PARAMS = SCRIPT_URL.searchParams; for (const [key, value] of Object.entries(params_input_func)) { get_params[key] = value(SCRIPT_URL_PARAMS.get(key)); } return get_params; } const setting_params = getParams(); const wrap_div = document.createElement('div') SCRIPT_ELEMENT.after(wrap_div); wrap_div.style.cssText = `text-align: center; height: ${setting_params['height']}px;`; const iframe = wrap_div.appendChild(document.createElement('iframe')); iframe.style.cssText = `border: none; width: ${setting_params['width']}px; height: ${setting_params['height']}px;`; iframe.src = new URL(`iframe.html?spot_id=${setting_params['spot_id']}&_ver=${new Date().getTime()}`, SCRIPT_URL); let parent_widnow = window; let touch_flag = true; for (let i = 0; i < 10; i++) { try { parent_widnow.document.addEventListener('touchend', async () => { if (touch_flag) { iframe.contentWindow.postMessage({ 'message_type': 'touchend' }, iframe.src); touch_flag = false; } }); } catch (e) { break; } parent_widnow = parent_widnow.parent; } })();