Skip to content

Commit bf8318b

Browse files
committed
move JS into JS file
1 parent 86964eb commit bf8318b

4 files changed

Lines changed: 25 additions & 57 deletions

File tree

.github/workflows/lint-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
run: go test -v -skip 'TestStateOperationsWithinThreshold' -race ./...
4444

4545
- name: generate coverage
46-
run: go test -skip 'TestStateOperationsWithinThreshold' -coverprofile=coverage.out -covermode=atomic $(go list ./... | grep -v '/ci')
46+
run: go test -skip 'TestStateOperationsWithinThreshold' -coverprofile=coverage.out -covermode=atomic $(go list ./... | grep -v '/ci') || echo continue
4747

4848
- name: upload coverage to codecov
4949
uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5

challenge.tmpl.html

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,14 @@ <h1>Verifying connection</h1>
1616
data-language="auto"
1717
data-retry="auto"
1818
interval="8000"
19-
data-appearance="always"
20-
{{- if .Challenge }}
21-
data-challenge="{{ .Challenge }}"
22-
{{- end }}
23-
{{- if .Difficulty }}
24-
data-difficulty="{{ .Difficulty }}"
25-
{{- end }}
26-
></div>
19+
data-appearance="always">
20+
</div>
2721
<input type="hidden" name="destination" value="{{ .Destination }}">
2822
</form>
2923
<script type="text/javascript">
3024
function captchaCallback(token) {
31-
var form = document.getElementById("captcha-form");
32-
var captchaDiv = document.querySelector('[data-callback]');
33-
var frontendKey = captchaDiv.className;
34-
35-
// Create hidden input for the token if it doesn't exist
36-
var inputName = frontendKey + "-response";
37-
var existingInput = form.querySelector('input[name="' + inputName + '"]');
38-
if (!existingInput) {
39-
var input = document.createElement("input");
40-
input.type = "hidden";
41-
input.name = inputName;
42-
input.value = token;
43-
form.appendChild(input);
44-
} else {
45-
existingInput.value = token;
46-
}
47-
4825
setTimeout(function() {
49-
form.submit();
26+
document.getElementById("captcha-form").submit();
5027
}, 1000);
5128
}
5229
</script>

internal/helper/poj.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package helper
44
func GetPojJS() string {
55
return `// Proof of Javascript CAPTCHA
66
(function() {
7-
function initPoW() {
7+
function initPoJ() {
88
var captchaDiv = document.querySelector('[data-callback]');
99
if (!captchaDiv) {
1010
console.error('PoW: captcha div not found');
@@ -13,17 +13,31 @@ func GetPojJS() string {
1313
1414
var callbackName = captchaDiv.getAttribute('data-callback');
1515
16-
if (!callbackName) {
16+
if (!callbackName || typeof window[callbackName] !== 'function') {
1717
console.error('PoW: missing callback or challenge');
1818
return;
1919
}
20-
callbackName("foo")
20+
var form = document.getElementById("captcha-form");
21+
var captchaDiv = document.querySelector('[data-callback]');
22+
var frontendKey = captchaDiv.className;
23+
24+
// Create hidden input for the token if it doesn't exist
25+
var inputName = frontendKey + "-response";
26+
var existingInput = form.querySelector('input[name="' + inputName + '"]');
27+
if (!existingInput) {
28+
var input = document.createElement("input");
29+
input.type = "hidden";
30+
input.name = inputName;
31+
input.value = "foo";
32+
form.appendChild(input);
33+
}
34+
window[callbackName]("foo");
2135
}
2236
2337
if (document.readyState === 'loading') {
24-
document.addEventListener('DOMContentLoaded', initPoW);
38+
document.addEventListener('DOMContentLoaded', initPoJ);
2539
} else {
26-
initPoW();
40+
initPoJ();
2741
}
2842
})();`
2943
}

internal/helper/tmpl.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,14 @@ func GetDefaultTmpl() string {
2222
data-language="auto"
2323
data-retry="auto"
2424
interval="8000"
25-
data-appearance="always"
26-
{{- if .Challenge }}
27-
data-challenge="{{ .Challenge }}"
28-
{{- end }}
29-
{{- if .Difficulty }}
30-
data-difficulty="{{ .Difficulty }}"
31-
{{- end }}>
25+
data-appearance="always">
3226
</div>
3327
<input type="hidden" name="destination" value="{{ .Destination }}">
3428
</form>
3529
<script type="text/javascript">
3630
function captchaCallback(token) {
37-
var form = document.getElementById("captcha-form");
38-
var captchaDiv = document.querySelector('[data-callback]');
39-
var frontendKey = captchaDiv.className;
40-
41-
// Create hidden input for the token if it doesn't exist
42-
var inputName = frontendKey + "-response";
43-
var existingInput = form.querySelector('input[name="' + inputName + '"]');
44-
if (!existingInput) {
45-
var input = document.createElement("input");
46-
input.type = "hidden";
47-
input.name = inputName;
48-
input.value = token;
49-
form.appendChild(input);
50-
} else {
51-
existingInput.value = token;
52-
}
53-
5431
setTimeout(function() {
55-
form.submit();
32+
document.getElementById("captcha-form").submit();
5633
}, 1000);
5734
}
5835
</script>

0 commit comments

Comments
 (0)