Skip to content

Instantly share code, notes, and snippets.

@niwaringo
Last active December 30, 2015 08:59
Show Gist options
  • Save niwaringo/7805846 to your computer and use it in GitHub Desktop.
Save niwaringo/7805846 to your computer and use it in GitHub Desktop.
blogとかで自分の書いた文字だけカウントしたためのプチスクリプト
(function($, undefined) {
var digits = function(text) {
return (text + "").replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
};
$.fn.writeowncount = function() {
this.clone(true).each(function() {
var $this = $(this);
var ignore_tags = ["iframe", "a", "blockquote", "script", "div.gist", "pre"];
var ignore_tag_str = ignore_tags.join(",");
$this.find(ignore_tag_str).remove();
console.log(digits($.trim($this.text()).length));
});
return this;
}
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment