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 @@
(:require-macros [cljs.core.async.macros :refer [go]]))
(defn transform-node [database node]
(let [parent (.-parentNode node)
href (.-href parent)
id (.hashCode href)
data (get database id)]
(defn transform-result-node!
[database node]
(let [parent (.-parentNode node)
href (.-href parent)
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
(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! []
(let [data (from-transit (:data (<! (storage/get))))]
(doseq [node (sel :.result_url_heading)]
(transform-node (:url-times data) node)
#_(aset node "textContent"
(aget node "textContent")
" - Hi there: "
(.-href (.-parentNode node)))))))
(console/log (sel :.result_url_heading))
(console/log (map dommy/text (sel :.result_url_heading)))
(console/log (map #(.-parentNode %) (sel :.result_url_heading))))
(let [data (from-transit (:data (<! (storage/get))))
nodes (sel :.result_url_heading)
base (sel1 :.web_regular_results)]
(doseq [node nodes]
(transform-result-node! (:url-times data) node))
(console/log "Base" base)
(map #(aget % "rootItem"))
(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 []
(console/log "Init on content script!")
(let [bg (runtime/connect)]
(>! 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