This article is a method for calculating the message length of Sina Weibo. That is (please abide by the community convention when speaking, and you can enter 119 characters).
var getMessageLength = (function() {
var byteLength = function(b) {
if(typeof b == "undefined") {
return 0;
}
var a = b.match(/[^x00-x80]/g);
return(b.length (!a ? 0 : a.length));
};
return function(message) {
message = message || '';
message = message.replace(/rn/g, "n");
var c = 41 ,
d = 140,
e = 20,
f = message,
g = message.match(/http://[a-zA-Z0-9] (.[a- zA-Z0-9] ) ([-A-Z0-9a-z_$. !*()/,:;@&=?~#%]*)*/gi) || [],
h = 0;
for(var i = 0, j = g.length; i < j; i ) {
var k = byteLength(g[i]);
if(/ ^(http://t.cn)/.test(g[i])) {
continue;
}
/^(http://) (t.sina.com.cn| t.sina.cn)/.test(g[i]) || /^(http://) (weibo.com|weibo.cn)/.test(g[i]) ? h = k <= c ? k : k <= d ? e : k - d e : h = k <= d ? e : k - d e;
f = f.replace(g[i], "");
}
var l = Math.ceil((h byteLength(f)) / 2);
return l;
};
})();
getMessageLength('The hard drive of my computer broke yesterday. I sent an email to the National Security Agency, but they refused to send me the backup content! '); //39