workaround newly js only twitter site for hoot:
Ted Unangst tedu@tedunangst.com
Tue, 30 Jun 2020 16:37:35 -0400
2 files changed,
16 insertions(+),
7 deletions(-)
M
docs/changelog.txt
→
docs/changelog.txt
@@ -2,6 +2,8 @@ changelog
=== next ++ Workaround js only twitter for hoot: feature. + ++ Boing boom tschak chonky chatter. + Quote unquote reliability improvements.
M
hoot.go
→
hoot.go
@@ -29,8 +29,8 @@ "golang.org/x/net/html"
"humungus.tedunangst.com/r/webs/htfilter" ) -var tweetsel = cascadia.MustCompile("p.tweet-text") -var linksel = cascadia.MustCompile(".time a.tweet-timestamp") +var tweetsel = cascadia.MustCompile("div.tweet-text") +var linksel = cascadia.MustCompile("td.timestamp a") var replyingto = cascadia.MustCompile(".ReplyingToContextBelowAuthor") var authorregex = regexp.MustCompile("twitter.com/([^/]+)")@@ -43,6 +43,8 @@ log.Printf("error parsing hoot: %s", err)
return url } divs := tweetsel.MatchAll(root) + + url = strings.Replace(url, "mobile.twitter.com", "twitter.com", -1) var wanted string wantmatch := authorregex.FindStringSubmatch(url)@@ -56,21 +58,25 @@ var htf htfilter.Filter
htf.Imager = func(node *html.Node) string { return "" } - for _, div := range divs { + for i, div := range divs { twp := div.Parent.Parent.Parent + link := url alink := linksel.MatchFirst(twp) if alink == nil { - log.Printf("missing link") - continue + if i != 0 { + log.Printf("missing link") + continue + } + } else { + link = "https://twitter.com" + htfilter.GetAttr(alink, "href") } replto := replyingto.MatchFirst(twp) if replto != nil { continue } - link := "https://twitter.com" + htfilter.GetAttr(alink, "href") authormatch := authorregex.FindStringSubmatch(link) if len(authormatch) < 2 { - log.Printf("no author?") + log.Printf("no author?: %s", link) continue } author := authormatch[1]@@ -103,6 +109,7 @@ if url[0] == ' ' {
url = url[1:] } url = strings.Replace(url, "mobile.twitter.com", "twitter.com", -1) + url = strings.Replace(url, "twitter.com", "mobile.twitter.com", -1) log.Printf("hooterizing %s", url) req, err := http.NewRequest("GET", url, nil) if err != nil {