Commit 8f369296 authored by Ricardo J. Mendez's avatar Ricardo J. Mendez

StartPage integration is now optional

parent c512cb8f
{
"name": "Relevance - Smart Tab Organizer",
"short_name": "Relevance",
"version": "1.0.9",
"version": "1.0.10",
"browser_action": {
"default_title": "Organize tabs",
"default_icon": {
......
......@@ -2,4 +2,5 @@
(def default-settings
{:ignore-set #{"localhost" "newtab" "t.co" "buff.ly"}
:sound-to-left? false})
\ No newline at end of file
:sound-to-left? false
:startpage? true})
\ No newline at end of file
(ns relevance.startpage
(:require [relevance.io :as io]
[relevance.settings :as settings]
[relevance.utils :refer [url-key time-display]]
[dommy.core :refer-macros [sel sel1] :as dommy]
[khroma.runtime :as runtime]
......@@ -20,7 +21,7 @@
id (url-key href)
data (get database id)
time (:time data)
root-item (-> parent .-parentNode .-parentNode .-parentNode) ; Yeah, hacky as fuck
root-item (-> parent .-parentNode .-parentNode .-parentNode) ; Yeah, hacky as fuck
]
(aset node "rootItem" root-item)
(aset root-item "total-time" time)
......@@ -41,23 +42,25 @@
(defn do-transformations! []
(go
(let [data (<! (io/load :data))
nodes (sel :.result_url_heading)
base (sel1 :.web_regular_results)]
(doseq [node nodes]
(transform-result-node! (:url-times data) node))
(doall
(->>
nodes
(map #(aget % "rootItem"))
(map-indexed #(do
;; We assign it (- %1) so that the first nodes get a higher value
(aset %2 "sort-order" (or (aget %2 "total-time") (- %1)))
%2))
(sort-by #(* -1 (aget % "sort-order")))
(map #(.appendChild base %))))
(when (:startpage? (or (<! (io/load :settings))
settings/default-settings))
(let [data (<! (io/load :data))
nodes (sel :.result_url_heading)
base (sel1 :.web_regular_results)]
(doseq [node nodes]
(transform-result-node! (:url-times data) node))
(doall
(->>
nodes
(map #(aget % "rootItem"))
(map-indexed #(do
;; We assign it (- %1) so that the first nodes get a higher value
(aset %2 "sort-order" (or (aget %2 "total-time") (- %1)))
%2))
(sort-by #(* -1 (aget % "sort-order")))
(map #(.appendChild base %))))
)))
))))
(defn ^:export main []
; (console/log "Init on content script!")
......@@ -65,7 +68,7 @@
(let [bg (runtime/connect)]
(go
(>! bg :content-initialized)
#_ (console/log "<-- Background replied" (<! bg))
#_(console/log "<-- Background replied" (<! bg))
)))
(main)
......@@ -97,7 +97,9 @@
(fn [app-state [_ settings]]
(let [ignore-set (utils/to-string-set (:ignore-set settings))]
(dispatch [:settings-set {:ignore-set ignore-set
:sound-to-left? (:sound-to-left? settings)} true])
:sound-to-left? (:sound-to-left? settings)
:startpage? (:startpage? settings)} true
])
app-state)))
......@@ -326,7 +328,7 @@
[:div {:class "page-header col-sm-10 col-sm-offset-1"}
[:h1 "Welcome!"]]
[:div {:class "col-sm-10 col-sm-offset-1"}
[:h2 "Thanks for installing Relevance 1.0.9"]
[:h2 "Thanks for installing Relevance 1.0.10"]
[:p [:a {:href "https://numergent.com/relevance/" :target "_blank"} "You can read about the latest changes here."]]
[:p "Relevance will help you sort your tabs when you have too many of them open. Here's how to use it:"]
[:ul
......@@ -369,7 +371,10 @@
[:p "This version of Relevance has an experimental integration with "
[:a {:href "https://startpage.com" :target "_blank"} "StartPage"]
". After you run a search, it'll look at the results on your current page and re-prioritize the links shown to bring to the front those you have spent the longest reading."]
[:p "Every search engine behaves differently, so if there's enough interest, I could extend this integration to others as well."]]])
[:p "StartPage integration is on by default for historical reasons, but I may remove it in the future. "
"You can toggle it from the " [:a {:on-click #(dispatch [:app-state-item [:ui-state :section] :settings])}
"settings section"] "."]
]])
......@@ -410,8 +415,10 @@
(defn div-settings []
(let [ignore-set (subscribe [:settings :ignore-set])
sound-to-left? (subscribe [:settings :sound-to-left?])
startpage? (subscribe [:settings :startpage?])
our-ignore (reagent/atom (string/join "\n" (sort @ignore-set)))
our-sound (reagent/atom @sound-to-left?)]
our-sound (reagent/atom @sound-to-left?)
our-startpage (reagent/atom @startpage?)]
(fn []
[:div {:class "col-sm-12"}
[:div {:class "row"}
......@@ -437,11 +444,23 @@
"If selected, tabs with sound will be prioritized, and moved to the left when sorting."]]
[:div {:class "col-sm-6"}]]
[:div {:class "row"}
[:div {:class "col-sm-12"}
[:h3 "Enable StartPage result ordering?"]]
[:div {:class "col-sm-6"}
[:p
[:input {:type :checkbox
:checked @our-startpage
:on-change #(reset! our-startpage (-> % .-target .-checked))
:style {:margin-right "4px"}}]
"If selected, results on StartPage will be sorted prioritizing those you have visited the most."]]
[:div {:class "col-sm-6"}]]
[:div {:class "row"}
[:div {:class "col-sm-12"}
[:a {:class "btn btn-danger btn-sm"
:on-click #(dispatch [:settings-parse {:ignore-set @our-ignore
:sound-to-left? @our-sound}])} "Save settings"]]]])))
:sound-to-left? @our-sound
:startpage? @our-startpage}])} "Save settings"]]]])))
......
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