mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-10-18 11:21:37 -04:00
61 lines
1.5 KiB
Vue
61 lines
1.5 KiB
Vue
<template>
|
|
<div style="height: 73px" @click="render"></div>
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
import { defineComponent } from 'vue';
|
|
import useConfig from '../composables/useConfig.ts';
|
|
import useDark from '../composables/useDark.ts';
|
|
|
|
interface Turnstile {
|
|
render(
|
|
element: Element,
|
|
config: { sitekey: string, theme: 'dark' | 'light', language: string, callback: (token: string) => void },
|
|
): void;
|
|
}
|
|
|
|
declare global {
|
|
interface Window {
|
|
turnstile?: Turnstile;
|
|
}
|
|
}
|
|
|
|
export default defineComponent({
|
|
props: {
|
|
value: {},
|
|
},
|
|
setup() {
|
|
const { detectDark } = useDark();
|
|
return {
|
|
config: useConfig(),
|
|
detectDark,
|
|
};
|
|
},
|
|
async mounted() {
|
|
await this.$loadScript(
|
|
'turnstile',
|
|
`https://challenges.cloudflare.com/turnstile/v0/api.js?render=explicit&language=${this.config.locale}`,
|
|
);
|
|
setTimeout(() => {
|
|
this.render();
|
|
}, 500);
|
|
},
|
|
methods: {
|
|
render() {
|
|
if (!window.turnstile || this.$el.innerHTML.length) {
|
|
return;
|
|
}
|
|
window.turnstile.render(this.$el, {
|
|
sitekey: process.env.TURNSTILE_SITEKEY!,
|
|
theme: this.detectDark() ? 'dark' : 'light',
|
|
language: this.config.locale,
|
|
callback: this.solved,
|
|
});
|
|
},
|
|
solved(token: string) {
|
|
this.$emit('input', token);
|
|
},
|
|
},
|
|
});
|
|
</script>
|