-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexecute-js.pl
executable file
·77 lines (50 loc) · 1.54 KB
/
execute-js.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env perl
=head1 NAME
execute-js.pl - Execute javascript in webkit
=head1 SYNOPSIS
Simple usage:
execute-js.pl http://www.google.com/
=head1 DESCRIPTION
Display a web page and execute javascript on the page.
=cut
use strict;
use warnings;
use Glib ':constants';
use Gtk3 -init;
use Gtk3::WebKit;
use Data::Dumper;
sub main {
my ($url) = @ARGV;
$url ||= 'http://localhost:3001/';
my $window = Gtk3::Window->new('toplevel');
my $screen = $window->get_screen;
$window->set_default_size(800, 600);
$window->signal_connect(destroy => sub { Gtk3->main_quit() });
my $view = Gtk3::WebKit::WebView->new();
my $button = Gtk3::Button->new("Execute");
my $entry = Gtk3::Entry->new();
# Execute the javascript when the user wants it
$button->signal_connect(clicked => \&execute_js, [$view, $entry]);
$entry->signal_connect(activate => \&execute_js, [$view, $entry]);
# Pack the widgets together
my $sw = Gtk3::ScrolledWindow->new();
$sw->add($view);
my $hbox = Gtk3::HBox->new(0, 0);
$hbox->pack_start($entry, TRUE, TRUE, 2);
$hbox->pack_start($button, FALSE, FALSE, 2);
my $box = Gtk3::VBox->new(0, 0);
$box->pack_start($hbox, FALSE, FALSE, 2);
$box->pack_start($sw, TRUE, TRUE, 2);
$window->add($box);
$window->show_all();
$view->load_uri($url);
Gtk3->main;
return 0;
}
sub execute_js {
my $data = pop @_;
my ($view, $entry) = @{ $data };
my $js = $entry->get_text;
$view->execute_script($js);
}
exit main() unless caller;