import Foundation enum RedditAuthChromeStyle { /// Hides Google sign-in on Reddit auth surfaces. Google OAuth does not work inside /// WKWebView subframes on macOS, so we remove the option instead of showing a broken flow. static let injectionScript = """ (function() { if (window.__reddoraGoogleLoginHidden) return; window.__reddoraGoogleLoginHidden = true; const GOOGLE_PATTERNS = [ /continue with google/i, /sign in with google/i, /sign in with google account/i ]; const SELECTORS = 'button, a, [role="button"], faceplate-tracker, faceplate-button'; function buttonLabel(node) { return ( (node.textContent || '') + ' ' + (node.getAttribute('aria-label') || '') + ' ' + (node.getAttribute('title') || '') ).trim(); } function isGoogleLoginButton(node) { return GOOGLE_PATTERNS.some(function(pattern) { return pattern.test(buttonLabel(node)); }); } function hideElement(node) { const target = node.closest('faceplate-tracker, faceplate-button') || node; target.style.setProperty('display', 'none', 'important'); target.style.setProperty('visibility', 'hidden', 'important'); target.setAttribute('aria-hidden', 'true'); target.setAttribute('hidden', ''); } function collectClickables(root, results) { if (!root) return; if (root.querySelectorAll) { root.querySelectorAll(SELECTORS).forEach(function(node) { results.push(node); }); } const children = root.children || root.childNodes; for (let i = 0; i < children.length; i++) { const child = children[i]; if (!(child instanceof Element)) continue; if (child.shadowRoot) { collectClickables(child.shadowRoot, results); } collectClickables(child, results); } } function hideGoogleLoginButtons(root) { const nodes = []; collectClickables(root || document.documentElement, nodes); for (let i = 0; i < nodes.length; i++) { const node = nodes[i]; if (!isGoogleLoginButton(node)) continue; hideElement(node); } } document.addEventListener('click', function(event) { const path = event.composedPath ? event.composedPath() : [event.target]; for (let i = 0; i < path.length; i++) { const node = path[i]; if (!(node instanceof Element)) continue; if (!node.matches || !node.matches(SELECTORS)) continue; if (!isGoogleLoginButton(node)) continue; event.preventDefault(); event.stopImmediatePropagation(); return; } }, true); hideGoogleLoginButtons(document); const observer = new MutationObserver(function() { hideGoogleLoginButtons(document); }); observer.observe(document.documentElement, { childList: true, subtree: true }); [250, 750, 1500, 3000].forEach(function(delay) { setTimeout(function() { hideGoogleLoginButtons(document); }, delay); }); })(); """ }