diff --git a/readeck/UI/Components/WebView.swift b/readeck/UI/Components/WebView.swift index 20d0f55..d8f6c28 100644 --- a/readeck/UI/Components/WebView.swift +++ b/readeck/UI/Components/WebView.swift @@ -37,11 +37,27 @@ struct WebView: UIViewRepresentable { func updateUIView(_ webView: WKWebView, context: Context) { context.coordinator.onHeightChange = onHeightChange context.coordinator.onScroll = onScroll - + let isDarkMode = colorScheme == .dark let fontSize = getFontSize(from: settings.fontSize ?? .extraLarge) let fontFamily = getFontFamily(from: settings.fontFamily ?? .serif) - + + // Clean up problematic HTML that kills performance + let cleanedHTML = htmlContent + // Remove Google attributes that cause navigation events + .replacingOccurrences(of: #"\s*jsaction="[^"]*""#, with: "", options: .regularExpression) + .replacingOccurrences(of: #"\s*jscontroller="[^"]*""#, with: "", options: .regularExpression) + .replacingOccurrences(of: #"\s*jsname="[^"]*""#, with: "", options: .regularExpression) + // Remove unnecessary IDs that bloat the DOM + .replacingOccurrences(of: #"\s*id="[^"]*""#, with: "", options: .regularExpression) + // Remove tabindex from non-interactive elements + .replacingOccurrences(of: #"\s*tabindex="[^"]*""#, with: "", options: .regularExpression) + // Remove role=button from figures (causes false click targets) + .replacingOccurrences(of: #"\s*role="button""#, with: "", options: .regularExpression) + // Fix invalid nested
tags inside
+ .replacingOccurrences(of: #"]*>([^<]*)"#, with: "
$1\n", options: .regularExpression)
+ .replacingOccurrences(of: #"([^<]*)"#, with: "\n$1", options: .regularExpression)
+
let styledHTML = """
@@ -222,7 +238,7 @@ struct WebView: UIViewRepresentable {
- \(htmlContent)
+ \(cleanedHTML)