mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-09-19 23:21:34 +02:00
Simplify menu tab loading process
This commit is contained in:
parent
dd37321626
commit
c28973319d
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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,9 +116,8 @@ open class FrostWebViewClient(val web: FrostWebView) : BaseWebViewClient() {
|
||||
/**
|
||||
* Main injections for facebook content
|
||||
*/
|
||||
private fun WebView.facebookJsInject() {
|
||||
jsInject(
|
||||
// CssHider.CORE,
|
||||
protected open val facebookJsInjectors: List<InjectorContract> = listOf(
|
||||
// CssHider.CORE,
|
||||
CssHider.HEADER,
|
||||
CssHider.COMPOSER.maybe(!prefs.showComposer),
|
||||
CssHider.STORIES.maybe(!prefs.showStories),
|
||||
@ -135,12 +135,14 @@ 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,
|
||||
prefs = prefs
|
||||
)
|
||||
|
||||
private fun WebView.facebookJsInject() {
|
||||
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<InjectorContract> =
|
||||
super.facebookJsInjectors - CssHider.HEADER
|
||||
|
||||
override fun emit(flag: Int) {
|
||||
super.emit(flag)
|
||||
when (flag) {
|
||||
|
@ -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
|
||||
});
|
||||
|
||||
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);
|
||||
// menu container
|
||||
const bookmarkFlyout = document.querySelector('#bookmarks_flyout');
|
||||
if (bookmarkFlyout instanceof HTMLElement) {
|
||||
bookmarkFlyout.style.marginTop = "0";
|
||||
}
|
||||
while (menu.childNodes.length) {
|
||||
viewport.appendChild(menu.childNodes[0]);
|
||||
}
|
||||
Frost.emit(0);
|
||||
|
||||
// Js handling is a bit slow so we need to wait
|
||||
setTimeout(() => {
|
||||
y.disconnect();
|
||||
console.log('Unhook styler');
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
x.observe(jewel, {
|
||||
childList: true,
|
||||
subtree: true
|
||||
});
|
||||
menuA.click();
|
||||
console.log("Menu setup clicked");
|
||||
// Reaction is also slow so we need to wait
|
||||
setTimeout(() => {
|
||||
Frost.emit(0);
|
||||
}, 100);
|
||||
}, 200);
|
||||
}).call(undefined);
|
||||
|
Loading…
Reference in New Issue
Block a user