Commit 60fbd3a3 authored by Ms Kimsible's avatar Ms Kimsible
Browse files

Display MT-captcha container with navigation hook + use explicit render

parent 5390df46
......@@ -17,18 +17,9 @@ function initMTC(registerHook, peertubeHelpers) {
return
}
// add captcha to the last step of the register stepper
const stepperSelector = 'my-custom-stepper .container'
await rendering(stepperSelector)
const stepper = document.querySelector(stepperSelector)
const div = document.createElement('div')
div.classList.add('mtcaptcha')
stepper.appendChild(div)
window.mtcaptchaConfig = {
'sitekey': s['mtcaptcha-site-key'],
'render': 'auto',
'render': 'explicit',
'customStyle': {
'cardColor': '#FAFAFA',
'inputTextColor': '#444444',
......@@ -50,6 +41,21 @@ function initMTC(registerHook, peertubeHelpers) {
'https://service2.mtcaptcha.com/mtcv1/client/mtcaptcha2.min.js',
])
// add captcha to the last step of the register stepper on router navigation
const MTCaptchaID = await insertMTCaptchaContainer('my-custom-stepper .container')
window.mtcaptchaConfig.renderQueue.push(MTCaptchaID)
registerHook({
target: 'action:router.navigation-end',
handler: async ({ path }) => {
if (path === '/signup') {
// add captcha to the last step of the register stepper on router navigation
const MTCaptchaID = await insertMTCaptchaContainer('my-custom-stepper .container')
window.mtcaptchaConfig.renderQueue.push(MTCaptchaID)
}
}
})
registerHook({
target: 'filter:api.signup.registration.create.params',
handler: body =>
......@@ -60,6 +66,16 @@ function initMTC(registerHook, peertubeHelpers) {
})
}
async function insertMTCaptchaContainer (stepperSelector) {
await rendering(stepperSelector)
const stepper = document.querySelector(stepperSelector)
const div = document.createElement('div')
div.id = `mtcaptcha-${Math.random().toString(16).slice(2)}`
div.classList.add('mtcaptcha')
stepper.appendChild(div)
return div.id
}
async function rendering (selector) {
// Waiting for DOMContent updated with a timeout of 5 seconds
await new Promise((resolve, reject) => {
......
{
"name": "peertube-plugin-mtcaptcha2",
"version": "0.0.2",
"version": "0.0.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
......
{
"name": "peertube-plugin-mtcaptcha2",
"description": "Fork of the PeerTube plugin adding MTCaptcha to the signup",
"version": "0.0.2",
"version": "0.0.5",
"author": "Ms Kimsible",
"bugs": "https://framagit.org/kimsible/peertube-plugin-mtcaptcha2/issues",
"clientScripts": [
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment