{-# LANGUAGE OverloadedStrings #-} module Game.Hanabi.FFI where import Miso import Control.Monad import Control.Monad.IO.Class(liftIO) foreign import javascript unsafe "var html = window.document.documentElement; $r = html.scrollHeight - html.clientHeight - (window.document.body.scrollTop || html.scrollTop);" getBottom :: IO Int atTheBottom :: IO Bool atTheBottom = (<=0) <$> getBottom windowBottomSub :: action -- ^ ActionToBeTaken -> action -- ^ NoAction -> Sub action windowBottomSub action noAction sink = windowAddEventListener "scroll" $ \_e -> do b <- atTheBottom liftIO $ sink $ if b then action else noAction -- foreign import javascript safe "var c=navigator.hardwareConcurrency; $r = c ? c : 1" getHardwareConcurrency :: IO Int -- Concurrency does not work at least with the current GHCJS.