Skip to content

Instantly share code, notes, and snippets.

@satyr
Created August 2, 2009 20:35
Show Gist options
  • Save satyr/160204 to your computer and use it in GitHub Desktop.
Save satyr/160204 to your computer and use it in GitHub Desktop.
#!ruby
unless $*[0]
puts "Usage: ruby #$0 [-[ef]] input"
puts ' -e: execute'
puts ' -f: focus'
exit 1
end
require 'net/telnet'
def mozexec js
prompt = /^repl> /
mozrepl = Net::Telnet.new 'Port'=> 4242, 'Prompt'=> prompt, 'Timeout'=> 5
mozrepl.waitfor prompt
mozrepl.cmd(js){|s| print s.sub prompt, '' }
mozrepl.close
end
opt = $*[0] =~ /^-\w*/ ? $*.shift : ''
execu = opt[/e/i]
focus = opt[/f/i]
input = $*.join(' ').encode('utf-8').chars.map{|c| '\\u%04x' % c.ord }.join
code = "gUbiquity.#{execu ? 'execute' : 'preview'}('#{input}');";
code = "minimize(); restore(); #{code} focus();" if focus
mozexec "with(opener || top){ #{code} }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment