Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.