()
| 1177 | setTurnstilePending(widget); |
| 1178 | |
| 1179 | if (window.turnstile && widget.id !== null) { |
| 1180 | window.turnstile.reset(widget.id); |
| 1181 | } |
| 1182 | } |
| 1183 | |
| 1184 | async function initializeFormProtection() { |
| 1185 | if ( |
| 1186 | !FORM_API_ORIGIN || |
| 1187 | !form || |
| 1188 | !weeklyForm || |
| 1189 | !submitButton || |
| 1190 | !weeklyButton |
| 1191 | ) { |
| 1192 | return; |
| 1193 | } |
| 1194 | |
| 1195 | setProtectedButtonsDisabled(true); |
| 1196 | |
| 1197 | try { |
| 1198 | const [configResponse, turnstile] = await Promise.all([ |
| 1199 | fetch(`${FORM_API_ORIGIN}/config`, { |
| 1200 | headers: { Accept: "application/json" }, |
| 1201 | }), |
| 1202 | loadTurnstile(), |
| 1203 | ]); |
| 1204 | const config = await configResponse.json(); |
| 1205 | |
| 1206 | if ( |
| 1207 | !configResponse.ok || |
| 1208 | !config.turnstileSiteKey || |
| 1209 | !config.actions?.suggestions || |
| 1210 | !config.actions?.weeklySignups |
| 1211 | ) { |
| 1212 | throw new Error( |
| 1213 | config.error || "Spam protection is temporarily unavailable.", |
| 1214 | ); |
| 1215 | } |
| 1216 | |
| 1217 | turnstileWidgets.suggestions.action = config.actions.suggestions; |
| 1218 | turnstileWidgets.weeklySignups.action = config.actions.weeklySignups; |
| 1219 | renderTurnstile( |
| 1220 | turnstile, |
| 1221 | turnstileWidgets.suggestions, |
| 1222 | config.turnstileSiteKey, |
| 1223 | ); |
| 1224 | renderTurnstile( |
| 1225 | turnstile, |
| 1226 | turnstileWidgets.weeklySignups, |
| 1227 | config.turnstileSiteKey, |
| 1228 | ); |
| 1229 | formProtectionReady = true; |
| 1230 | } catch { |
| 1231 | setFormStatus( |
| 1232 | "Submissions are temporarily unavailable. Refresh and try again.", |
| 1233 | "error", |
| 1234 | ); |
| 1235 | setWeeklyStatus( |
| 1236 | "Signups are temporarily unavailable. Refresh and try again.", |
no test coverage detected