Created
July 28, 2013 00:11
-
-
Save rhenium/6096821 to your computer and use it in GitHub Desktop.
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
require "net/http" | |
require "uri" | |
require "cgi" | |
Plugin.create :loopsuruyatu do | |
@main_window = nil | |
@loop_num_of = {} | |
Gtk::TimeLine.addopenway(/^http:\/\/loop\.suruyatu\.com\/\d+/) do |shrinked_url, cancel| | |
begin | |
i_postbox = Plugin::GUI::Postbox.instance | |
i_postbox.options[:postboxstorage] = nil | |
@main_window << i_postbox | |
match = MessageConverters.expand_url_one(shrinked_url).to_s.match(/^http:\/\/loop\.suruyatu\.com\/(\d+)/) | |
@loop_num_of[i_postbox] = match[1] | |
rescue | |
Plugin.activity(:error, "URLが処理できない形式です: #{url}") | |
cancel.call | |
end | |
end | |
on_window_created do |i_window| | |
@main_window = i_window | |
end | |
on_gui_postbox_join_widget do |i_postbox| | |
loop_num = @loop_num_of.fetch(i_postbox, nil) | |
next unless loop_num | |
postbox = Plugin.filtering(:gui_get_gtk_widget, i_postbox).first | |
if postbox.nil? | |
Plugin.activity(:error, "Postboxを取得できませんでした.") | |
next | |
end | |
widget = postbox.widget_post | |
widget.buffer.text = "(処理中)" | |
widget.sensitive = false | |
Thread.new do | |
begin | |
red = Net::HTTP.get_response(URI.parse("http://loop.suruyatu.com/#{loop_num}"))["Location"] | |
widget.buffer.text = CGI.unescape(URI.parse(red).query[/(?<=text=)(.+)/]) | |
rescue | |
notice "loop failed: #{url}, #{$!}" | |
Plugin.activity(:error, "なんかダメだった") | |
widget.buffer.text = "" | |
ensure | |
widget.sensitive = true | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment