Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
fix: OriginSrc not working on new frs page
Browse files Browse the repository at this point in the history
  • Loading branch information
mkx173 committed Apr 20, 2024
1 parent eefdbcd commit 5dcb96a
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions app/src/main/java/gm/tieba/tabswitch/hooker/auto/OriginSrc.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.Uri;

import androidx.annotation.NonNull;

import org.json.JSONArray;
import org.json.JSONObject;


import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedHelpers;
import gm.tieba.tabswitch.XposedContext;
Expand All @@ -32,6 +34,8 @@ public String key() {
private static XC_MethodHook.Unhook picListUnhook;
private static XC_MethodHook.Unhook pbContentUnhook;
private static XC_MethodHook.Unhook mediaUnhook;
private static XC_MethodHook.Unhook picInfoUnhook;
private static XC_MethodHook.Unhook feedPicComponentUnhook;

private static void doHook() {
if (isHooked) return;
Expand Down Expand Up @@ -76,6 +80,38 @@ protected void beforeHookedMethod(final XC_MethodHook.MethodHookParam param) thr
}
}
});
picInfoUnhook = XposedHelpers.findAndHookMethod("tbclient.PicInfo$Builder", sClassLoader, "build", boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(final XC_MethodHook.MethodHookParam param) throws Throwable {
final String[] strings = new String[]{"small_pic_url", "big_pic_url"};
for (final String string : strings) {
XposedHelpers.setObjectField(param.thisObject, string, XposedHelpers
.getObjectField(param.thisObject, "origin_pic_url"));
}
}
});
feedPicComponentUnhook = XposedHelpers.findAndHookMethod("tbclient.FeedPicComponent$Builder", sClassLoader, "build", boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(final XC_MethodHook.MethodHookParam param) throws Throwable {
String schema = (String) XposedHelpers.getObjectField(param.thisObject, "schema");
String paramsJson = Uri.parse(schema).getQueryParameter("params");

JSONObject jsonObject = new JSONObject(paramsJson);
JSONObject pageParams = jsonObject.getJSONObject("pageParams");
JSONArray picDataList = pageParams.getJSONArray("pic_data_list");

for (int i = 0; i < picDataList.length(); i++) {
JSONObject picData = picDataList.getJSONObject(i);
String originPicUrl = picData.getString("origin_pic_url");
picData.put("big_pic_url", originPicUrl);
picData.put("small_pic_url", originPicUrl);
picData.put("is_show_origin_btn", 0);
}

String modifiedUri = "tiebaapp://router/portal?params=" + jsonObject.toString();
XposedHelpers.setObjectField(param.thisObject, "schema", modifiedUri);
}
});
isHooked = true;
}

Expand All @@ -93,6 +129,14 @@ private static void doUnHook() {
mediaUnhook.unhook();
mediaUnhook = null;
}
if (picInfoUnhook != null) {
picInfoUnhook.unhook();
picInfoUnhook = null;
}
if (feedPicComponentUnhook != null) {
feedPicComponentUnhook.unhook();
feedPicComponentUnhook = null;
}
isHooked = false;
}

Expand Down

0 comments on commit 5dcb96a

Please sign in to comment.