File tree Expand file tree Collapse file tree 5 files changed +61
-11
lines changed Expand file tree Collapse file tree 5 files changed +61
-11
lines changed Original file line number Diff line number Diff line change 16
16
<!-- Third-party libraries -->
17
17
{{if .EnableCaptcha}}
18
18
{{if eq .CaptchaType "recaptcha"}}
19
- <script src='{{URLJoin .RecaptchaURL "api.js"}}' async ></script>
19
+ <script src='{{URLJoin .RecaptchaURL "api.js"}}'></script>
20
20
{{end}}
21
21
{{if eq .CaptchaType "hcaptcha"}}
22
- <script src='https://hcaptcha.com/1/api.js' async ></script>
22
+ <script src='https://hcaptcha.com/1/api.js'></script>
23
23
{{end}}
24
24
{{if eq .CaptchaType "cfturnstile"}}
25
- <script src='https://challenges.cloudflare.com/turnstile/v0/api.js' async defer ></script>
25
+ <script src='https://challenges.cloudflare.com/turnstile/v0/api.js'></script>
26
26
{{end}}
27
27
{{end}}
28
28
<script src="{{AssetUrlPrefix}}/js/index.js?v={{AssetVersion}}" onerror="alert('Failed to load asset files from ' + this.src + ', please make sure the asset files can be accessed and the ROOT_URL setting in app.ini is correct.')"></script>
Original file line number Diff line number Diff line change 9
9
</div>
10
10
{{else if eq .CaptchaType "recaptcha"}}
11
11
<div class="inline field required">
12
- <div class="g-recaptcha" data-sitekey="{{.RecaptchaSitekey}}"></div>
12
+ <div id="captcha" captcha-type="g-recaptcha" class="g-recaptcha-style " data-sitekey="{{.RecaptchaSitekey}}"></div>
13
13
</div>
14
14
{{else if eq .CaptchaType "hcaptcha"}}
15
15
<div class="inline field required">
16
- <div class="h-captcha" data-sitekey="{{.HcaptchaSitekey}}"></div>
16
+ <div id="captcha" captcha-type="h-captcha" class="h-captcha-style " data-sitekey="{{.HcaptchaSitekey}}"></div>
17
17
</div>
18
18
{{else if eq .CaptchaType "mcaptcha"}}
19
19
<div class="inline field df ac db-small captcha-field">
20
20
<span>{{.locale.Tr "captcha"}}</span>
21
21
<div class="border-secondary w-100-small" id="mcaptcha__widget-container" style="width: 50%; height: 5em"></div>
22
- <div class="m-captcha" data-sitekey="{{.McaptchaSitekey}}" data-instance-url="{{.McaptchaURL}}"></div>
22
+ <div id="captcha" class="m-captcha" data-sitekey="{{.McaptchaSitekey}}" data-instance-url="{{.McaptchaURL}}"></div>
23
23
</div>
24
24
{{else if eq .CaptchaType "cfturnstile"}}
25
25
<div class="inline field captcha-field tc">
26
- <div class ="cf-turnstile" data-sitekey="{{.CfTurnstileSitekey}}"></div>
26
+ <div id="captcha" captcha-type ="cf-turnstile" data-sitekey="{{.CfTurnstileSitekey}}"></div>
27
27
</div>
28
28
{{end}}{{end}}
Original file line number Diff line number Diff line change
1
+ import { isDarkTheme } from '../utils.js' ;
2
+
3
+ export function initCaptcha ( ) {
4
+ const captchaEl = document . querySelector ( '#captcha' ) ;
5
+ if ( ! captchaEl ) return ;
6
+
7
+ const siteKey = captchaEl . getAttribute ( 'data-sitekey' ) ;
8
+ const isDark = isDarkTheme ( ) ;
9
+
10
+ const params = {
11
+ sitekey : siteKey ,
12
+ theme : isDark ? 'dark' : 'light'
13
+ } ;
14
+
15
+ switch ( captchaEl . getAttribute ( 'captcha-type' ) ) {
16
+ case 'g-recaptcha' : {
17
+ // eslint-disable-next-line no-undef
18
+ if ( grecaptcha ) {
19
+ // eslint-disable-next-line no-undef
20
+ grecaptcha . ready ( ( ) => {
21
+ // eslint-disable-next-line no-undef
22
+ grecaptcha . render ( captchaEl , params ) ;
23
+ } ) ;
24
+ }
25
+ break ;
26
+ }
27
+ case 'cf-turnstile' : {
28
+ // eslint-disable-next-line no-undef
29
+ if ( turnstile ) {
30
+ // eslint-disable-next-line no-undef
31
+ turnstile . render ( captchaEl , params ) ;
32
+ }
33
+ break ;
34
+ }
35
+ case 'h-captcha' : {
36
+ // eslint-disable-next-line no-undef
37
+ hcaptcha . render ( captchaEl , params ) ;
38
+ break ;
39
+ }
40
+ default :
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ import {initRepoCommentForm, initRepository} from './features/repo-legacy.js';
90
90
import { initFormattingReplacements } from './features/formatting.js' ;
91
91
import { initMcaptcha } from './features/mcaptcha.js' ;
92
92
import { initCopyContent } from './features/copycontent.js' ;
93
+ import { initCaptcha } from './features/captcha.js' ;
93
94
94
95
// Run time-critical code as soon as possible. This is safe to do because this
95
96
// script appears at the end of <body> and rendered HTML is accessible at that point.
@@ -190,6 +191,7 @@ $(document).ready(() => {
190
191
191
192
initCommitStatuses ( ) ;
192
193
initMcaptcha ( ) ;
194
+ initCaptcha ( ) ;
193
195
194
196
initUserAuthLinkAccountView ( ) ;
195
197
initUserAuthOauth2 ( ) ;
Original file line number Diff line number Diff line change @@ -220,18 +220,24 @@ textarea:focus,
220
220
}
221
221
222
222
@media @mediaMdAndUp {
223
- .g-recaptcha ,
224
- .h-captcha {
223
+ .g-recaptcha-style ,
224
+ .h-captcha-style {
225
225
margin : 0 auto !important ;
226
226
width : 304px ;
227
227
padding-left : 30px ;
228
+
229
+ iframe {
230
+ border-radius : 5px !important ;
231
+ width : 302px !important ;
232
+ height : 76px !important ;
233
+ }
228
234
}
229
235
}
230
236
231
237
@media (max-height : 575px ) {
232
238
#rc-imageselect ,
233
- .g-recaptcha ,
234
- .h-captcha {
239
+ .g-recaptcha-style ,
240
+ .h-captcha-style {
235
241
transform : scale (.77 );
236
242
transform-origin : 0 0 ;
237
243
}
You can’t perform that action at this time.
0 commit comments