lichess.captcha.js
parent
e54069cebb
commit
0c37df6851
|
@ -70,7 +70,7 @@ trait AssetHelper { self: I18nHelper with SecurityHelper =>
|
|||
ctx.blind option
|
||||
jsAt(s"compiled/lichess.analyse.nvui.min.js")
|
||||
|
||||
def captchaTag = jsAt(s"compiled/captcha.js")
|
||||
def captchaTag = jsModule("captcha")
|
||||
|
||||
lazy val highchartsLatestTag = raw {
|
||||
s"""<script src="${staticUrl("vendor/highcharts-4.2.5/highcharts.js")}"></script>"""
|
||||
|
|
|
@ -74,7 +74,7 @@ function makeBundle(filename) {
|
|||
}
|
||||
|
||||
const standalonesJs = () => gulp.src([
|
||||
'captcha.js', 'embed-analyse.js'
|
||||
'embed-analyse.js'
|
||||
].map(f => `src/standalones/${f}`))
|
||||
.pipe(buffer())
|
||||
.pipe(terser({safari10: true}))
|
||||
|
|
|
@ -65,4 +65,8 @@ export default rollupProject({
|
|||
input: 'src/coordinate.ts',
|
||||
output: 'lichess.coordinate',
|
||||
},
|
||||
captcha: {
|
||||
input: 'src/captcha.ts',
|
||||
output: 'lichess.captcha',
|
||||
},
|
||||
});
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
window.lichess.load.then(() => {
|
||||
setTimeout(() => {
|
||||
$('div.captcha').each(function(this: HTMLElement) {
|
||||
const $captcha = $(this),
|
||||
$board = $captcha.find('.mini-board'),
|
||||
$input = $captcha.find('input').val(''),
|
||||
cg = $board.data('chessground'),
|
||||
fen = cg.getFen(),
|
||||
destsObj = $board.data('moves'),
|
||||
dests = new Map();
|
||||
for (let k in destsObj) dests.set(k, destsObj[k].match(/.{2}/g));
|
||||
cg.set({
|
||||
turnColor: cg.state.orientation,
|
||||
movable: {
|
||||
free: false,
|
||||
dests,
|
||||
color: cg.state.orientation,
|
||||
events: {
|
||||
after(orig: string, dest: string) {
|
||||
$captcha.removeClass('success failure');
|
||||
submit(orig + ' ' + dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const submit = function(solution: string) {
|
||||
$input.val(solution);
|
||||
$.ajax({
|
||||
url: $captcha.data('check-url'),
|
||||
data: {
|
||||
solution
|
||||
},
|
||||
success: function(data) {
|
||||
$captcha.toggleClass('success', data == 1).toggleClass('failure', data != 1);
|
||||
if (data == 1) $board.data('chessground').stop();
|
||||
else setTimeout(function() {
|
||||
cg.set({
|
||||
fen: fen,
|
||||
turnColor: cg.state.orientation,
|
||||
movable: { dests }
|
||||
});
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
}, 1000);
|
||||
});
|
|
@ -1,51 +0,0 @@
|
|||
$(function() {
|
||||
lichess.requestIdleCallback(function() {
|
||||
setTimeout(function() {
|
||||
$('div.captcha').each(function() {
|
||||
const $captcha = $(this),
|
||||
$board = $captcha.find('.mini-board'),
|
||||
$input = $captcha.find('input').val(''),
|
||||
cg = $board.data('chessground'),
|
||||
fen = cg.getFen(),
|
||||
destsObj = $board.data('moves'),
|
||||
dests = new Map();
|
||||
for (let k in destsObj) dests.set(k, destsObj[k].match(/.{2}/g));
|
||||
cg.set({
|
||||
turnColor: cg.state.orientation,
|
||||
movable: {
|
||||
free: false,
|
||||
dests,
|
||||
color: cg.state.orientation,
|
||||
events: {
|
||||
after(orig, dest) {
|
||||
$captcha.removeClass('success failure');
|
||||
submit(orig + ' ' + dest);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const submit = function(solution) {
|
||||
$input.val(solution);
|
||||
$.ajax({
|
||||
url: $captcha.data('check-url'),
|
||||
data: {
|
||||
solution
|
||||
},
|
||||
success: function(data) {
|
||||
$captcha.toggleClass('success', data == 1).toggleClass('failure', data != 1);
|
||||
if (data == 1) $board.data('chessground').stop();
|
||||
else setTimeout(function() {
|
||||
cg.set({
|
||||
fen: fen,
|
||||
turnColor: cg.state.orientation,
|
||||
movable: { dests }
|
||||
});
|
||||
}, 300);
|
||||
}
|
||||
});
|
||||
};
|
||||
});
|
||||
}, 1000);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue