sync
authorAlan Knowles <alan@akbkhome.com>
Fri, 30 Dec 2011 02:28:32 +0000 (10:28 +0800)
committerAlan Knowles <alan@akbkhome.com>
Fri, 30 Dec 2011 02:28:32 +0000 (10:28 +0800)
BrowserToolbar.js
BrowserView.js
inject.js

index 6d3e5d5..d6eef3f 100644 (file)
@@ -61,7 +61,7 @@ BrowserToolbar = new GType({
        var grab = function(){
             print("sedning hello");
             TabbedBrowser.browser.current_tab().get_web_view().execute_script(
-                "downloadpage('"+document.location.href+"');"
+                "gatherlinks();"
             );
     
            // print('test');
index 6d78ba7..f7156ef 100644 (file)
@@ -128,9 +128,9 @@ BrowserView = new GType({
         
         this.downloadpage = function(link){
             
-                var url = File.read(__script_path__+"/downloadqueue/"+link);
-               TabbedBrowser.browser.current_tab().get_web_view().execute_script(
-                "downloadpage("+url+");");             
+                //var url = File.read(__script_path__+"/downloadqueue/"+link);
+               //TabbedBrowser.browser.current_tab().get_web_view().execute_script(
+                //"gatherlinks();");           
                
             
         };
@@ -160,14 +160,28 @@ BrowserView = new GType({
         
           this.signal.console_message.connect(function(wv, msg, line, sid) {
                 //print('BrowserView.js got ' + msg);
+               var methodname;
+               myData = JSON.parse(msg, function (key, value) {
+                   if (key=='method'){ methodname = value;}
                 
-                if (msg.indexOf('html')){
+                    return value;
+               });
+               
+               /*if (msg.indexOf('html')){
                     File.write(__script_path__+"/parsequeue/"+Math.random(), msg);
                 }
                 
                 
                 File.write(__script_path__+"/downloadqueue/"+Math.random(), msg);
-                
+                */
+               
+               if (methodname == 'gatherlinks'){
+                   File.write(__script_path__+"/downloadqueue/"+Math.random(), msg);
+               }
+               
+               if (methodname == 'downloadpage'){
+                   File.write(__script_path__+"/parsequeue/"+Math.random(), msg);
+               }
                 this.queuerun();
                 
                 return true;
index 5a1e0d3..d7296bd 100644 (file)
--- a/inject.js
+++ b/inject.js
@@ -4,8 +4,10 @@ function gatherlinks() {
        var urls= [];
        for (var i= document.links.length; i-->0;){
                urls.push(document.links[i].href);
-               console.log(document.links[i].href);
+               
        }
+        console.log(JSON.stringify( { method: 'gatherlinks' , data : urls }));
+        print('gatherlinks');
        return urls;
 
 }
@@ -17,9 +19,7 @@ function downloadpage(url) {
                xmlhttp.open("HEAD", url,true);
                xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4) {
-               console.log(xmlhttp.getAllResponseHeaders());
-               console.log(xmlhttp.responseText);
-                
+               console.log( JSON.stringify ({method: 'downloadpage', headers:xmlhttp.getAllResponseHeaders(), data:xmlhttp.responseText}));
                }
                
                xmlhttp.send(null);