From c28973319df956c6ce75998b4d213c2da31bf91b Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 21 Nov 2021 23:21:14 -0800 Subject: Simplify menu tab loading process --- .../com/pitchedapps/frost/injectors/JsInjector.kt | 2 +- .../pitchedapps/frost/web/FrostWebViewClients.kt | 59 +++++++++++++--------- app/src/web/ts/menu.ts | 50 +++++------------- 3 files changed, 48 insertions(+), 63 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt index 7c52fac7..58ebb171 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt @@ -97,7 +97,7 @@ interface InjectorContract { * Helper method to inject multiple functions simultaneously with a single callback */ fun WebView.jsInject(vararg injectors: InjectorContract, prefs: Prefs) { - injectors.filter { it != JsActions.EMPTY }.forEach { + injectors.asSequence().filter { it != JsActions.EMPTY }.forEach { it.inject(this, prefs) } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt index a6603f01..3e906a23 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -37,6 +37,7 @@ import com.pitchedapps.frost.facebook.WWW_FACEBOOK_COM import com.pitchedapps.frost.facebook.formattedFbUrl import com.pitchedapps.frost.injectors.CssAsset import com.pitchedapps.frost.injectors.CssHider +import com.pitchedapps.frost.injectors.InjectorContract import com.pitchedapps.frost.injectors.JsActions import com.pitchedapps.frost.injectors.JsAssets import com.pitchedapps.frost.injectors.ThemeProvider @@ -115,32 +116,33 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { /** * Main injections for facebook content */ + protected open val facebookJsInjectors: List = listOf( + // CssHider.CORE, + CssHider.HEADER, + CssHider.COMPOSER.maybe(!prefs.showComposer), + CssHider.STORIES.maybe(!prefs.showStories), + CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!prefs.showSuggestedFriends), + CssHider.SUGGESTED_GROUPS.maybe(!prefs.showSuggestedGroups), + themeProvider.injector(ThemeCategory.FACEBOOK), + CssHider.NON_RECENT.maybe( + (web.url?.contains("?sk=h_chr") ?: false) && + prefs.aggressiveRecents + ), + CssHider.ADS.maybe(!prefs.showFacebookAds), + CssHider.POST_ACTIONS.maybe(!prefs.showPostActions), + CssHider.POST_REACTIONS.maybe(!prefs.showPostReactions), + CssAsset.FullSizeImage.maybe(prefs.fullSizeImage), + JsAssets.DOCUMENT_WATCHER, + JsAssets.HORIZONTAL_SCROLLING, + JsAssets.AUTO_RESIZE_TEXTAREA.maybe(prefs.autoExpandTextBox), +// JsAssets.CLICK_A, + JsAssets.CONTEXT_A, + JsAssets.MEDIA, + JsAssets.SCROLL_STOP, + ) + private fun WebView.facebookJsInject() { - jsInject( -// CssHider.CORE, - CssHider.HEADER, - CssHider.COMPOSER.maybe(!prefs.showComposer), - CssHider.STORIES.maybe(!prefs.showStories), - CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!prefs.showSuggestedFriends), - CssHider.SUGGESTED_GROUPS.maybe(!prefs.showSuggestedGroups), - themeProvider.injector(ThemeCategory.FACEBOOK), - CssHider.NON_RECENT.maybe( - (web.url?.contains("?sk=h_chr") ?: false) && - prefs.aggressiveRecents - ), - CssHider.ADS.maybe(!prefs.showFacebookAds), - CssHider.POST_ACTIONS.maybe(!prefs.showPostActions), - CssHider.POST_REACTIONS.maybe(!prefs.showPostReactions), - CssAsset.FullSizeImage.maybe(prefs.fullSizeImage), - JsAssets.DOCUMENT_WATCHER, - JsAssets.HORIZONTAL_SCROLLING, - JsAssets.AUTO_RESIZE_TEXTAREA.maybe(prefs.autoExpandTextBox), - JsAssets.CLICK_A, - JsAssets.CONTEXT_A, - JsAssets.MEDIA, - JsAssets.SCROLL_STOP, - prefs = prefs - ) + jsInject(*facebookJsInjectors.toTypedArray(), prefs = prefs) } private fun WebView.messengerJsInject() { @@ -295,6 +297,13 @@ class FrostWebViewClientMenu(web: FrostWebView) : FrostWebViewClient(web) { jsInject(JsAssets.MENU, prefs = prefs) } + /* + * We do not inject headers as they include the menu flyout. + * Instead, we remove the flyout margins within the js script so that it covers the header. + */ + override val facebookJsInjectors: List = + super.facebookJsInjectors - CssHider.HEADER + override fun emit(flag: Int) { super.emit(flag) when (flag) { diff --git a/app/src/web/ts/menu.ts b/app/src/web/ts/menu.ts index b26e9cc9..a288ba07 100644 --- a/app/src/web/ts/menu.ts +++ b/app/src/web/ts/menu.ts @@ -20,43 +20,19 @@ return } - /* - * Required to remove height restrictions - */ - const y = new MutationObserver(() => { - viewport.removeAttribute('style'); - root.removeAttribute('style'); - }); - - y.observe(viewport, { - attributes: true - }); - y.observe(root, { - attributes: true - }); + // menu container + const bookmarkFlyout = document.querySelector('#bookmarks_flyout'); + if (bookmarkFlyout instanceof HTMLElement) { + bookmarkFlyout.style.marginTop = "0"; + } - const x = new MutationObserver(() => { - const menu = document.querySelector('.mSideMenu'); - if (menu) { - x.disconnect(); - console.log("Found side menu"); - // Transfer elements - while (root.firstChild) { - root.removeChild(root.firstChild); - } - while (menu.childNodes.length) { - viewport.appendChild(menu.childNodes[0]); - } + // Js handling is a bit slow so we need to wait + setTimeout(() => { + menuA.click(); + console.log("Menu setup clicked"); + // Reaction is also slow so we need to wait + setTimeout(() => { Frost.emit(0); - setTimeout(() => { - y.disconnect(); - console.log('Unhook styler'); - }, 500); - } - }); - x.observe(jewel, { - childList: true, - subtree: true - }); - menuA.click(); + }, 100); + }, 200); }).call(undefined); -- cgit v1.2.3