Prechádzať zdrojové kódy

Hide Reddit header login controls and auth modal close button in the embedded WebView.

Inject home and auth chrome styles so the in-app Reddit experience matches the intended UI without the header Log In/menu buttons or sign-up modal X.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 1 mesiac pred
rodič
commit
79366564c0

+ 14 - 0
Reddit App/Managers/RedditWebViewManager.swift

@@ -19,6 +19,20 @@ enum RedditWebViewManager {
         )
         configuration.userContentController.addUserScript(boundaryScript)
 
+        let chromeScript = WKUserScript(
+            source: RedditHomeChromeStyle.injectionScript,
+            injectionTime: .atDocumentEnd,
+            forMainFrameOnly: true
+        )
+        configuration.userContentController.addUserScript(chromeScript)
+
+        let authChromeScript = WKUserScript(
+            source: RedditAuthChromeStyle.injectionScript,
+            injectionTime: .atDocumentEnd,
+            forMainFrameOnly: true
+        )
+        configuration.userContentController.addUserScript(authChromeScript)
+
         return configuration
     }
 

+ 27 - 0
Reddit App/Utilities/RedditAuthChromeStyle.swift

@@ -0,0 +1,27 @@
+import Foundation
+
+enum RedditAuthChromeStyle {
+    /// Hides Reddit auth modal close buttons in the embedded WebView.
+    static let injectionScript = """
+    (function() {
+      const STYLE_ID = 'reddora-auth-chrome-style';
+      if (document.getElementById(STYLE_ID)) return;
+
+      const style = document.createElement('style');
+      style.id = STYLE_ID;
+      style.textContent = `
+        auth-flow-modal button[aria-label="Close"],
+        auth-flow-modal button[aria-label="close"],
+        faceplate-modal button[aria-label="Close"],
+        shreddit-signup-drawer button[aria-label="Close"],
+        [role="dialog"] button[aria-label="Close"] {
+          display: none !important;
+          visibility: hidden !important;
+          pointer-events: none !important;
+        }
+      `;
+
+      (document.head || document.documentElement).appendChild(style);
+    })();
+    """
+}

+ 27 - 0
Reddit App/Utilities/RedditHomeChromeStyle.swift

@@ -0,0 +1,27 @@
+import Foundation
+
+enum RedditHomeChromeStyle {
+    /// Hides Reddit's header Log In button and user-menu trigger in the embedded WebView.
+    static let injectionScript = """
+    (function() {
+      const STYLE_ID = 'reddora-home-chrome-style';
+      if (document.getElementById(STYLE_ID)) return;
+
+      const style = document.createElement('style');
+      style.id = STYLE_ID;
+      style.textContent = `
+        #login-button,
+        faceplate-tracker:has(#login-button),
+        #expand-user-drawer-button,
+        activate-feature:has(#expand-user-drawer-button),
+        rpl-tooltip:has(#expand-user-drawer-button) {
+          display: none !important;
+          visibility: hidden !important;
+          pointer-events: none !important;
+        }
+      `;
+
+      (document.head || document.documentElement).appendChild(style);
+    })();
+    """
+}

+ 2 - 0
Reddit App/Views/RedditWebView.swift

@@ -38,6 +38,8 @@ struct RedditWebView: NSViewRepresentable {
 
         func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
             webView.evaluateJavaScript(RedditPostBoundaryStyle.injectionScript, completionHandler: nil)
+            webView.evaluateJavaScript(RedditHomeChromeStyle.injectionScript, completionHandler: nil)
+            webView.evaluateJavaScript(RedditAuthChromeStyle.injectionScript, completionHandler: nil)
             scheduleSubmitPrefillIfNeeded(on: webView)
         }