Skip to content

Instantly share code, notes, and snippets.

@osak
Created August 11, 2011 13:42
Show Gist options
  • Select an option

  • Save osak/1139686 to your computer and use it in GitHub Desktop.

Select an option

Save osak/1139686 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
require 'uri'
miquire :addon, 'bitly/bitly'
Module.new do
args = {
:slug => :shrink_url_im,
:name => 'URL短縮',
:condition => lambda{ |postbox| postbox.post.editable? },
:description => 'テキストボックス内のURLを短縮',
:exec => lambda { |postbox|
postbox.post.buffer.text = postbox.post.buffer.text.gsub(/https?:\/\/\S+/) { |url| Bitly.new.shrink_url(url) || url } },
:visible => true,
:role => :postbox,
}
Plugin.create(:contextmenu).add_event_filter(:command) { |menu|
menu[args[:slug]] = args
[menu]
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment