bin/views/captcha.pug

47 lines
2.1 KiB
Plaintext
Raw Normal View History

2023-04-17 02:37:07 +02:00
mixin captcha(text)
div(class='captcha_box')
-
const pyRange = (start, stop, step) =>
Array.from(
{ length: (stop - start) / step + 1 },
(value, index) => start + index * step
);
var captcha = text
var shuffled_indexes = pyRange(0, captcha.length - 1, 1);
shuffled_indexes.sort(() => crypto.randomInt(0,10) > 5 ? 1 : -1);
var current_index = -1;
const rint = (m, mx) => crypto.randomInt(m, mx);
const blowfish = () => {
const rules = [
'font-weight:normal',
'font-family:inherit',
'font-weight:bold',
'font-weight:normal',
'display:block',
'display:inline-block',
'display:flex',
'display:none',
'display:none'
];
const n = rint(8, 16);
let out = '';
for (let i = 0; i < n; i++) {
out += rules[rint(0,rules.length - 1)] + ';'.repeat(rint(1,6))
}
return out;
}
each index in shuffled_indexes
-
current_index++
var left_margin = 0;
p(class='c_s' style=`transform:translate(${((index - current_index) * (rint(80,82) / 10))}px, ${rint(-3,3)}px);${blowfish()};font-weight:${rint(0,2) == 1 ? 'bold' : 'normal'};color:#220000;display:inline-block`)= captcha[index]
each i in pyRange(0, rint(4,10), 1)
p(class='c_s' style=`transform:translate(${((index - current_index) * (rint(80,82) / 10))}px, ${rint(-3,3)}px);${blowfish()};font-weight:bold;color:#220000;display:none`)= a