Content.purs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. module ExampleWebExt.Content where
  2. import LinkedIn
  3. import Prelude
  4. import Browser.DOM (getBrowserDom)
  5. import Data.Either (Either(..))
  6. import Data.List.NonEmpty (NonEmptyList)
  7. import Data.List.NonEmpty as NEL
  8. import Data.Maybe (Maybe(..))
  9. import Effect (Effect)
  10. import Effect.Class.Console (logShow)
  11. import Effect.Console (log)
  12. import LinkedIn.ArtDecoCard (parseArtDecoCard)
  13. import LinkedIn.ArtDecoTab (parseArtDecoTab)
  14. import LinkedIn.JobsUnifiedTopCard (parseJobsUnifiedTopCardElement)
  15. import LinkedIn.Profile.Project as PP
  16. import LinkedIn.Profile.Skill as PS
  17. import LinkedIn.Profile.Utils (toUIElement)
  18. import LinkedIn.Profile.WorkExperience as PWE
  19. import Yoga.Tree (Tree, showTree)
  20. main :: Effect Unit
  21. main = do
  22. dom <- getBrowserDom
  23. artDecoCards <- getArtDecoCards dom
  24. artDecoTabs <- getArtDecoTabs dom
  25. jobsUnifiedTopCard <- getJobsUnifiedTopCard dom
  26. log "[content] starting up"
  27. maybeShowTree artDecoCards >>= log
  28. maybeShowPruned "no card found" artDecoCards >>= log
  29. maybeShowPruned "no tabs found" artDecoTabs >>= log
  30. maybeShowPruned "no top card found" jobsUnifiedTopCard >>= log
  31. case artDecoCards of
  32. Nothing -> log "nothing"
  33. Just l -> do
  34. parsed <- (\(LinkedInUIElement _ n) -> parseArtDecoCard n) $ NEL.head l
  35. logShow parsed
  36. case parsed of
  37. Left l -> logShow l
  38. Right p -> do
  39. logShow $ toUIElement <$> p
  40. logShow $ PWE.fromUI p
  41. logShow $ PP.fromUI p
  42. case artDecoTabs of
  43. Nothing -> log "nothing"
  44. Just l -> do
  45. parsed <- (\(LinkedInUIElement _ n) -> parseArtDecoTab n) $ NEL.head l
  46. logShow parsed
  47. case parsed of
  48. Left l -> logShow l
  49. Right p -> do
  50. logShow $ PS.fromUI p
  51. case jobsUnifiedTopCard of
  52. Nothing -> log "nothing"
  53. Just l -> do
  54. parsed <- (\(LinkedInUIElement _ n) -> parseJobsUnifiedTopCardElement n) $ NEL.head l
  55. logShow parsed
  56. maybeShowTree ∷ Maybe (NonEmptyList LinkedInUIElement) → Effect String
  57. maybeShowTree Nothing = pure "nope"
  58. maybeShowTree (Just nel) = do
  59. tree <- asTree $ NEL.head nel
  60. pure $ showTree tree
  61. maybeShowPruned ∷ String → Maybe (NonEmptyList LinkedInUIElement) → Effect String
  62. maybeShowPruned errorMsg els = do
  63. trees <- asPrunedTrees els
  64. case trees of
  65. Nothing -> pure errorMsg
  66. Just ts -> do
  67. pure $ showTree $ NEL.head ts
  68. --pure $ showMaybeTree $ zipperTest $ head ts
  69. showMaybeTree ∷ ∀ (a ∷ Type). Show a ⇒ Maybe (Tree a) → String
  70. showMaybeTree Nothing = "No tree"
  71. showMaybeTree (Just t) = showTree t