Changeset 828


Ignore:
Timestamp:
02/04/14 16:59:25 (10 years ago)
Author:
ngw8
Message:

Added support for converting websites that scroll sideways. Still need to make the overview index page display the layout a bit better and maybe add up/down/left/right buttons rather than previous/next on each converted page.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/io/WebParser.java

    r824 r828  
    289289                       
    290290                        final MutableBool bottomReached = new MutableBool(false);
     291                        final MutableBool rightReached = new MutableBool(false);
    291292                       
    292293                        final MutableInt pageCount = new MutableInt(0);
     
    317318                                @Override
    318319                                public void handle(long arg0) {
    319                                         System.out.println(frameCount);
    320320                                        // Must wait 2 frames before taking a snapshot of the webview, otherwise JavaFX won't have redrawn
    321321                                        if (frameCount++ > 1) {
     
    340340
    341341                                                        WebParser.addTextToFrame(visibleWidth, visibleHeight, window, webEngine, frameToAddTo);
    342                                                         System.out.println("added text");
     342
    343343                                                        FrameIO.SaveFrame(frameToAddTo);
    344344                                                } catch (Exception ex) {
     
    438438                                                webEngine.executeScript(""
    439439                                                                // Initializing the counter used when scrolling the page
    440                                                                 + "var scrollCounter = 0;");
     440                                                                + "var scrollCounter = 0;"
     441                                                                + "var scrollCounterHorizontal = 0;");
    441442
    442443                                                // Setting up the element that contains the CSS to hide all text.
     
    573574                        }
    574575
    575                         while (!bottomReached.getValue()) {
     576                        // Loop that scrolls the page horizontally
     577                        while (!rightReached.getValue()) {
     578                                bottomReached.setValue(false);
     579                               
    576580                                Platform.runLater(new Runnable() {
    577581                                        @Override
     
    580584                                                        // Scrolling down the page
    581585                                                        webEngine.executeScript(""
    582                                                                         + "window.scrollTo(0, scrollCounter * 0.9 * window.innerHeight);"
    583                                                                         + "scrollCounter = scrollCounter+1;");
    584 
    585                                                         System.out.println("Scrolling");
    586 
    587                                                         bottomReached.setValue((Boolean) webEngine.executeScript("(window.pageYOffset + window.innerHeight >= document.documentElement.scrollHeight)"));
    588 
    589                                                         synchronized (notifier) {
    590                                                                 notifier.notify();
    591                                                         }
     586                                                                        + "scrollCounter = 0;"
     587                                                                        + "window.scrollTo(scrollCounterHorizontal * 0.9 * window.innerWidth, 0);"
     588                                                                        + "scrollCounterHorizontal = scrollCounterHorizontal+1;");
     589
     590                                                        rightReached.setValue((boolean) webEngine.executeScript("(window.pageXOffset + window.innerWidth >= document.documentElement.scrollWidth)"));
    592591
    593592                                                } catch (Exception e) {
     
    596595                                        }
    597596                                });
    598 
    599                                 synchronized (notifier) {
    600                                         try {
    601                                                 // Waiting for the page to be scrolled
    602                                                 notifier.wait();
    603                                         } catch (InterruptedException e) {
    604                                                 // TODO Auto-generated catch block
    605                                                 e.printStackTrace();
    606                                         }
    607                                 }
    608 
    609                                 timer.start();
    610 
    611                                 synchronized (notifier) {
    612                                         try {
    613                                                 // Waiting for the timer thread to finish before looping again
    614                                                 notifier.wait();
    615                                         } catch (InterruptedException e) {
    616                                                 // TODO Auto-generated catch block
    617                                                 e.printStackTrace();
    618                                         }
    619                                 }
    620 
     597                               
     598                                // Loop that scrolls the page vertically (for each horizontal scroll position)
     599                                while (!bottomReached.getValue()) {
     600                                        Platform.runLater(new Runnable() {
     601                                                @Override
     602                                                public void run() {
     603                                                        try {
     604                                                                // Scrolling down the page
     605                                                                webEngine.executeScript(""
     606                                                                                + "window.scrollTo(window.pageXOffset, scrollCounter * 0.9 * window.innerHeight);"
     607                                                                                + "scrollCounter = scrollCounter+1;");
     608
     609                                                                bottomReached.setValue((Boolean) webEngine.executeScript("(window.pageYOffset + window.innerHeight >= document.documentElement.scrollHeight)"));
     610       
     611                                                                synchronized (notifier) {
     612                                                                        notifier.notify();
     613                                                                }
     614       
     615                                                        } catch (Exception e) {
     616                                                                e.printStackTrace();
     617                                                        }
     618                                                }
     619                                        });
     620       
     621                                        synchronized (notifier) {
     622                                                try {
     623                                                        // Waiting for the page to be scrolled
     624                                                        notifier.wait();
     625                                                } catch (InterruptedException e) {
     626                                                        // TODO Auto-generated catch block
     627                                                        e.printStackTrace();
     628                                                }
     629                                        }
     630       
     631                                        timer.start();
     632       
     633                                        synchronized (notifier) {
     634                                                try {
     635                                                        // Waiting for the timer thread to finish before looping again
     636                                                        notifier.wait();
     637                                                } catch (InterruptedException e) {
     638                                                        // TODO Auto-generated catch block
     639                                                        e.printStackTrace();
     640                                                }
     641                                        }
     642       
     643                                }
    621644                        }
    622645
     
    882905                                        // If the element has a background color then add it (to Expeditee) as a rectangle with that background color
    883906                                        if (bgColor != null) {
    884                                                 System.out.println("bg");
    885907                                                frame.addRectangle(Math.round(x), Math.round(y), Math.round(width), Math.round(height), 0, null, bgColor);
    886908                                        }
Note: See TracChangeset for help on using the changeset viewer.