changeset 45:b1354c094d9b

Added javascript keys
author unexist
date Sun, 24 Jan 2010 03:06:30 +0100
parents 1b63ba3238f3
children 0f9e756631e1
files bin/subtly subtly/browser.rb subtly/webkit.rb
diffstat 3 files changed, 33 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/bin/subtly	Sun Jan 24 01:56:33 2010 +0100
+++ b/bin/subtly	Sun Jan 24 03:06:30 2010 +0100
@@ -36,7 +36,10 @@
   "ZZ"  => :SubtlyQuit,
 
   # Jumps
-  "g_"  => "http://www.google.de/search?q=%s"
+  "g_"  => "http://www.google.de/search?q=%s",
+
+  # Javascript
+  "t"   => "alert('test')"
 })
 
 # Set proxy
--- a/subtly/browser.rb	Sun Jan 24 01:56:33 2010 +0100
+++ b/subtly/browser.rb	Sun Jan 24 03:06:30 2010 +0100
@@ -360,11 +360,16 @@
                   @mode       = :jump
                   @input.text = ":open %s" % [ @keys[@keychain.to_sym].gsub("%s", @buffer) ]
                 else
-                  time = Integer(@times) rescue 1
+                  time    = Integer(@times) rescue 0
+                  command = @keys[@keychain.to_sym]
 
                   # Repeat command
-                  (0..time).each do 
-                    commands(@keys[@keychain.to_sym])
+                  (0..time).each do
+                    if(command.is_a?(String))
+                      @webkit.execute(command)
+                    else
+                      commands(command)
+                    end
                   end
 
                   # Tidy up
--- a/subtly/webkit.rb	Sun Jan 24 01:56:33 2010 +0100
+++ b/subtly/webkit.rb	Sun Jan 24 03:06:30 2010 +0100
@@ -183,6 +183,16 @@
       @session.proxy = uri #< Delegate to session
     end
 
+    ## execute
+    # Execute script
+    #
+    # @param [String, #read]  script  Script to execute
+    ##
+
+    def execute(script)
+      Subtly::Webkit.ffi_execute(@widget, script)
+    end
+
     private
 
     ## ffi_new
@@ -374,5 +384,16 @@
     attach_function(:ffi_get_session,
       :webkit_get_default_session, [ ], :pointer
     )
+
+    ## ffi_execute
+    # Execute script
+    #
+    # @param [Pointer, #read] web_view  A #WebKitWebView
+    # @param [String,  #read] script    A Javascript
+    ##
+
+    attach_function(:ffi_execute,
+      :webkit_web_view_execute_script, [ :pointer, :string ], :void
+    )
   end # }}}
 end