feat: Open Url Out Bot WebView Regex
This commit is contained in:
parent
0532e97ff2
commit
5a1203d2a8
@ -100,6 +100,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import xyz.nextalone.nagram.NaConfig;
|
||||
|
||||
public abstract class BotWebViewContainer extends FrameLayout implements NotificationCenter.NotificationCenterDelegate {
|
||||
private final static String DURGER_KING_USERNAME = "DurgerKingBot";
|
||||
@ -1983,6 +1986,19 @@ public abstract class BotWebViewContainer extends FrameLayout implements Notific
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
Uri uriNew = Uri.parse(url);
|
||||
|
||||
// ----- Nagram Hook start -----
|
||||
String urlPatternStr = NaConfig.INSTANCE.getOpenUrlOutBotWebViewRegex().String();
|
||||
if (botWebViewContainer != null && !urlPatternStr.isEmpty()) {
|
||||
Pattern urlPattern = Pattern.compile(urlPatternStr, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
|
||||
if (urlPattern.matcher(url).find()) {
|
||||
botWebViewContainer.onOpenUri(uriNew);
|
||||
d("shouldOverrideUrlLoading("+url+") = true");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// ----- Nagram Hook end -----
|
||||
|
||||
if (botWebViewContainer != null && Browser.isInternalUri(uriNew, null)) {
|
||||
if (MessagesController.getInstance(botWebViewContainer.currentAccount).webAppAllowedProtocols != null &&
|
||||
MessagesController.getInstance(botWebViewContainer.currentAccount).webAppAllowedProtocols.contains(uriNew.getScheme())) {
|
||||
|
@ -45,6 +45,7 @@ import org.telegram.ui.Components.UndoView;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import kotlin.Unit;
|
||||
|
||||
@ -108,6 +109,16 @@ public class NekoExperimentalSettingsActivity extends BaseNekoXSettingsActivity
|
||||
private final AbstractConfigCell regexFiltersEnableInChatsRow = cellGroup.appendCell(new ConfigCellTextCheck(NaConfig.INSTANCE.getRegexFiltersEnableInChats()));
|
||||
private final AbstractConfigCell disableChatActionRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableChatAction));
|
||||
private final AbstractConfigCell disableChoosingStickerRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableChoosingSticker));
|
||||
private final AbstractConfigCell openUrlOutBotWebViewRegexRow = cellGroup.appendCell(new ConfigCellTextInput(null, NaConfig.INSTANCE.getOpenUrlOutBotWebViewRegex(),
|
||||
null, null,
|
||||
(input) -> {
|
||||
try {
|
||||
Pattern.compile(input, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
|
||||
return input;
|
||||
} catch (Exception ignored) {
|
||||
return "";
|
||||
}
|
||||
}));
|
||||
private final AbstractConfigCell divider1 = cellGroup.appendCell(new ConfigCellDivider());
|
||||
|
||||
// Story
|
||||
|
@ -638,6 +638,12 @@ object NaConfig {
|
||||
ConfigItem.configTypeInt,
|
||||
0
|
||||
)
|
||||
val openUrlOutBotWebViewRegex =
|
||||
addConfig(
|
||||
"OpenUrlOutBotWebViewRegex",
|
||||
ConfigItem.configTypeString,
|
||||
""
|
||||
)
|
||||
|
||||
private fun addConfig(
|
||||
k: String,
|
||||
|
@ -158,4 +158,5 @@
|
||||
<string name="ShowTimeHint">点击消息时间显示详细信息</string>
|
||||
<string name="SearchHashtagDefaultPageChannel">在频道点击标签默认搜索页面</string>
|
||||
<string name="SearchHashtagDefaultPageChat">在其他对话点击标签默认搜索页面</string>
|
||||
<string name="OpenUrlOutBotWebViewRegex">指定 URL Regex 跳出 bot webview</string>
|
||||
</resources>
|
||||
|
@ -158,4 +158,5 @@
|
||||
<string name="ShowTimeHint">Click message time to display details</string>
|
||||
<string name="SearchHashtagDefaultPageChannel">Channel Click Hashtag Default Search Page</string>
|
||||
<string name="SearchHashtagDefaultPageChat">Chat Click Hashtag Default Search Page</string>
|
||||
<string name="OpenUrlOutBotWebViewRegex">Url regex to jump out of bot webview</string>
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user