feat(lanzou): add RemoveJSComment function to clean JavaScript comments from HTML

This commit is contained in:
MadDogOwner 2025-04-16 05:27:54 +08:00
parent 88abb323cb
commit d0a8df768e
No known key found for this signature in database
GPG Key ID: 0730AD911EB33562

View File

@ -78,6 +78,45 @@ func RemoveNotes(html string) string {
})
}
// 清理JS注释
func RemoveJSComment(data string) string {
var result strings.Builder
inComment := false
inSingleLineComment := false
for i := 0; i < len(data); i++ {
v := data[i]
if inSingleLineComment && (v == '\n' || v == '\r') {
inSingleLineComment = false
result.WriteByte(v)
continue
}
if inComment {
if v == '*' && i+1 < len(data) && data[i+1] == '/' {
inComment = false
i++
}
continue
}
if v == '/' && i+1 < len(data) {
nextChar := data[i+1]
if nextChar == '*' {
inComment = true
i++
continue
} else if nextChar == '/' {
inSingleLineComment = true
i++
continue
}
}
result.WriteByte(v)
}
return result.String()
}
var findAcwScV2Reg = regexp.MustCompile(`arg1='([0-9A-Z]+)'`)
// 在页面被过多访问或其他情况下,有时候会先返回一个加密的页面,其执行计算出一个acw_sc__v2后放入页面后再重新访问页面才能获得正常页面