From b583cc86c90430bcd487c7d5de4304c0835fb0bd Mon Sep 17 00:00:00 2001 From: NoPlagiarism <110791-NoPlagiarism@users.noreply.framagit.org> Date: Fri, 30 Sep 2022 12:53:59 +0000 Subject: [PATCH] Support *.reddit.com (closes #86) --- app/src/fullLinks/AndroidManifest.xml | 2 ++ app/src/main/AndroidManifest.xml | 2 ++ .../app/fedilab/nitterizeme/helpers/Utils.java | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/src/fullLinks/AndroidManifest.xml b/app/src/fullLinks/AndroidManifest.xml index b9c8b13..ed6bd96 100644 --- a/app/src/fullLinks/AndroidManifest.xml +++ b/app/src/fullLinks/AndroidManifest.xml @@ -92,6 +92,7 @@ + @@ -198,6 +199,7 @@ + diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 593d55c..4ec53bb 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -93,6 +93,7 @@ + @@ -166,6 +167,7 @@ + diff --git a/app/src/main/java/app/fedilab/nitterizeme/helpers/Utils.java b/app/src/main/java/app/fedilab/nitterizeme/helpers/Utils.java index 45b8d0a..6ec5cc7 100644 --- a/app/src/main/java/app/fedilab/nitterizeme/helpers/Utils.java +++ b/app/src/main/java/app/fedilab/nitterizeme/helpers/Utils.java @@ -99,6 +99,7 @@ public class Utils { public static final String LAST_USED_APP_PACKAGE = "last_used_app_package"; public static final Pattern youtubePattern = Pattern.compile("(www\\.|m\\.)?(youtube\\.com|youtu\\.be|youtube-nocookie\\.com)/(((?!([\"'<])).)*)"); public static final Pattern redditPattern = Pattern.compile("(www\\.|m\\.)?(reddit\\.com|preview\\.redd\\.it|i\\.redd\\.it)/(((?!([\"'<])).)*)"); + public static final Pattern redditSubdomainPattern = Pattern.compile("([\\w_-]+)\\.reddit.com/?(?!r/)(((?!([\"'<])).)*)"); public static final Pattern nitterPattern = Pattern.compile("(mobile\\.|www\\.)?twitter.com([\\w-/]+)"); public static final Pattern bibliogramPostPattern = Pattern.compile("(m\\.|www\\.)?instagram.com(/p/[\\w-/]+)"); public static final Pattern scriberipPattern = Pattern.compile("(www\\.)?medium.com/(((?!([\"'<])).)*)"); @@ -433,7 +434,7 @@ public class Utils { } else { return url; } - } else if (Arrays.asList(reddit_domains).contains(host)) { //Reddit URL + } else if (Arrays.asList(reddit_domains).contains(host) || (host != null && host.endsWith(reddit_domains[1]))) { //Reddit URL boolean teddit_enabled = sharedpreferences.getBoolean(SET_TEDDIT_ENABLED, true); if (teddit_enabled) { String tedditHost = sharedpreferences.getString(SET_TEDDIT_HOST, MainActivity.DEFAULT_TEDDIT_HOST); @@ -442,7 +443,15 @@ public class Utils { if (tedditHost.startsWith("http")) { scheme = ""; } - Matcher matcher = redditPattern.matcher(url); + Matcher matcher = redditSubdomainPattern.matcher(url); + while (matcher.find()) { + final String subdomain = matcher.group(1); + final String path = matcher.group(2); + if (subdomain != null && subdomain.toLowerCase().compareTo("www") != 0) { + url = scheme + "reddit.com" + "/r/" + subdomain + "/" + path; + } + } + matcher = redditPattern.matcher(url); while (matcher.find()) { String redditPath = matcher.group(3); if (Objects.requireNonNull(matcher.group(2)).compareTo("preview.redd.it") == 0 || @@ -1220,7 +1229,7 @@ public class Utils { || url.contains("/maps/place") || url.contains("/amp/s/") || (host != null && host.contains(outlook_safe_domain)) || Arrays.asList(youtube_domains).contains(host) || Arrays.asList(invidious_instances).contains(host) || Arrays.asList(tiktok_domains).contains(host) || (host != null && host.endsWith(medium_domains[0]) - || (host != null && host.endsWith(wikipedia_domains[0]))); + || (host != null && host.endsWith(wikipedia_domains[0])) || (host != null && host.endsWith(reddit_domains[1]))); } public static boolean routerEnabledForHost(Context context, String url) { @@ -1242,7 +1251,7 @@ public class Utils { return sharedpreferences.getBoolean(MainActivity.SET_OSM_ENABLED, true); } else if (Arrays.asList(youtube_domains).contains(host) || Arrays.asList(invidious_instances).contains(host)) { return sharedpreferences.getBoolean(SET_INVIDIOUS_ENABLED, true); - } else if (Arrays.asList(reddit_domains).contains(host)) { + } else if (Arrays.asList(reddit_domains).contains(host) || (host != null && host.endsWith(reddit_domains[1]))) { return sharedpreferences.getBoolean(SET_TEDDIT_ENABLED, true); } else if (Arrays.asList(tiktok_domains).contains(host)) { return sharedpreferences.getBoolean(SET_PROXITOK_ENABLED, true);