Commit 95ce1dad authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

Merge branch 'feature/show-relevance' into develop

parents d44df83a 308acccc
String.prototype.hashCode = function() {};
......@@ -4,10 +4,8 @@
:dependencies [[org.clojure/clojure "1.7.0"]
[org.clojure/clojurescript "1.7.145"]
[org.clojure/core.async "0.1.346.0-17112a-alpha"]
[cljs-ajax "0.5.0"]
[cljsjs/react-bootstrap "0.25.2-0" :exclusions [org.webjars.bower/jquery]]
[devcards "0.2.0-8"]
[khroma "0.2.0-SNAPSHOT"]
[prismatic/dommy "1.1.0"]
[re-frame "0.4.1" :exclusions [cljsjs/react]]
......@@ -15,13 +13,15 @@
:source-paths ["src/app" "src/devcards"]
:profiles {:dev {:plugins [[lein-cljsbuild "1.1.0"]
[lein-chromebuild "0.3.0"]]
:cljsbuild {:builds {:dev
{:source-paths ["src/app" "src/devcards"]
:compiler {:output-to "target/unpacked/booklet.js"
:output-dir "target/js"
:optimizations :whitespace
:pretty-print true
:devcards true}}}}
:cljsbuild {:builds
{:dev
{:source-paths ["src/app"]
:compiler {:output-to "target/unpacked/booklet.js"
:output-dir "target/js"
:externs ["externs/misc-externs.js"]
:main "booklet.background"
:optimizations :whitespace
:pretty-print true}}}}
:chromebuild {:resource-paths ["resources/js"
"resources/html"
......
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<!--
We need the following highlight pack embedded because otherwise devcards
attempt to do some inline execution, which Chrome does not like on
extensions.
-->
<script type="text/javascript" id="com-rigsomelight-code-highlighting" src="highlight.pack.js"></script>
<script type="text/javascript" src="booklet.js"></script>
<script type="text/javascript" src="devcards-init.js"></script>
</head>
<body>
</body>
</html>
This diff is collapsed.
String.prototype.hashCode = function(){
var hash = 0;
if (this.length == 0) return hash;
for (var i = 0; i < this.length; i++) {
var char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash = hash & hash; // Convert to 32bit integer
}
return hash;
};
booklet.content.init();
\ No newline at end of file
......@@ -23,6 +23,13 @@
],
"persistent": false
},
"content_scripts": [
{
"matches": ["https://*.startpage.com/*", "https://duckduckgo.com/*"],
"run_at": "document_end",
"js": ["booklet.js", "content-init.js"]
}
],
"manifest_version": 2
}
......@@ -2,7 +2,6 @@
(:require [clojure.set :refer [difference]]
[cljs.core.async :refer [>! <!]]
[booklet.utils :refer [on-channel from-transit to-transit]]
[cognitect.transit :as transit]
[khroma.log :as console]
[khroma.alarms :as alarms]
[khroma.runtime :as runtime]
......@@ -300,6 +299,12 @@
(defn init-time-tracking []
(dispatch-sync [::initialize])
(go-loop
[conn (runtime/on-connect)]
(let [content (<! conn)]
(console/log "--> Background received" (<! content))
(>! content :background-ack)
(recur conn)))
)
(defn init-click-handling []
......
(ns booklet.content
(:require [booklet.utils :refer [on-channel from-transit to-transit]]
[dommy.core :refer-macros [sel sel1] :as dommy]
[khroma.runtime :as runtime]
[khroma.log :as console]
[cljs.core.async :refer [>! <!]]
[khroma.storage :as storage])
(:require-macros [cljs.core.async.macros :refer [go]]))
(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 " ms]")))))
(defn do-transformations! []
(go
(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)
(doall
(->>
nodes
(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)))
%2))
(sort-by #(* -1 (aget % "sort-order")))
(map #(.appendChild base %))))
)))
(defn ^:export init []
(console/log "Init on content script!")
(do-transformations!)
(let [bg (runtime/connect)]
(go
(>! bg :content-initialized)
(console/log "<-- Background replied" (<! bg)))))
\ No newline at end of file
......@@ -22,8 +22,7 @@
(defn from-transit
[transit-data]
(transit/read (transit/reader :json) transit-data)
)
(transit/read (transit/reader :json) transit-data))
(def initial-focus-wrapper
(with-meta identity
......
(ns booklet.devcards
(:require [devcards.core :as core]
[khroma.log :as console]))
(defn ^:export main []
(console/log "Initializing UI...")
(core/start-devcard-ui!*))
\ No newline at end of file
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