Reformat comments

pull/3/head
Daniel Lauzon 4 years ago
parent a7f9a45d35
commit 07de945405

@ -283,8 +283,10 @@ func (s *Session) firstNav(ctx context.Context) error {
// - kb.ArrowRight (which causes an initial selection, and/or advances it by one) // - kb.ArrowRight (which causes an initial selection, and/or advances it by one)
// - kb.End which scrolls to the end of the page, and advances the selected item. // - kb.End which scrolls to the end of the page, and advances the selected item.
// Note timing is important, because when the kb.End causes significant scrolling, // Note timing is important, because when the kb.End causes significant scrolling,
// the active element become undefined for a certain time, in that case, we get an error (ignore), sleep, and retry. // the active element become undefined for a certain time, in that case, we
// The termnation criteria is that the selected item (document.activeElement.href) is stable for >2 iterations // get an error (ignore), sleep, and retry.
// The termnation criteria is that the selected item (document.activeElement.href)
// is stable for >2 iterations
func navToEnd(ctx context.Context) error { func navToEnd(ctx context.Context) error {
var prev, active string var prev, active string
lastRepeated := 0 lastRepeated := 0
@ -294,8 +296,12 @@ func navToEnd(ctx context.Context) error {
time.Sleep(tick) time.Sleep(tick)
if err := chromedp.Evaluate(`document.activeElement.href`, &active).Do(ctx); err != nil { if err := chromedp.Evaluate(`document.activeElement.href`, &active).Do(ctx); err != nil {
time.Sleep(tick) // this extra sleep is important: after the kb.End, it sometimes takes a while for the active element to be reset // This extra sleep is important: after the kb.End,
continue // ignore this error: no active element, or active element has no href // it sometimes takes a while for the scrolled page to be in a state
// which allows the next kb.ArrowRight to take effect and actually select
// the next element at the new scroll position.
time.Sleep(tick)
continue // ignore this error: no active element, or active element has no href
} }
if active == prev { if active == prev {
lastRepeated++ lastRepeated++
@ -309,7 +315,6 @@ func navToEnd(ctx context.Context) error {
break break
} }
prev = active prev = active
// time.Sleep(tick)
} }
if *verboseFlag { if *verboseFlag {
log.Printf("Successfully jumped to the end: %s", active) log.Printf("Successfully jumped to the end: %s", active)

Loading…
Cancel
Save