Skip to content

Instantly share code, notes, and snippets.

@shibafu528
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibafu528/5b635774b8c3198eb7a3 to your computer and use it in GitHub Desktop.
Save shibafu528/5b635774b8c3198eb7a3 to your computer and use it in GitHub Desktop.
twitter-text gem を利用して、mikutter PostBoxの文字数カウントをt.coを考慮したものに変更します。なおcoreの短縮システムとの兼ね合いはとっていません。
# -*- coding: utf-8 -*-
require 'twitter-text'
class Gtk::PostBox
# この値は変更される場合があるため、API help/configuration 'short_url_length' から取得するべき
TCO_LENGTH = 22
def remain_charcount
if not widget_post.destroyed?
footer = if add_footer? then UserConfig[:footer].size else 0 end
body_count = widget_post.buffer.text.size
Twitter::Extractor.extract_urls(widget_post.buffer.text) do |url|
body_count -= if url.length < TCO_LENGTH
then -(TCO_LENGTH - url.length)
else url.length - TCO_LENGTH end
if url.start_with?("https://") then body_count += 1 end
end
140 - body_count - footer
end
end
end
Plugin.create(:mikutter_patch_charcount) { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment