Posts Tagged ‘window’

Hack infinite scroll javascript with infinite auto-scroll to bottom of page

Thursday, January 7th, 2010

This is a hack to have your browser load all search results when a page is using jQuery’s infinite scroll feature, like this site: http://instantwatcher.com/titles/all?infinite=1.
Here’s the client side javascript to keep auto-scrolling this page to the bottom, thus triggering infinite scroll to load more results. It runs until there are no more results to load:

    function scrollToBottom(){
      bottom = document.body.scrollHeight;
      current = window.innerHeight+ document.body.scrollTop;
      if((bottom-current) >0){
        window.scrollTo(0, bottom);
        setTimeout ( 'scrollToBottom()', 1000 );
      }
    };
    scrollToBottom();

I run this on Safari using this short applescript:


tell application "Safari"
  set doc to front document
  set this_url to URL of doc
  do JavaScript "
    function scrollToBottom(){
      bottom = document.body.scrollHeight;
      current = window.innerHeight+ document.body.scrollTop;
      if((bottom-current) >0){
        window.scrollTo(0, bottom);
        setTimeout ( 'scrollToBottom()', 1000 );
      }
    };
    scrollToBottom();
    " in doc
end tell

Try it!

PyQt’s magical disappearing (but not reappearing) windows on Mac OS X

Monday, November 16th, 2009

After the grueling Qt and PyQt installation process on my Mac OS X 10.5 machine, I have PyQt up and running. I made a little hello, window type app for a sanity test and found a very puzzling feature. PyQt can make a resizable window which the mouse can resize to nothing! This is not allowed through the API methods (namely widget.resize(...,...)), with those the window always keeps a minimum width and height. But the user is allowed to drag the window to nothingness. If the user lets go while the window has non-positive dimensions then the window is lost forever as far as the mouse user is concerned.

Here’s the simple PyQt code:


import sys
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.show()
sys.exit(app.exec_())

And here are some screenshots of the result:

pyqt-disappearing-window-01.png


pyqt-disappearing-window-02.png


pyqt-disappearing-window-03.png


pyqt-disappearing-window-04.png


pyqt-disappearing-window-05.png


pyqt-disappearing-window-06.png


pyqt-disappearing-window-07.png


pyqt-disappearing-window-08.png

Update:
Here’s an animated gif version illustrating the above:
pyqt disappearing window animated gif

Update:
Shucks! Seems like this is fixed in the new version of PyQt4 that I just got.