     if doesScroll(scrollingElement, "y", 1, 1) or doesScroll(scrollingElement, "y", -1, 1)
       return scrollingElement
     else
-      element = getScrollingElement() ? document.body
+      element = document.body ? getScrollingElement()
 
   if doesScroll(element, "y", 1, 1) or doesScroll(element, "y", -1, 1)
     element

  'twitter.com': 'div.permalink-container div.permalink[role=main]'
  'reddit.com': '#overlayScrollContainer'
  'new.reddit.com': '#overlayScrollContainer'
  'mail.google.com': 'table[role="presentation"]'

root = exports ? (window.root ?= {})
root.Scroller = Scroller


# From element and its parents, find the first which we should scroll and which does scroll.
findScrollableElement = (element, direction, amount, factor) ->
  while element != getScrollingElement() and not isScrollableElement element, direction, amount, factor
    element = DomUtils.getContainingElement(element) ? getScrollingElement()
  element

# On some pages, the scrolling element is not actually scrollable.  Here, we search the document for the
