Merge branch 'sub_dom_reddit' into 'develop'

Support *.reddit.com (closes #86)

Closes #86

See merge request tom79/nitterizeme!154
This commit is contained in:
Thomas 2022-09-30 12:53:59 +00:00
commit 20d814368b
3 changed files with 17 additions and 4 deletions

View File

@ -93,6 +93,7 @@
<data android:host="i.redd.it" /> <data android:host="i.redd.it" />
<data android:host="old.reddit.com" /> <data android:host="old.reddit.com" />
<data android:host="preview.redd.it" /> <data android:host="preview.redd.it" />
<data android:host="*.reddit.com" />
<!-- TIKTOK URLs --> <!-- TIKTOK URLs -->
<data android:host="tiktok.com" /> <data android:host="tiktok.com" />
@ -201,6 +202,7 @@
<data android:host="i.redd.it" /> <data android:host="i.redd.it" />
<data android:host="old.reddit.com" /> <data android:host="old.reddit.com" />
<data android:host="preview.redd.it" /> <data android:host="preview.redd.it" />
<data android:host="*.reddit.com" />
<!-- MEDIUM URLs --> <!-- MEDIUM URLs -->
<data android:host="www.medium.com" /> <data android:host="www.medium.com" />

View File

@ -94,6 +94,7 @@
<data android:host="i.redd.it" /> <data android:host="i.redd.it" />
<data android:host="old.reddit.com" /> <data android:host="old.reddit.com" />
<data android:host="preview.redd.it" /> <data android:host="preview.redd.it" />
<data android:host="*.reddit.com" />
<!-- TIKTOK URLs --> <!-- TIKTOK URLs -->
<data android:host="tiktok.com" /> <data android:host="tiktok.com" />
@ -168,6 +169,7 @@
<data android:host="i.redd.it" /> <data android:host="i.redd.it" />
<data android:host="old.reddit.com" /> <data android:host="old.reddit.com" />
<data android:host="preview.redd.it" /> <data android:host="preview.redd.it" />
<data android:host="*.reddit.com" />
<!-- TIKTOK URLs --> <!-- TIKTOK URLs -->
<data android:host="tiktok.com" /> <data android:host="tiktok.com" />

View File

@ -99,6 +99,7 @@ public class Utils {
public static final String LAST_USED_APP_PACKAGE = "last_used_app_package"; 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 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 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 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 bibliogramPostPattern = Pattern.compile("(m\\.|www\\.)?instagram.com(/p/[\\w-/]+)");
public static final Pattern scriberipPattern = Pattern.compile("(www\\.)?medium.com/(((?!([\"'<])).)*)"); public static final Pattern scriberipPattern = Pattern.compile("(www\\.)?medium.com/(((?!([\"'<])).)*)");
@ -433,7 +434,7 @@ public class Utils {
} else { } else {
return url; 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); boolean teddit_enabled = sharedpreferences.getBoolean(SET_TEDDIT_ENABLED, true);
if (teddit_enabled) { if (teddit_enabled) {
String tedditHost = sharedpreferences.getString(SET_TEDDIT_HOST, MainActivity.DEFAULT_TEDDIT_HOST); String tedditHost = sharedpreferences.getString(SET_TEDDIT_HOST, MainActivity.DEFAULT_TEDDIT_HOST);
@ -442,7 +443,15 @@ public class Utils {
if (tedditHost.startsWith("http")) { if (tedditHost.startsWith("http")) {
scheme = ""; 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()) { while (matcher.find()) {
String redditPath = matcher.group(3); String redditPath = matcher.group(3);
if (Objects.requireNonNull(matcher.group(2)).compareTo("preview.redd.it") == 0 || 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)) || 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(youtube_domains).contains(host) || Arrays.asList(invidious_instances).contains(host)
|| Arrays.asList(tiktok_domains).contains(host) || (host != null && host.endsWith(medium_domains[0]) || 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) { public static boolean routerEnabledForHost(Context context, String url) {
@ -1242,7 +1251,7 @@ public class Utils {
return sharedpreferences.getBoolean(MainActivity.SET_OSM_ENABLED, true); return sharedpreferences.getBoolean(MainActivity.SET_OSM_ENABLED, true);
} else if (Arrays.asList(youtube_domains).contains(host) || Arrays.asList(invidious_instances).contains(host)) { } else if (Arrays.asList(youtube_domains).contains(host) || Arrays.asList(invidious_instances).contains(host)) {
return sharedpreferences.getBoolean(SET_INVIDIOUS_ENABLED, true); 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); return sharedpreferences.getBoolean(SET_TEDDIT_ENABLED, true);
} else if (Arrays.asList(tiktok_domains).contains(host)) { } else if (Arrays.asList(tiktok_domains).contains(host)) {
return sharedpreferences.getBoolean(SET_PROXITOK_ENABLED, true); return sharedpreferences.getBoolean(SET_PROXITOK_ENABLED, true);