From dd37321626e6e5d604f12d7ffb00eeb789df0d5f Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 21 Nov 2021 22:14:23 -0800 Subject: Change basse url for menu --- app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt index 9b08c775..5d4df797 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt @@ -46,7 +46,12 @@ enum class FbItem( FRIENDS(R.string.friends, GoogleMaterial.Icon.gmd_person_add, "friends/center/requests"), GROUPS(R.string.groups, GoogleMaterial.Icon.gmd_group, "groups"), MARKETPLACE(R.string.marketplace, GoogleMaterial.Icon.gmd_store, "marketplace"), - MENU(R.string.menu, GoogleMaterial.Icon.gmd_menu, "settings"), + /* + * Unlike other urls, menus cannot be linked directly as it is a soft reference. Instead, we can + * pick any url with the blue bar and manually click to enter the menu. + * The notifications page was picked arbitrarily as I assume it has the smallest loading footprint. + */ + MENU(R.string.menu, GoogleMaterial.Icon.gmd_menu, "notifications.php"), MESSAGES(R.string.messages, MaterialDesignIconic.Icon.gmi_comments, "messages"), MESSENGER(R.string.messenger, CommunityMaterial.Icon2.cmd_facebook_messenger, "", prefix = HTTPS_MESSENGER_COM), NOTES(R.string.notes, CommunityMaterial.Icon3.cmd_note, "notes"), -- cgit v1.2.3 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 From ba458a612610512e28b65bafcf74177ddc77bbbe Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sun, 21 Nov 2021 23:56:20 -0800 Subject: Improve menu loading when going back --- .../pitchedapps/frost/fragments/WebFragments.kt | 16 --------------- .../com/pitchedapps/frost/injectors/CssAsset.kt | 7 ++++++- .../com/pitchedapps/frost/injectors/JsAssets.kt | 2 +- .../pitchedapps/frost/web/FrostWebViewClients.kt | 13 +++++++++++- app/src/main/play/en-US/whatsnew | 3 ++- app/src/main/res/xml/frost_changelog.xml | 2 +- app/src/web/ts/menu.ts | 10 ++------- app/src/web/ts/menu_quick.ts | 24 ++++++++++++++++++++++ docs/Changelog.md | 1 + 9 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 app/src/web/ts/menu_quick.ts diff --git a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt index 3cac92af..29473461 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/fragments/WebFragments.kt @@ -61,20 +61,4 @@ class WebFragment : BaseFragment() { } super.updateFab(contract) } - - override fun onBackPressed(): Boolean { - if (baseEnum == FbItem.MENU) { - val core = core - val web = core as? WebView - if (web != null && web.canGoBack() && !web.canGoBackOrForward(-2)) { - // If menu item + we are at the second last entry, reload the base - // To properly inflate the menu - // Related to https://github.com/AllanWang/Frost-for-Facebook/issues/1593 - core.clearHistory() - core.reloadBase(true) - return true - } - } - return super.onBackPressed() - } } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt index b384efad..a1f66520 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt @@ -23,7 +23,12 @@ import com.pitchedapps.frost.prefs.Prefs * Small misc inline css assets */ enum class CssAsset(private val content: String) : InjectorContract { - FullSizeImage("div._4prr[style*=\"max-width\"][style*=\"max-height\"]{max-width:none !important;max-height:none !important}") + FullSizeImage("div._4prr[style*=\"max-width\"][style*=\"max-height\"]{max-width:none !important;max-height:none !important}"), + + /* + * Remove top margin and hide some contents from the top bar and notification page (as it's our base url) + */ + Menu("#bookmarks_flyout{margin-top:0 !important}#notifications_list{display:none !important}") ; val injector: JsInjector by lazy { diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt index bceb9b3e..f1c958bc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt @@ -34,7 +34,7 @@ import java.util.Locale * The enum name must match the css file name */ enum class JsAssets(private val singleLoad: Boolean = true) : InjectorContract { - MENU, CLICK_A, CONTEXT_A, MEDIA, HEADER_BADGES, TEXTAREA_LISTENER, NOTIF_MSG, + MENU, MENU_QUICK(singleLoad = false), CLICK_A, CONTEXT_A, MEDIA, HEADER_BADGES, TEXTAREA_LISTENER, NOTIF_MSG, DOCUMENT_WATCHER, HORIZONTAL_SCROLLING, AUTO_RESIZE_TEXTAREA(singleLoad = false), SCROLL_STOP, ; 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 3e906a23..ad7f7858 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -302,7 +302,7 @@ class FrostWebViewClientMenu(web: FrostWebView) : FrostWebViewClient(web) { * Instead, we remove the flyout margins within the js script so that it covers the header. */ override val facebookJsInjectors: List = - super.facebookJsInjectors - CssHider.HEADER + super.facebookJsInjectors - CssHider.HEADER + CssAsset.Menu override fun emit(flag: Int) { super.emit(flag) @@ -313,6 +313,17 @@ class FrostWebViewClientMenu(web: FrostWebView) : FrostWebViewClient(web) { } } + /* + * Facebook doesn't properly load back to the menu even in standard browsers. + * Instead, if we detect the base soft url, we will manually click the menu item + */ + override fun doUpdateVisitedHistory(view: WebView, url: String?, isReload: Boolean) { + super.doUpdateVisitedHistory(view, url, isReload) + if (url?.startsWith(FbItem.MENU.url) == true) { + jsInject(JsAssets.MENU_QUICK, prefs = prefs) + } + } + override fun onPageFinishedActions(url: String) { // Skip } diff --git a/app/src/main/play/en-US/whatsnew b/app/src/main/play/en-US/whatsnew index 2e50ba70..b60f93c3 100644 --- a/app/src/main/play/en-US/whatsnew +++ b/app/src/main/play/en-US/whatsnew @@ -1,3 +1,4 @@ v3.1.2 -* Fix loading full size images \ No newline at end of file +* Fix loading full size images +* Fix menu tab \ No newline at end of file diff --git a/app/src/main/res/xml/frost_changelog.xml b/app/src/main/res/xml/frost_changelog.xml index 9bc126fb..146346b5 100644 --- a/app/src/main/res/xml/frost_changelog.xml +++ b/app/src/main/res/xml/frost_changelog.xml @@ -8,7 +8,7 @@ - + diff --git a/app/src/web/ts/menu.ts b/app/src/web/ts/menu.ts index a288ba07..5b3e6fa9 100644 --- a/app/src/web/ts/menu.ts +++ b/app/src/web/ts/menu.ts @@ -1,4 +1,4 @@ -// Click menu and move contents to main view +// Click menu after delay and notify (function () { const viewport = document.querySelector("#viewport"); const root = document.querySelector("#root"); @@ -20,12 +20,6 @@ return } - // menu container - const bookmarkFlyout = document.querySelector('#bookmarks_flyout'); - if (bookmarkFlyout instanceof HTMLElement) { - bookmarkFlyout.style.marginTop = "0"; - } - // Js handling is a bit slow so we need to wait setTimeout(() => { menuA.click(); @@ -34,5 +28,5 @@ setTimeout(() => { Frost.emit(0); }, 100); - }, 200); + }, 500); }).call(undefined); diff --git a/app/src/web/ts/menu_quick.ts b/app/src/web/ts/menu_quick.ts new file mode 100644 index 00000000..f7b117a4 --- /dev/null +++ b/app/src/web/ts/menu_quick.ts @@ -0,0 +1,24 @@ +// Copy of menu.ts without timeouts or notifications +(function () { + const viewport = document.querySelector("#viewport"); + const root = document.querySelector("#root"); + const bookmarkJewel = document.querySelector("#bookmarks_jewel"); + if (!viewport || !root || !bookmarkJewel) { + console.log('Menu.js: main elements not found'); + Frost.emit(0); + return + } + const menuA = bookmarkJewel.querySelector("a"); + if (!menuA) { + console.log('Menu.js: menu links not found'); + Frost.emit(0); + return + } + const jewel = document.querySelector('#mJewelNav'); + if (!jewel) { + console.log('Menu.js: jewel is null'); + return + } + + menuA.click(); +}).call(undefined); diff --git a/docs/Changelog.md b/docs/Changelog.md index 87a48b87..b3596f36 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -2,6 +2,7 @@ ## v3.1.2 * Fix loading full size images +* Fix menu tab ## v3.1.1 * Many internal fixes to address 3.1.0 issues -- cgit v1.2.3 From f448eaf4c21c40778663f2d11b6f6f8ad8855b0f Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Mon, 22 Nov 2021 12:06:07 -0800 Subject: Default menu to home as some entries forcefully redirect there --- app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt | 12 +++++++++--- .../main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt | 4 ++-- .../kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt index 5d4df797..7d9d5c12 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/facebook/FbItem.kt @@ -46,14 +46,20 @@ enum class FbItem( FRIENDS(R.string.friends, GoogleMaterial.Icon.gmd_person_add, "friends/center/requests"), GROUPS(R.string.groups, GoogleMaterial.Icon.gmd_group, "groups"), MARKETPLACE(R.string.marketplace, GoogleMaterial.Icon.gmd_store, "marketplace"), + /* * Unlike other urls, menus cannot be linked directly as it is a soft reference. Instead, we can * pick any url with the blue bar and manually click to enter the menu. - * The notifications page was picked arbitrarily as I assume it has the smallest loading footprint. + * We pick home.php as some back interactions default to home regardless of the base url. */ - MENU(R.string.menu, GoogleMaterial.Icon.gmd_menu, "notifications.php"), + MENU(R.string.menu, GoogleMaterial.Icon.gmd_menu, "home.php"), MESSAGES(R.string.messages, MaterialDesignIconic.Icon.gmi_comments, "messages"), - MESSENGER(R.string.messenger, CommunityMaterial.Icon2.cmd_facebook_messenger, "", prefix = HTTPS_MESSENGER_COM), + MESSENGER( + R.string.messenger, + CommunityMaterial.Icon2.cmd_facebook_messenger, + "", + prefix = HTTPS_MESSENGER_COM + ), NOTES(R.string.notes, CommunityMaterial.Icon3.cmd_note, "notes"), NOTIFICATIONS(R.string.notifications, MaterialDesignIconic.Icon.gmi_globe, "notifications"), ON_THIS_DAY(R.string.on_this_day, GoogleMaterial.Icon.gmd_today, "onthisday"), diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt index a1f66520..39e2332a 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAsset.kt @@ -26,9 +26,9 @@ enum class CssAsset(private val content: String) : InjectorContract { FullSizeImage("div._4prr[style*=\"max-width\"][style*=\"max-height\"]{max-width:none !important;max-height:none !important}"), /* - * Remove top margin and hide some contents from the top bar and notification page (as it's our base url) + * Remove top margin and hide some contents from the top bar and home page (as it's our base url) */ - Menu("#bookmarks_flyout{margin-top:0 !important}#notifications_list{display:none !important}") + Menu("#bookmarks_flyout{margin-top:0 !important}#m_news_feed_stream,#MComposer{display:none !important}") ; val injector: JsInjector by lazy { 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 ad7f7858..3b332199 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClients.kt @@ -135,7 +135,7 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() { JsAssets.DOCUMENT_WATCHER, JsAssets.HORIZONTAL_SCROLLING, JsAssets.AUTO_RESIZE_TEXTAREA.maybe(prefs.autoExpandTextBox), -// JsAssets.CLICK_A, + JsAssets.CLICK_A, JsAssets.CONTEXT_A, JsAssets.MEDIA, JsAssets.SCROLL_STOP, -- cgit v1.2.3