Last active
August 29, 2015 14:05
-
-
Save shibafu528/5b635774b8c3198eb7a3 to your computer and use it in GitHub Desktop.
twitter-text gem を利用して、mikutter PostBoxの文字数カウントをt.coを考慮したものに変更します。なおcoreの短縮システムとの兼ね合いはとっていません。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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