diff -r e0b3ef3c07d0 -r 641ced48fd5a web/client.php --- a/web/client.php Thu Jan 10 18:53:10 2019 +0100 +++ b/web/client.php Fri Jan 11 01:19:45 2019 +0100 @@ -96,6 +96,7 @@ + @@ -181,16 +182,17 @@ const TWEET_LENGTH = ; function updateCounter() { var _v = $("#status").val(); - if (_v.length > TWEET_LENGTH) { - _v = _v.substr(0,TWEET_LENGTH); - $("#status").val(_v); - } - $('#tweetCounter').html(TWEET_LENGTH-_v.length); - if(TWEET_LENGTH-_v.length < 0) { + var _tRes = twttr.txt.parseTweet(_v); + if(_tRes.valid) { + $('#tweetCounter').removeClass("tweetCounterNegative"); + $('#sendTweet').prop("disabled",false); + $('#sendTweet').removeClass("sendTweetDisabled"); + $('#tweetCounter').html(""); + } else { $('#tweetCounter').addClass("tweetCounterNegative"); - } - else { - $('#tweetCounter').removeClass("tweetCounterNegative"); + $('#sendTweet').prop("disabled",true); + $('#sendTweet').addClass("sendTweetDisabled"); + $('#tweetCounter').html(_tRes.validRangeEnd - _tRes.displayRangeEnd); } $(".tweetButton").each(function(_i, _e) { if (_v.search($(_e).find('span.twbSyntax').text().replace(/(\W)/g, '\\$1')) > -1) { @@ -200,6 +202,7 @@ } }); } + updateCounter(); // BUTTONS $(".tweetButton").click(function() { @@ -208,7 +211,10 @@ }) // SEND TWEETS - $("#sendTweet").click(function(){ + $("#sendTweet").click(function(e){ + if($('#sendTweet').prop('disabled')) { + return; + } var MyStatus = $('#status').val(); $.post('tweet_ajax.php', {status:MyStatus} ,function(data) {