16fd99e8ba
Stop blocking WeChat delivery when Page Data insert works but publish quota blocks h5_publish_records; fix smoke URL missing /api; patch survey radios for WeChat X5 and detect dataset constants in admin pages. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
/**
|
|
* 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 = `<style id="mindspace-wechat-survey-compat">
|
|
.genre-option { position: relative; }
|
|
.genre-option label { position: relative; z-index: 1; pointer-events: none; -webkit-tap-highlight-color: transparent; }
|
|
.genre-option input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 2; }
|
|
.genre-option input:checked + label { pointer-events: none; }
|
|
button.submit-btn, .submit-btn { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
|
|
</style>`;
|
|
if (/<\/head>/i.test(next)) {
|
|
next = next.replace(/<\/head>/i, `${patch}\n</head>`);
|
|
} else if (/<body\b/i.test(next)) {
|
|
next = next.replace(/<body\b/i, `${patch}\n<body`);
|
|
} else {
|
|
next = `${patch}\n${next}`;
|
|
}
|
|
}
|
|
|
|
return { html: next, patched: true };
|
|
}
|