浏览代码

Add JS function for coloring of visited job offers

jherve 1 年之前
父节点
当前提交
6016d7a15d
共有 2 个文件被更改,包括 20 次插入5 次删除
  1. 15 0
      src/Content.js
  2. 5 5
      src/Content.purs

+ 15 - 0
src/Content.js

@@ -0,0 +1,15 @@
+export function colorVisitedJobsLoopImpl () {
+    // We need to poll at regular intervals to catch all the new elements
+    // that appear as the page loads. A cleaner solution would involve use
+    // of MutationObserver but this simple timer does the trick.
+    setInterval(async () => {
+        document.querySelectorAll("div[data-job-id]").forEach(async el => {
+            const id = `linked_in_${el.dataset.jobId}`;
+
+            const inStorage = (await browser.storage.local.get(id))[id];
+            if (inStorage) {
+                el.style.backgroundColor = "#ffe4da";
+            }
+        })
+    }, 1000);
+}

+ 5 - 5
src/Content.purs

@@ -15,6 +15,9 @@ import LinkedIn (extractFromDocument, getContext)
 import LinkedIn.Loadable (waitFor)
 import LinkedIn.PageUrl (PageUrl(..))
 
+-- TODO: This function should be implemented in PS as well
+foreign import colorVisitedJobsLoopImpl :: Effect Unit
+
 main :: Effect Unit
 main = do
   log "[content] starting up"
@@ -27,14 +30,10 @@ main = do
 
   case ctx of
     Right (UrlJobOffer _) -> extractDataAndSendToBackground
-    Right (UrlListRecommendedJobOffers) -> colorAlreadyVisitedOffers
-    Right (UrlSearchJobOffers) -> colorAlreadyVisitedOffers
+    Right (UrlListRecommendedJobOffers) -> colorVisitedJobsLoopImpl
+    Right (UrlSearchJobOffers) -> colorVisitedJobsLoopImpl
     _ -> log "[content] Nothing to do"
 
-colorAlreadyVisitedOffers ∷ Effect Unit
-colorAlreadyVisitedOffers = log "[content] Coloring of job offers is not implemented yet"
-
 backgroundMessageHandler ∷ RuntimeMessage -> MessageSender → Effect Unit
 backgroundMessageHandler m _ = case m of
   RuntimeMessageRequestPageContent -> launchAff_ do