Content.purs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 Data.Traversable (traverse)
  10. import Effect (Effect)
  11. import Effect.Class.Console (logShow)
  12. import Effect.Console (log)
  13. import LinkedIn.ArtDecoCard (parseArtDecoCard)
  14. import LinkedIn.ArtDecoCardAlt (ArtDecoCardAltElement, queryArtDecoCardAlt)
  15. import LinkedIn.ArtDecoTab (parseArtDecoTab)
  16. import LinkedIn.JobsUnifiedTopCard (parseJobsUnifiedTopCardElement)
  17. import LinkedIn.Profile.Project as PP
  18. import LinkedIn.Profile.Skill as PS
  19. import LinkedIn.Profile.Utils (toUIElement)
  20. import LinkedIn.Profile.WorkExperience as PWE
  21. import Web.DOM (Node)
  22. import Yoga.Tree (Tree, showTree)
  23. main :: Effect Unit
  24. main = do
  25. dom <- getBrowserDom
  26. artDecoCards <- getArtDecoCards dom
  27. artDecoTabs <- getArtDecoTabs dom
  28. jobsUnifiedTopCard <- getJobsUnifiedTopCard dom
  29. log "[content] starting up"
  30. maybeShowTree artDecoCards >>= log
  31. maybeShowPruned "no card found" artDecoCards >>= log
  32. maybeShowPruned "no tabs found" artDecoTabs >>= log
  33. maybeShowPruned "no top card found" jobsUnifiedTopCard >>= log
  34. case artDecoCards of
  35. Nothing -> log "nothing"
  36. Just l -> do
  37. parsed <- (\(LinkedInUIElement _ n) -> parseArtDecoCard n) $ NEL.head l
  38. logShow parsed
  39. case parsed of
  40. Left l -> logShow l
  41. Right p -> do
  42. logShow $ toUIElement <$> p
  43. logShow $ PWE.fromUI p
  44. logShow $ PP.fromUI p
  45. case artDecoCards of
  46. Nothing -> log "nothing"
  47. Just l -> do
  48. queried <- (\(LinkedInUIElement _ n) -> queryArtDecoCardAlt n) $ NEL.head l
  49. case queried of
  50. Left l -> logShow l
  51. Right p -> do
  52. detached <- traverse toDetached p :: Effect (ArtDecoCardAltElement DetachedNode)
  53. logShow detached
  54. case artDecoTabs of
  55. Nothing -> log "nothing"
  56. Just l -> do
  57. parsed <- (\(LinkedInUIElement _ n) -> parseArtDecoTab n) $ NEL.head l
  58. logShow parsed
  59. case parsed of
  60. Left l -> logShow l
  61. Right p -> do
  62. logShow $ PS.fromUI p
  63. case jobsUnifiedTopCard of
  64. Nothing -> log "nothing"
  65. Just l -> do
  66. parsed <- (\(LinkedInUIElement _ n) -> parseJobsUnifiedTopCardElement n) $ NEL.head l
  67. logShow parsed
  68. maybeShowTree ∷ Maybe (NonEmptyList LinkedInUIElement) → Effect String
  69. maybeShowTree Nothing = pure "nope"
  70. maybeShowTree (Just nel) = do
  71. tree <- asTree $ NEL.head nel
  72. pure $ showTree tree
  73. maybeShowPruned ∷ String → Maybe (NonEmptyList LinkedInUIElement) → Effect String
  74. maybeShowPruned errorMsg els = do
  75. trees <- asPrunedTrees els
  76. case trees of
  77. Nothing -> pure errorMsg
  78. Just ts -> do
  79. pure $ showTree $ NEL.head ts
  80. --pure $ showMaybeTree $ zipperTest $ head ts
  81. showMaybeTree ∷ ∀ (a ∷ Type). Show a ⇒ Maybe (Tree a) → String
  82. showMaybeTree Nothing = "No tree"
  83. showMaybeTree (Just t) = showTree t