|
7 | 7 |
|
8 | 8 | <head> |
9 | 9 | <!-- change this to your project name --> |
10 | | - <title>eframe template</title> |
| 10 | + <title>Waffle - Template</title> |
11 | 11 |
|
12 | 12 | <!-- config for our rust wasm binary. go to https://trunkrs.dev/assets/#rust for more customization --> |
13 | 13 | <link data-trunk rel="rust" data-wasm-opt="2" /> |
|
141 | 141 | }); |
142 | 142 | } |
143 | 143 | </script> |
| 144 | + |
| 145 | + <!-- hCaptcha widget integration --> |
| 146 | + <script src="https://js.hcaptcha.com/1/api.js" async defer></script> |
| 147 | + <div id="captcha-container" style="display:none; position:fixed; top:0; left:0; width:100vw; height:100vh; background:rgba(0,0,0,0.7); z-index:9999; align-items:center; justify-content:center;"> |
| 148 | + <div style="background:#222; padding:32px; border-radius:12px; display:inline-block;"> |
| 149 | + <div id="hcaptcha-widget" class="h-captcha" data-sitekey="your-hcaptcha-site-key" data-callback="onHCaptchaSuccess"></div> |
| 150 | + <button onclick="closeCaptcha()" style="margin-top:16px;">Cancel</button> |
| 151 | + </div> |
| 152 | + </div> |
| 153 | + <script> |
| 154 | + // Show/hide captcha overlay via a single JS entrypoint for Rust/WASM |
| 155 | + function openCaptcha() { |
| 156 | + document.getElementById('captcha-container').style.display = 'flex'; |
| 157 | + } |
| 158 | + function closeCaptcha() { |
| 159 | + document.getElementById('captcha-container').style.display = 'none'; |
| 160 | + } |
| 161 | + // Unified JS entrypoint for Rust/WASM with action/message |
| 162 | + function JSRust(action, message) { |
| 163 | + switch(action) { |
| 164 | + case 'openCaptcha': |
| 165 | + openCaptcha(); |
| 166 | + break; |
| 167 | + case 'closeCaptcha': |
| 168 | + closeCaptcha(); |
| 169 | + break; |
| 170 | + case 'log': |
| 171 | + if (message) { |
| 172 | + console.log('[JSRust]', message); |
| 173 | + } |
| 174 | + break; |
| 175 | + // Add more actions as needed |
| 176 | + default: |
| 177 | + console.warn('[JSRust] Unknown action:', action, message); |
| 178 | + } |
| 179 | + } |
| 180 | + // Called by hCaptcha when solved |
| 181 | + function onHCaptchaSuccess(token) { |
| 182 | + JSRust('closeCaptcha'); |
| 183 | + if (window.wasm_bindgen && window.wasm_bindgen.pass_captcha_token) { |
| 184 | + window.wasm_bindgen.pass_captcha_token(token); |
| 185 | + } else if (window.pass_captcha_token) { |
| 186 | + window.pass_captcha_token(token); |
| 187 | + } |
| 188 | + } |
| 189 | + // For Rust/WASM: window.JSRust('openCaptcha') or window.JSRust('closeCaptcha') |
| 190 | + window.JSRust = JSRust; |
| 191 | + window.openCaptcha = openCaptcha; |
| 192 | + window.closeCaptcha = closeCaptcha; |
| 193 | + </script> |
| 194 | + <!-- End hCaptcha integration --> |
144 | 195 | </body> |
145 | 196 |
|
146 | 197 | </html> |
|
0 commit comments