diff --git a/captcha.pl b/captcha.pl old mode 100644 new mode 100755 index 173f4f5..eb30285 --- a/captcha.pl +++ b/captcha.pl @@ -52,6 +52,7 @@ my %font=( my $query=new CGI; my $key=($query->param("key") or 'default'); +my $refresh=$query->param("refresh"); my $selector=($query->param("selector") or ".captcha"); my $style=($query->cookie("wakabastyle") or DEFAULT_STYLE); @@ -66,7 +67,7 @@ init_captcha_database($dbh) unless(table_exists_captcha($dbh,SQL_CAPTCHA_TABLE)) my $ip=($ENV{HTTP_CF_CONNECTING_IP} or $ENV{REMOTE_ADDR} or '0.0.0.0'); my ($word,$timestamp)=get_captcha_word($dbh,$ip,$key); -if(!$word) +if(!$word || $refresh) { $word=make_word(); $timestamp=time(); diff --git a/futaba_style.pl b/futaba_style.pl index e8a6678..665fe3c 100644 --- a/futaba_style.pl +++ b/futaba_style.pl @@ -83,6 +83,47 @@ var sitevars = { "self": "", "admin": 1 }; + +const cd = { + default: 60, + wait: undefined, + interval: undefined +}; + +function decrement() { + let wait = document.getElementById("wait"); + let duration = wait.querySelector("span"); + cd.wait--; + if (cd.wait > 0) { + if (cd.wait == 1) { + duration.innerHTML = `1 second`; + } else { + duration.innerHTML = `${cd.wait} seconds`; + } + } else { + clearInterval(cd.interval); + wait.innerHTML = ""; + } +} + +function countdown(n) { + let wait = document.getElementById("wait"); + wait.innerHTML = ` (Wait ${n} seconds)`; + cd.wait = n; + cd.interval = setInterval(decrement, 1000); +} + +function refresh() { + if (cd.wait > 0) return; + let img = document.getElementById("captcha"); + let r = "mainpage"; + let m = location.pathname.match(/(\d+).html/); + if (m) r = `res${m[1]}`; + let now = Math.floor(Date.now() / 1000); + let src = `/captcha.pl?key=${r}&refresh=${now}`; + img.src = src; + countdown(cd.default); +} }; @@ -285,9 +326,11 @@ use constant PAGE_TEMPLATE => compile_template(NORMAL_HEAD_INCLUDE.q{
-
-
- +
+
+ + Refresh captcha (Wait 5 seconds) +