-
Notifications
You must be signed in to change notification settings - Fork 32
/
history.go
81 lines (66 loc) · 2.32 KB
/
history.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package chrome
import "github.com/gopherjs/gopherjs/js"
type History struct {
o *js.Object
}
/*
* Types
*/
type HistoryItem struct {
*js.Object
Id string `js:"id"`
Url string `js:"url"`
Title string `js:"title"`
LastVisitTime int64 `js:"lastVisitTime"`
VisitCount int `js:"visitCount"`
TypedCount int `js:"typedCount"`
}
type VisitItem struct {
*js.Object
Id string `js:"id"`
VisitId string `js:"visitId"`
VisitTime int64 `js:"visitTime"`
ReferringVisitId string `js:"referringVisitId"`
Transition string `js:"transition"`
}
/*
* Methods:
*/
// Search searches the history for the last visit time of each page matching the query.
func (h *History) Search(query Object, callback func(results []HistoryItem)) {
h.o.Call("search", query, callback)
}
// GetVisits retrieves information about visits to a URL.
func (h *History) GetVisits(details Object, callback func(results []VisitItem)) {
h.o.Call("getVisits", details, callback)
}
// AddUrl adds a URL to the history at the current time with a transition type of "link".
func (h *History) AddUrl(details Object, callback func()) {
h.o.Call("addUrl", details, callback)
}
// DeleteUrl removes all occurrences of the given URL from the history.
func (h *History) DeleteUrl(details Object, callback func()) {
h.o.Call("deleteUrl", details, callback)
}
// DeleteRange removes all items within the specified date range from the history.
// Pages will not be removed from the history unless all visits fall within the range.
func (h *History) DeleteRange(rang Object, callback func()) {
h.o.Call("deleteRange", rang, callback)
}
// DeleteAll deletes all items from the history.
func (h *History) DeleteAll(callback func()) {
h.o.Call("deleteAll", callback)
}
/*
* Events
*/
// OnVisited fired when a URL is visited, providing the HistoryItem data for that URL.
// This event fires before the page has loaded.
func (h *History) OnVisited(callback func(result HistoryItem)) {
h.o.Get("onVisited").Call("addListener", callback)
}
// OnVisitedRemoved fired when one or more URLs are removed from the history service.
// When all visits have been removed the URL is purged from history.
func (h *History) OnVisitedRemoved(callback func(removed Object)) {
h.o.Get("onVisitedRemoved").Call("addListener", callback)
}