Content.purs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. module ExampleWebExt.Content where
  2. import Data.List.NonEmpty
  3. import LinkedIn
  4. import Prelude
  5. import Browser.DOM (getBrowserDom)
  6. import Data.List ((:))
  7. import Data.List as L
  8. import Data.List.NonEmpty as NEL
  9. import Data.Maybe (Maybe(..))
  10. import Data.NonEmpty (NonEmpty, (:|))
  11. import Effect (Effect)
  12. import Effect.Class.Console (logShow)
  13. import Effect.Console (log)
  14. import LinkedIn.ArtDecoCard (parseArtDecoCard)
  15. import Yoga.Tree (showTree)
  16. import Yoga.Tree.Zipper as Z
  17. main :: Effect Unit
  18. main = do
  19. dom <- getBrowserDom
  20. artDecoCards <- getArtDecoCards dom
  21. artDecoTabs <- getArtDecoTabs dom
  22. jobsUnifiedTopCard <- getJobsUnifiedTopCard dom
  23. log "[content] starting up"
  24. maybeShowTree artDecoCards >>= log
  25. maybeShowPruned "no card found" artDecoCards >>= log
  26. maybeShowPruned "no tabs found" artDecoTabs >>= log
  27. maybeShowPruned "no top card found" jobsUnifiedTopCard >>= log
  28. case artDecoCards of
  29. Nothing -> log "nothing"
  30. Just l -> do
  31. parsed <- (\(LinkedInUIElement _ n) -> parseArtDecoCard n) $ NEL.head l
  32. logShow parsed
  33. maybeShowTree ∷ Maybe (NonEmptyList LinkedInUIElement) → Effect String
  34. maybeShowTree Nothing = pure "nope"
  35. maybeShowTree (Just nel) = do
  36. tree <- asTree $ head nel
  37. pure $ showTree tree
  38. maybeShowPruned ∷ String → Maybe (NonEmptyList LinkedInUIElement) → Effect String
  39. maybeShowPruned errorMsg els = do
  40. trees <- asPrunedTrees els
  41. case trees of
  42. Nothing -> pure errorMsg
  43. Just ts -> do
  44. pure $ showTree $ head ts
  45. --pure $ showMaybeTree $ zipperTest $ head ts
  46. showMaybeTree Nothing = "No tree"
  47. showMaybeTree (Just t) = showTree t