-
-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[New module] Skip redirect #10
Comments
As with #7 the main issue is to obtain the database with all the redirections to use. Clear Urls have a public database with all the rules, that's the main reason it was implemented. In any case ClearUrl does some of the static redirections too (though probably not all). |
As far as I see from Skip Redirect's issues, their approach is just using static redirections, and no need for a database. I think most of the redirections are in this link: I really don't know how to code in Java, so it might look really bad but this is the best I could do to replicate the codes: Java codeimport java.util.*;
import java.util.regex.*;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
class Bundle {
public LinkedList<String> prefix;
public String prefixString;
}
public class main {
public static String decodeURIComponent(String s, String charset) {
if (s == null) {
return null;
}
String result = null;
try {
result = URLDecoder.decode(s, charset);
}
// This exception should never occur.
catch (UnsupportedEncodingException e) {
result = s;
}
return result;
}
public static Bundle comprehend(LinkedList<String> pList, String s) {
LinkedList<String> result = new LinkedList<String>();
result.push("www\\.");
for (String p : pList) {
result.push(p + s);
}
String resultString = "(?:";
for (int i = 0; i < result.size(); i++) {
resultString = resultString + result.get(i) + "|";
}
resultString = resultString.substring(0, resultString.length() - 1) + ")";
Bundle resultBundle = new Bundle();
resultBundle.prefix = result;
resultBundle.prefixString = resultString;
return resultBundle;
}
public static Pattern getQueryRegexpPlainProtocol(String plainString) {
return Pattern.compile("https?://.*" + "=" + "(" + plainString + "(?:[^?&;#]*[?][^?]*|[^?&;#]*)" + ")", Pattern.CASE_INSENSITIVE);
}
public static String maybeDecode(String urlMatch, Pattern percentReg, Pattern symbolReg) {
Matcher percentMatcher = percentReg.matcher(urlMatch);
Matcher symbolMatcher = symbolReg.matcher(urlMatch);
while (percentMatcher.find()) {
urlMatch = decodeURIComponent(urlMatch, "UTF-8");
break;
}
while (symbolMatcher.find()) {
urlMatch = decodeURIComponent(urlMatch, "UTF-8");
break;
}
if (urlMatch.indexOf("http") != 0) {
urlMatch = "http://" + urlMatch;
}
return urlMatch;
}
public static String getPlainMatches(String url, String plainString, Pattern plainReg) {
List<Pattern> list = new ArrayList<Pattern>();
list.add(plainReg);
list.add(getQueryRegexpPlainProtocol(plainString));
for (Pattern p: list) {
Matcher matcher = p.matcher(url);
if (matcher.find()) {
return matcher.group(1);
}
}
return null;
}
public static String getRedirectTarget(String url, String plainString, Pattern plainReg, Pattern percentReg, Pattern symbolReg) {
String extractedUrl = getPlainMatches(url, plainString, plainReg);
if (extractedUrl != null) {
return getRedirectTarget(maybeDecode(extractedUrl, percentReg, symbolReg), plainString, plainReg, percentReg, symbolReg);
}
return url;
}
public static void main(String[] args) {
String[] protocols = {
"rtsp",
"mms",
"https",
"http",
"ftp",
};
LinkedList<String> protocolList = new LinkedList<String>();
Collections.addAll(protocolList, protocols);
// possibleColonPrefix
Bundle colonBundle = comprehend(protocolList, "(?::)");
LinkedList<String> possibleColonPrefixes = colonBundle.prefix;
String possibleColonPrefixesString = colonBundle.prefixString;
// possiblePlainPrefixes
Bundle plainBundle = comprehend(protocolList, "(?::|%3A|%253A)");
LinkedList<String> possiblePlainPrefixes = plainBundle.prefix;
String possiblePlainPrefixesString = plainBundle.prefixString;
// pathRegexpPlainProtocol
Pattern pathRegexpPlainProtocol = Pattern.compile("https?://.*?" + "(?:[^/][/]|\\?)" + "(" + possibleColonPrefixesString + ".*$" + ")", Pattern.CASE_INSENSITIVE);
// %
Pattern percentRegExp = Pattern.compile("%25", Pattern.CASE_INSENSITIVE);
// #$&+,/:;=?@
Pattern symbolRegExp = Pattern.compile("(%23|%24|%26|%2B|%2C|%2F|%3A|%3B|%3D|%3F|%40)", Pattern.CASE_INSENSITIVE);
// Test
String[] testUrls = {
"https://www.google.com/chrome/?or-maybe-rather-firefox=https%3A%2F%2Fwww.mozilla.org/", // -> https://www.mozilla.org/
"https://www.google.com/?url=www.example.com", // -> http://www.example.com
"https://www.youtube.com/redirect?event=backstage_event&redir_token=QUFFLUhqbnUyRDFFeWFuWm5LRy1JZnZnSEV4dVF5QWFWUXxBQ3Jtc0trQ3FpMkotdDJpQkhzTjVBWGhUWExEYjRsUzNrSEFtX2lFQ2R5QTFHT2RRQV9iZjNMcENLTVo1LVhjaDRFQmp4Z2tHbHMxNVhaN1kwTG9CdVZCMXNtSDhfY1FIbTdwY3N5SkZQbTRIOF9uZS1DME5nOA&q=https%3A%2F%2Ftwitter.com%2FKW7MD8FEWT7lMXx%2Fstatus%2F1493586411479392261%3Ft%3D5UmHquFVB6A_R-CbFgUM2g%26s%3D19&html_redirect=1", // -> https://twitter.com/KW7MD8FEWT7lMXx/status/1493586411479392261?t=5UmHquFVB6A_R-CbFgUM2g&s=19
};
for (String url: testUrls) {
String redirectUrl = getRedirectTarget(url, possiblePlainPrefixesString, pathRegexpPlainProtocol, percentRegExp, symbolRegExp);
System.out.println("---------------------------------------------------------");
System.out.println(url);
System.out.println("-> " + redirectUrl);
}
}
} I just did the plain text URL first, and haven't included Encoded, Base64 or Exceptions situations. The results of 3 example links look like this I think the exceptions are in this link: |
This action updates assets files, currently there is only one asset file, the ClearURLs catalog, but the action can be easily expanded if more are added ( maybe these issues can benefit from it: #82 #61 #10 #7 ), just copy and paste the ClearURLS catalog step and change the enviroment variables. Co-authored-by: Ilithy <[email protected]>
Hi, I don't know if it would be too difficult to implement or not but it would be nice if there's another module to skip redirection links, similar to how
Skip Redirect
extension works:https://github.com/sblask/webextension-skip-redirect
https://addons.mozilla.org/en-US/firefox/addon/skip-redirect/
For example this link
can be rewritten to
I really like this project, one of my must-install app on android now.
The text was updated successfully, but these errors were encountered: