Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

calculate character count with URL shortening in mind

  • Loading branch information...
commit 42be2b8197a24bdcba3fe51a65f2245917eab59c 1 parent 68ee1d6
@splitbrain authored
Showing with 9 additions and 0 deletions.
  1. +9 −0 script.js
View
9 script.js
@@ -23,6 +23,15 @@ function countChars(){
avail -= (lgn.innerHTML.length + 1);
avail -= ta.value.length;
+ // ping.fm shorturls are 21 chars, see if it will shorten and count the shortened url
+ var matches = ta.value.match(/\b((https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gi);
+ if(matches) for(var i=0; i<matches.length; i++){
+ if(matches[i].length > 21){
+ // we counted too much, the url will be shortened
+ avail = avail+ (matches[i].length - 21);
+ }
+ }
+
var out = document.getElementById('chars');
if(avail > 0){
Please sign in to comment.
Something went wrong with that request. Please try again.