-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChromeOpenerHandler.m
79 lines (67 loc) · 3.46 KB
/
ChromeOpenerHandler.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#import "ChromeOpenerHandler.h"
@implementation ChromeOpenerHandler
- (instancetype)init {
self = [super init];
if (self) {
self.name = @"ChromeOpener";
self.identifier = @"com.cfarzaneh.chromeopener";
}
return self;
}
- (id)openURL:(NSURL *)url sender:(NSString *)sender {
NSString *linkOpenerPlistPath = @"/var/mobile/Library/Preferences/org.thebigboss.linkopener.plist";
if ([[NSFileManager defaultManager] fileExistsAtPath:linkOpenerPlistPath]) {
NSDictionary *myDict = [[NSDictionary alloc] initWithContentsOfFile:linkOpenerPlistPath];
BOOL isEnabled = [[myDict objectForKey:@"Enabled"] boolValue];
if (isEnabled == true) {
if (!([url.host isEqualToString:@"twitter.com"] || [url.host isEqualToString:@"mobile.twitter.com"] ||
[url.host isEqualToString:@"m.twitter.com"] || [url.host isEqualToString:@"www.facebook.com"] ||
[url.host isEqualToString:@"facebook.com"] || [url.host isEqualToString:@"fb.com"] ||
[url.host isEqualToString:@"imdb.com"] || [url.host isEqualToString:@"www.imdb.com"] ||
[url.host hasPrefix:@"ebay.co"] || [url.host hasPrefix:@"www.ebay.co"] ||
[url.host isEqualToString:@"cydia.saurik.com"] ||
[url.host isEqualToString:@"github.com"] || [url.host isEqualToString:@"gist.github.com"] ||
(([url.host isEqualToString:@"reddit.com"] || [url.host hasSuffix:@".reddit.com"]) && ([url.pathComponents containsObject:@"comments"] || url.pathComponents.count == 3)) || [url.host isEqualToString:@"redd.it"] ||
[url.host hasSuffix:@".tumblr.com"] || [url.host isEqualToString:@"vine.co"] || [url.host isEqualToString:@"instagram.com"] || [url.host isEqualToString:@"www.instagram.com"] ||
[url.host isEqualToString:@"dict.cc"] || [url.host hasSuffix:@".dict.cc"] || [url.host isEqualToString:@"yelp.com"] || [url.host isEqualToString:@"www.yelp.com"] ||
[url.host isEqualToString:@"overcast.fm"])) {
if ([url.scheme isEqualToString:@"http"]) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES];
components.scheme = @"googlechrome";
return components.URL;
}
else if ([url.scheme isEqualToString:@"https"]) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES];
components.scheme = @"googlechromes";
return components.URL;
}
}
}
else {
if ([url.scheme isEqualToString:@"http"]) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES];
components.scheme = @"googlechrome";
return components.URL;
}
else if ([url.scheme isEqualToString:@"https"]) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES];
components.scheme = @"googlechromes";
return components.URL;
}
}
} //LinkOpener has been installed
else {
if ([url.scheme isEqualToString:@"http"]) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES];
components.scheme = @"googlechrome";
return components.URL;
}
else if ([url.scheme isEqualToString:@"https"]) {
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES];
components.scheme = @"googlechromes";
return components.URL;
}
} //LinkOpener not installed
return nil;
}
@end