diff --git a/ext/manifest.json b/ext/manifest.json index 4a7e049..144b8c9 100644 --- a/ext/manifest.json +++ b/ext/manifest.json @@ -14,16 +14,18 @@ "matches": [""], "js": [ "browser-polyfill.min.js", + "out/cljs_base.js", "content.js" ] } ], "background": { - "scripts": ["browser-polyfill.min.js", "background.js"] + "scripts": ["browser-polyfill.min.js", "out/cljs_base.js", "background.js"] }, "browser_action": { "default_icon": "icons/icon48.png", "default_title": "Looped In" }, - "content_security_policy": "script-src 'self'; object-src 'self'; connect-src 'self' https://hn.algolia.com" + "content_security_policy": "script-src 'self'; object-src 'self'; connect-src 'self' https://hn.algolia.com", + "web_accessible_resources": ["*.map"] } diff --git a/project.clj b/project.clj index cfcccea..35354be 100644 --- a/project.clj +++ b/project.clj @@ -7,6 +7,6 @@ [org.clojure/clojurescript "1.9.946"] [org.clojure/core.async "0.3.465"] [cljs-ajax "0.7.3"]] - :source-paths ["src/build"] + :source-paths ["src_clj"] :main looped-in.build :aliases {"build" ["run"]}) diff --git a/src/build/looped_in/build.clj b/src/build/looped_in/build.clj deleted file mode 100644 index 6a46fa6..0000000 --- a/src/build/looped_in/build.clj +++ /dev/null @@ -1,18 +0,0 @@ -(ns looped-in.build - (:require [cljs.build.api :as cljs])) - -(defn build - [root opts] - (println (str "Compiling " root " to " (:output-to opts))) - (cljs/build root opts) - (println (str "Compiled " (:output-to opts)))) - -(defn -main [& args] - (build "src/content" {:output-to "ext/content.js" - :optimizations :simple - :closure-output-charset "US-ASCII" - :pretty-print true}) - (build "src/background" {:output-to "ext/background.js" - :optimizations :simple - :closure-output-charset "US-ASCII" - :pretty-print true})) diff --git a/src_clj/looped_in/build.clj b/src_clj/looped_in/build.clj new file mode 100644 index 0000000..26cba3d --- /dev/null +++ b/src_clj/looped_in/build.clj @@ -0,0 +1,12 @@ +(ns looped-in.build + (:require [cljs.build.api :as cljs])) + +(defn -main [& args] + (cljs/build "src_cljs" {:optimizations :simple + :source-map true + :pretty-print true + :output-dir "ext/out" + :modules {:content {:output-to "ext/content.js" + :entries #{"looped-in.content"}} + :background {:output-to "ext/background.js" + :entries #{"looped-in.background"}}}})) diff --git a/src/background/looped_in/background.cljs b/src_cljs/looped_in/background.cljs similarity index 100% rename from src/background/looped_in/background.cljs rename to src_cljs/looped_in/background.cljs diff --git a/src/content/looped_in/content.cljs b/src_cljs/looped_in/content.cljs similarity index 83% rename from src/content/looped_in/content.cljs rename to src_cljs/looped_in/content.cljs index de00c1c..a84a894 100644 --- a/src/content/looped_in/content.cljs +++ b/src_cljs/looped_in/content.cljs @@ -5,6 +5,12 @@ (enable-console-print!) +(defn log [& args] + (apply js/console.log "[Looped In]" args)) + +(defn error [& args] + (apply js/console.error "[Looped In]" args)) + (defn fetch-submission "Fetches submissions from Hacker News by `url`" [url] @@ -14,8 +20,8 @@ "hitsPerPage" 1000 "restrictSearchableAttributes" "url"} :handler (fn [res] (go (>! response-chan res))) - :error-handler (fn [err] (js/console.error "Error fetching HN stories:" - (clj->js err)))}) + :error-handler (fn [err] (error "Error fetching HN stories:" + (clj->js err)))}) response-chan)) (defn filter-response @@ -24,6 +30,7 @@ ;; request and this method for 5 minutes using localStorage [url response] (let [{:strs [hits]} response] + (log "response" response) (filter #(= (get % "url") url) hits))) (defn sort-hits @@ -39,7 +46,7 @@ (defn handle-hits "Handles a filtered response" [hits] - (js/console.log (clj->js hits)) + (log (clj->js hits)) (let [num-comments (total-num-comments hits)] (-> js/browser (.-runtime)