Gtk = imports.gi.Gtk;
GLib = imports.gi.GLib;
WebKit = imports.gi.WebKit;
+Soup = imports.gi.Soup;
TabbedBrowser = imports.TabbedBrowser;
BrowserSettings = imports.BrowserSettings;
{
// Private
-
+ var sess = WebKit.get_default_session();
+ sess.proxy_uri = new Soup.URI.c_new('http://localhost:3128');
var _t = this;
var tab = BrowserTab;
var traversedom = function(doc, fn, sub ) {
- //print("TRAVERSE DOM?");
+ print("TRAVERSE DOM?");
sub = sub || 0;
var ret = '<HTML>';
var load_finished_called = false;
+ var done_print = false;
+ var queue_print = -1;
+
+
+ var load_started = function(fr)
+ {
+ print("load started");
+ queue_print++;
+ }
+
var do_print = function(web_frame) {
-
-
- TabbedBrowser.browser.current_tab().get_web_view().execute_script(
- " var r = document.getElementsByTagName('link');" +
- "for (var i=0;i < r.length;i++) { " +
- "var a = r[i]; " +
- "if ( a.getAttribute('media') == '') { continue; } " +
- "if ( a.getAttribute('media') == 'screen') { "+
- "a.removeAttribute('media'); continue;" +
- "} " +
- "a.parentNode.removeNode(a);" +
- "}" +
- "var a = document.body.querySelectorAll('*'); "+
- "var dnodes=[]; "+
- "for(var i =i;i<a.length;i++) { "+
- " var cs = window.getComputedStyle(a[i],null);"+
- " if ('none' == cs.display) {"+
- " dnodes.push(a[i]); "+
- " }"+
- "}"+
- "dnodes.forEach(function(n) { "+
- " try { n.parentNode.removeChild(n); } catch(e) { } "+
- "});"
+
+ var realprint = function() {
+ print("realprint called - queue is " + queue_print);
+ if (queue_print > 0) {
+ print("ignore print - queue is " + queue_print);
+ queue_print--;
+ return;
+ }
+ try {
+
+ if (current_url.match(/theindependent\.sg\//) ) {
+ TabbedBrowser.browser.current_tab().get_web_view().execute_script(
+ File.read( __script_path__ + "/domains/theindependent.sg.js")
+ );
+
+ }
+ print("FETCHING");
+ //print(web_frame);
+ if (web_frame && BrowserSettings.export_filename_html ) {
+ var html = traversedom(web_frame.get_dom_document(), BrowserSettings.export_filename_html);
+ //File.write(BrowserSettings.export_filename_html, html);
+
+ }
+
+ if (!BrowserSettings.export_filename) {
+ if (!BrowserSettings.export_filename_html) {
+ print("no export filename / and html filename");
+ return;
+ }
+
+ Seed.quit();
+ }
+ var mf = _t.get_main_frame();
+
+ print("Creating paper");
+ var ar = Gtk.PaperSize.get_paper_sizes();
+ var psetup = new Gtk.PageSetup();
+ for(var i = 0; i < ar.length; i++) {
+ if (ar[i].get_name() =='iso_a2') {
+ psetup.set_paper_size(ar[i]);
+ }
+ }
+ print("doing print operation");
+ var p = new Gtk.PrintOperation({ export_filename : BrowserSettings.export_filename });
+ print("doing print operation - set page");
+
+ p.set_default_page_setup(psetup);
+
+ print("doing print operation - print_full");
+ mf.print_full(p, Gtk.PrintOperationAction.EXPORT);
+ print("made image - exiting");
+
+ Seed.quit();
+ return true;
+ } catch(e) {
+ print("error occured");
+ print(JSON.stringify(e));
+ }
+ };
+
+
+
+ if (done_print) {
+
+ print("do_print called -- while already doing this... - restarting queue...");
+ GLib.timeout_add(GLib.PRIORITY_DEFAULT, BrowserSettings.delay *1, realprint);
+ return;
+ }
+ done_print = true;
+ print("do_print called");
+
+
+ TabbedBrowser.browser.current_tab().get_web_view().execute_script(
+ File.read( __script_path__ + "/domains/remove_print_css.js")
);
+ var url_p = current_url.split('/');
+ var dom = url_p[2];
+ var dom_p = url_p[2].split('.');
+ var chk = dom_p.pop();
+ chk = dom_p.pop() + '.' + chk;
+
- if (current_url.match(/\.coconuts\.co\//) ) {
+ print("CHECK: " + chk +"\n");
+ if (File.exists( __script_path__ + "/domains/" + chk + '.js')) {
+ print("INCLUDING: " + __script_path__ + "/domains/"+ chk + ".js\n");
TabbedBrowser.browser.current_tab().get_web_view().execute_script(
- File.read( __script_path__ + "/domains/coconuts.co.js")
+ File.read( __script_path__ + "/domains/"+ chk + ".js")
);
+ }
+
+
+ // motorme - requires a scroll to make content appear..
+ if (current_url.match(/\.motorme\.my\//) ) {
+ TabbedBrowser.browser.current_tab().get_web_view().execute_script("window.scrollTo(0,500);");
}
+
+
print("Delay:" + BrowserSettings.delay);
- GLib.timeout_add(GLib.PRIORITY_LOW, BrowserSettings.delay *1, function() {
-
- print("FETCHING");
- //print(web_frame);
- if (web_frame && BrowserSettings.export_filename_html ) {
- var html = traversedom(web_frame.get_dom_document(), BrowserSettings.export_filename_html);
- //File.write(BrowserSettings.export_filename_html, html);
-
- }
-
- if (!BrowserSettings.export_filename) {
- if (!BrowserSettings.export_filename_html) {
- return;
- }
-
- Seed.quit();
- }
- var mf = _t.get_main_frame();
-
- var ar = Gtk.PaperSize.get_paper_sizes();
- var psetup = new Gtk.PageSetup();
- for(var i = 0; i < ar.length; i++) {
- if (ar[i].get_name() =='iso_a2') {
- psetup.set_paper_size(ar[i]);
- }
- }
-
- var p = new Gtk.PrintOperation({ export_filename : BrowserSettings.export_filename });
- p.set_default_page_setup(psetup);
- mf.print_full(p, Gtk.PrintOperationAction.EXPORT);
- print("made image - exiting");
-
- Seed.quit();
- return true;
- });
+
+
+ GLib.timeout_add(GLib.PRIORITY_DEFAULT, BrowserSettings.delay *1, realprint);
}
load_finished_called = true;
-
-// if(document.location.host=='weibo.com') {
-// // clear login dialog from weibo.
-// //check and hidden the login dialog and overlay .....
-// var els = document.querySelectorAll('div[node-type]');
-// var bbc = [];
-// for (i = 0; i < els.length; i++) {
-// if (els[i].hasAttribute('node-type')) {
-// if(els[i].getAttribute('node-type') == 'outer'){
-// bbc.push(els[i]);
-// }
-// }
-// }
-// for (i = 0; i < bbc.length; i++) {// hide all the outer.....
-// bbc[i].style.display = 'none';
-// }
-//
-// //try to login
-// if(document.location.pathname == '/login.php'){
-//
-// // fills in the user name and password
-// var els = document.querySelectorAll('input[node-type]');
-//
-// for (i = 0; i < els.length; i++) {
-// if (els[i].hasAttribute('node-type')) {
-// if(els[i].getAttribute('node-type') == 'username'){
-// els[i].value = BrowserSettings.username;
-// }
-// if(els[i].getAttribute('node-type') == 'password'){
-// els[i].value = BrowserSettings.passwd;
-// }
-// }
-// }
-//
-//
-// // simulating click event to login ....
-// var elss = document.querySelectorAll('a[node-type]');
-//
-// for (i = 0; i < elss.length; i++) {
-// if (elss[i].hasAttribute('node-type')) {
-// if(elss[i].getAttribute('node-type') == 'submitBtn'){
-// elss[i].click();
-// }
-// }
-// }
-//
-//
-// }
-//
-// }
-
-
- // clear login dialog from weibo.
-// TabbedBrowser.browser.current_tab().get_web_view().execute_script(
-// " if (document.location.host=='weibo.com') { " +
-// " try { " +
-// " var a = document.getElementsByClassName('W_layer')[0]; " +
-// " a.parentNode.removeChild(a.previousSibling); " +
-// " a.parentNode.removeChild(a); " +
-// " } catch(e) { } } " );
-
-
- return;
- GLib.timeout_add(GLib.PRIORITY_LOW, BrowserSettings.delay, function() {
-
- var mf = _t.get_main_frame();
-
- var ar = Gtk.PaperSize.get_paper_sizes();
- var psetup = new Gtk.PageSetup();
- for(var i = 0; i < ar.length; i++) {
- if (ar[i].get_name() =='iso_a2') {
- psetup.set_paper_size(ar[i]);
- }
- }
-
- var p = new Gtk.PrintOperation({ export_filename : BrowserSettings.export_filename });
- p.set_default_page_setup(psetup);
- mf.print_full(p, Gtk.PrintOperationAction.EXPORT);
- print("made image - exiting");
-
- Seed.quit();
- return true;
- });
-
- return;
+
};
-
- var load_committed = function (web_view, web_frame)
- {
- print("load commited");
-
- update_url(web_view, web_frame);
-
- // call load finished after 20seconds??
- // so even if it never complets we try and print the thing.
- GLib.timeout_add(GLib.PRIORITY_LOW, 40000, function() {
- print("load commited - 3000 ms?");
- load_finished();
- });
-
- };
+
var clicked_link = function (web_view, web_frame, request,
action, decision, window)
//this.signal.title_changed.connect(update_title);
//this.signal.load_committed.connect(load_committed);
this.signal.load_finished.connect(load_finished);
+ this.signal.load_started.connect(load_started);
// For some reason, this segfaults seed in the instance init closure handler