/** * WeChat WebView compatibility patches for Page Data survey HTML. * X5 often fails to select radios hidden with pointer-events:none. */ export function htmlNeedsWechatSurveyCompat(html) { const content = String(html ?? ''); if (!/\/assets\/page-data-client\.js/i.test(content)) return false; if (!/\.insertRow\s*\(/.test(content)) return false; return ( /pointer-events\s*:\s*none/i.test(content) || /\.genre-option\s+input/i.test(content) || /input\[type=["']radio["']\][^{]*pointer-events/i.test(content) ); } export function applyWechatSurveyCompat(html) { const source = String(html ?? ''); if (!htmlNeedsWechatSurveyCompat(source)) { return { html: source, patched: false }; } let next = source; next = next.replace( /\.genre-option\s+input\s*\{[^}]*pointer-events\s*:\s*none\s*;?[^}]*\}/gi, '.genre-option input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 2; }', ); if (!/data-mindspace-wechat-survey-compat/i.test(next)) { const patch = ``; if (/<\/head>/i.test(next)) { next = next.replace(/<\/head>/i, `${patch}\n`); } else if (/