mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-08 19:56:34 +01:00
web/turnstile: use own callback for refreshing the widget
or at least try to, idk man, im so tired of cf turnstile
This commit is contained in:
parent
b31c126cec
commit
a3c807a993
3 changed files with 7 additions and 25 deletions
|
@ -18,15 +18,15 @@
|
||||||
const setup = () => {
|
const setup = () => {
|
||||||
window.turnstile?.render(turnstileElement, {
|
window.turnstile?.render(turnstileElement, {
|
||||||
sitekey,
|
sitekey,
|
||||||
|
"refresh-expired": "never",
|
||||||
|
|
||||||
"error-callback": (error) => {
|
"error-callback": (error) => {
|
||||||
console.log("error code from turnstile:", error);
|
console.log("error code from turnstile:", error);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
"expired-callback": () => {
|
"expired-callback": () => {
|
||||||
console.log("turnstile expired. i am callback this is my message")
|
console.log("turnstile expired, refreshing neow");
|
||||||
},
|
turnstile.reset();
|
||||||
"timeout-callback": () => {
|
|
||||||
console.log("turnstile timed out. i am callback this is my message")
|
|
||||||
},
|
},
|
||||||
callback: () => {
|
callback: () => {
|
||||||
$turnstileSolved = true;
|
$turnstileSolved = true;
|
||||||
|
@ -39,10 +39,6 @@
|
||||||
} else {
|
} else {
|
||||||
turnstileScript.addEventListener("load", setup);
|
turnstileScript.addEventListener("load", setup);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.addEventListener("focus", () => {
|
|
||||||
turnstile.refreshIfExpired();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ export const requestSession = async () => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
turnstile.update();
|
turnstile.reset();
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ const getResponse = () => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const update = () => {
|
const reset = () => {
|
||||||
const turnstileElement = document.getElementById("turnstile-widget");
|
const turnstileElement = document.getElementById("turnstile-widget");
|
||||||
|
|
||||||
if (turnstileElement) {
|
if (turnstileElement) {
|
||||||
|
@ -21,21 +21,7 @@ const update = () => {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshIfExpired = () => {
|
|
||||||
const turnstileElement = document.getElementById("turnstile-widget");
|
|
||||||
|
|
||||||
if (turnstileElement) {
|
|
||||||
const isExpired = window?.turnstile?.isExpired(turnstileElement);
|
|
||||||
if (isExpired) {
|
|
||||||
console.log("expired, refreshing the turnstile widget rn");
|
|
||||||
return update();
|
|
||||||
}
|
|
||||||
console.log("turnstile not expired, nothing to do");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
getResponse,
|
getResponse,
|
||||||
update,
|
reset,
|
||||||
refreshIfExpired,
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue