Files

35 lines
1.1 KiB
Go

package quanwenrss
import (
"golang.org/x/net/html"
"strings"
)
// Restriction evidence is inspected before presentation chrome is removed.
func bodyRestricted(raw string) bool {
t := html.NewTokenizer(strings.NewReader(raw))
for {
kind := t.Next()
if kind == html.ErrorToken {
return false
}
if kind != html.StartTagToken && kind != html.SelfClosingTagToken {
continue
}
token := t.Token()
for _, a := range token.Attr {
value := strings.ToLower(a.Val)
if (a.Key == "data-content-state" && (value == "partial" || value == "incomplete")) || (a.Key == "data-content-truncated" && value == "true") || (a.Key == "data-accessible" && value == "false") {
return true
}
if a.Key == "class" || a.Key == "id" || a.Key == "data-component" || a.Key == "data-testid" || a.Key == "data-test" || a.Key == "src" {
for _, marker := range []string{"paywall", "giftarticle", "captcha", "challenge", "cf-chl", "placeholder", "skeleton", "truncated", "partial"} {
if strings.Contains(value, marker) {
return true
}
}
}
}
}
}