Commit 308acccc authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Re-ordering start page results based on time spent on the page

parent ccb100f3
...@@ -8,35 +8,45 @@ ...@@ -8,35 +8,45 @@
(:require-macros [cljs.core.async.macros :refer [go]])) (:require-macros [cljs.core.async.macros :refer [go]]))
(defn transform-node [database node] (defn transform-result-node!
(let [parent (.-parentNode node) [database node]
href (.-href parent) (let [parent (.-parentNode node)
id (.hashCode href) href (.-href parent)
data (get database id)] id (.hashCode href)
data (get database id)
time (:time data)
root-item (-> parent .-parentNode .-parentNode .-parentNode) ; Yeah, hacky as fuck
(aset node "rootItem" root-item)
(aset root-item "total-time" time)
(when data (when data
(aset node "textContent" (aset node "textContent"
(str (aget node "textContent") " [time viewed: " (:time data) " ms]")) (str (aget node "textContent") " [time viewed: " time " ms]")))))
(defn do-transformations [] (defn do-transformations! []
(go (go
(let [data (from-transit (:data (<! (storage/get))))] (let [data (from-transit (:data (<! (storage/get))))
(doseq [node (sel :.result_url_heading)] nodes (sel :.result_url_heading)
(transform-node (:url-times data) node) base (sel1 :.web_regular_results)]
#_(aset node "textContent" (doseq [node nodes]
(str (transform-result-node! (:url-times data) node))
(aget node "textContent") (console/log "Base" base)
" - Hi there: " (doall
(.-href (.-parentNode node))))))) (->>
(console/log (sel :.result_url_heading)) nodes
(console/log (map dommy/text (sel :.result_url_heading))) (map #(aget % "rootItem"))
(console/log (map #(.-parentNode %) (sel :.result_url_heading)))) (map-indexed #(do
;; We assign it (- 100 %1) so that the first nodes get a higher value
(aset %2 "sort-order" (or (aget %2 "total-time") (- 100 %1)))
(sort-by #(* -1 (aget % "sort-order")))
(map #(.appendChild base %))))
(defn ^:export init [] (defn ^:export init []
(console/log "Init on content script!") (console/log "Init on content script!")
(do-transformations) (do-transformations!)
(let [bg (runtime/connect)] (let [bg (runtime/connect)]
(go (go
(>! bg :content-initialized) (>! bg :content-initialized)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment