- 实现EPUB阅读器搜索功能及选中注释功能 - 优化CFI模块,修复代码审查发现的11个问题 - 实现大书远距目录跳转与后台补全优化方案 - 优化设置面板与章节运行时联动 - 重构及大量改进优化
47 lines
1.7 KiB
Swift
47 lines
1.7 KiB
Swift
|
|
import Foundation
|
|
|
|
extension RDEPUBParser {
|
|
|
|
public func readingProfile() -> RDEPUBReadingProfile {
|
|
if metadata.layout == .fixed {
|
|
return .webFixedLayout
|
|
}
|
|
return hasInteractiveContent() ? .webInteractive : .textReflowable
|
|
}
|
|
|
|
public func hasInteractiveContent() -> Bool {
|
|
let interactiveMediaTypes = [
|
|
"application/javascript",
|
|
"text/javascript",
|
|
"application/ecmascript"
|
|
]
|
|
if manifest.values.contains(where: { item in
|
|
interactiveMediaTypes.contains(item.mediaType.lowercased()) || item.properties.contains("scripted")
|
|
}) {
|
|
return true
|
|
}
|
|
|
|
for item in spine where item.linear && (item.mediaType.contains("html") || item.mediaType.contains("xhtml")) {
|
|
guard let html = htmlString(forRelativePath: item.href) else {
|
|
continue
|
|
}
|
|
if containsInteractiveMarkup(html) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
private func containsInteractiveMarkup(_ html: String) -> Bool {
|
|
let interactivePattern = #"<(script|iframe|video|audio|canvas|object|embed)\b|\bon(load|click|touchstart|touchend|mouseover|submit|change|input)=|hype_generated_script|swiper|webview"#
|
|
if html.range(of: interactivePattern, options: [.regularExpression, .caseInsensitive]) != nil {
|
|
return true
|
|
}
|
|
|
|
let dynamicSVGPattern = #"<svg\b[^>]*>[\s\S]*?(<(script|foreignObject|animate|animateMotion|animateTransform|set)\b|\bon(load|click|touchstart|touchend|mouseover)=)"#
|
|
return html.range(of: dynamicSVGPattern, options: [.regularExpression, .caseInsensitive]) != nil
|
|
}
|
|
}
|