Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
R
Relevance
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Insights
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Security & Compliance
Security & Compliance
Dependency List
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Numergent
Relevance
Commits
308acccc
Commit
308acccc
authored
Oct 26, 2015
by
Ricardo J. Mendez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Re-ordering start page results based on time spent on the page
parent
ccb100f3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
22 deletions
+32
-22
src/app/booklet/content.cljs
src/app/booklet/content.cljs
+32
-22
No files found.
src/app/booklet/content.cljs
View file @
308acccc
...
...
@@ -8,35 +8,45 @@
(
:require-macros
[
cljs.core.async.macros
:refer
[
go
]]))
(
defn
transform-node
[
database
node
]
(
defn
transform-result-node!
[
database
node
]
(
let
[
parent
(
.-parentNode
node
)
href
(
.-href
parent
)
id
(
.hashCode
href
)
data
(
get
database
id
)]
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
!
[]
(
go
(
let
[
data
(
from-transit
(
:data
(
<!
(
storage/get
))))]
(
doseq
[
node
(
sel
:.result_url_heading
)]
(
transform-node
(
:url-times
data
)
node
)
#
_
(
aset
node
"textContent"
(
str
(
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
)
(
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
)
(
do-transformations
!
)
(
let
[
bg
(
runtime/connect
)]
(
go
(
>!
bg
:content-initialized
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment