Skip to content

Instantly share code, notes, and snippets.

@touhonoob
Created May 15, 2012 11:53
Show Gist options
  • Save touhonoob/2701170 to your computer and use it in GitHub Desktop.
Save touhonoob/2701170 to your computer and use it in GitHub Desktop.
Javascript檢查發文時間
<?php
class mod_jscheckrenzoku{
const COOKIE_LASTSUBMIT = "lastSubmit";
public function mod_jscheckrenzoku() {
}
function getModuleName() {
return 'mod_jscheckrenzoku';
}
/* Get the module version infomation */
function getModuleVersionInfo() {
return 'v1';
}
public function autoHookHead(&$style, $isReply){
$style .= "<style>#jscheckrenzoku{color:red} #jscheckrenzoku a{color:blue} #jscheckrenzoku_count{font-weight: 800;} </style><script>
var mod_jscheckrenzoku_int, mod_jscheckrenzoku_timeout;
function jscheckrenzoku(){
var renzoku = " . RENZOKU . ";
var current_ts = Math.round((new Date()).getTime() / 1000);
var lastSubmit = parseInt(getCookie('" . self::COOKIE_LASTSUBMIT . "'), 10);
if(!isNaN(lastSubmit) && current_ts - lastSubmit < renzoku){
mod_jscheckrenzoku_timeout = renzoku - current_ts + lastSubmit;
$('input[name=sendbtn]').after(' <span id=\"jscheckrenzoku\">由於連續發文限制,還要 <span id=\"jscheckrenzoku_count\">' + mod_jscheckrenzoku_timeout + '</span> 秒才能發文。</span>');
$('input[name=sendbtn]').attr('disabled', true);
mod_jscheckrenzoku_int = setInterval(jscheckrenzoku_count,1000);
return false;
}else{
return true;
}
}
function jscheckrenzoku_count(){
if(--mod_jscheckrenzoku_timeout > 0){
$('#jscheckrenzoku_count').html(mod_jscheckrenzoku_timeout);
}else{
clearInterval(mod_jscheckrenzoku_int);
$('#jscheckrenzoku').html('現在可以發文了(゚∀゚)');
$('input[name=sendbtn]').removeAttr('disabled');
}
}
$(document).ready(function(){
if(document.forms[0]!=undefined){;
var form = $(document.forms[0]);
form.removeAttr('onsubmit');
form.submit(function(){
return c() && jscheckrenzoku();
});
}
});
</script>";
}
public function autoHookRegistAfterCommit($lastno, $resto, $name, $email, $sub, $com){
$time = time();
setcookie(self::COOKIE_LASTSUBMIT, $time, $time + 86400);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment