Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Added code for 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Insull committed Nov 21, 2012
1 parent 3d03cea commit d29efe9
Showing 1 changed file with 68 additions and 62 deletions.
130 changes: 68 additions & 62 deletions Tweak.xm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* LinkOpener - Opens links in 3rd party apps.
*
* By Adaminsull <http://h4ck.co.uk>
* Edited by bensge
* Based on YTOpener by Ad@m <http://hbang.ws>
* Licensed under the GPL license <http://www.gnu.org/copyleft/gpl.html>
*/
Expand All @@ -10,87 +11,92 @@

%group LOSpringBoard
static BOOL LOOpenURL(NSURL *url) {
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
if ([[url host] isEqualToString:@"twitter.com"] && [[url pathComponents] count] == 2) {
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tweetbot://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"tweetbot:///user_profile/" stringByAppendingString:[[url pathComponents] objectAtIndex:1]]]];
return YES;
} else if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"twitter://user?screen_name=" stringByAppendingString:[[url pathComponents] objectAtIndex:1]]]];
return YES;
}
} else if ([[url host] isEqualToString:@"www.facebook.com"] && [[url pathComponents] count] == 2 && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"fb://profileForLinkOpener/" stringByAppendingString:[[url pathComponents]objectAtIndex:1]]]];
return YES;
} else if (([[url host] hasPrefix:@"ebay.co"] || [[url host] hasPrefix:@"www.ebay.co"]) && [[url pathComponents] count] == 4 && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"ebay://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"ebay://launch?itm=" stringByAppendingString:[[url pathComponents] objectAtIndex:3]]]];
return YES;
} else if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"vnd.youtube://"]]) {
BOOL isMobile = NO;
if (([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) && ([[url host] isEqualToString:@"youtube.com"] || [[url host] isEqualToString:@"www.youtube.com"] || (isMobile = [[url host] isEqualToString:@"m.youtube.com"])) && isMobile ? [[url fragment] rangeOfString:@"/watch"].length > 0 : [[url path] isEqualToString:@"/watch"]) {
NSArray *params = [(isMobile ? [[url fragment] stringByReplacingOccurrencesOfString:@"/watch?" withString:@""] : [url query]) componentsSeparatedByString:@"&"];
for (NSString *i in params) {
if ([i rangeOfString:@"v="].location == 0) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"vnd.youtube://" stringByAppendingString:[i stringByReplacingOccurrencesOfString:@"v=" withString:@""]]]];
return YES;
}
}
} else if ([[url host] isEqualToString:@"youtu.be"] && [[url pathComponents] count] > 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"vnd.youtube://" stringByAppendingString:[[url pathComponents] objectAtIndex:1]]]];
return YES;
} else if ([[url scheme] isEqualToString:@"youtube"]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"vnd." stringByAppendingString:[url absoluteString]]]];
return YES;
}
}
if ([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) {
if ([[url host] isEqualToString:@"twitter.com"] && [[url pathComponents] count] == 2) {
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tweetbot://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"tweetbot:///user_profile/" stringByAppendingString:[[url pathComponents] objectAtIndex:1]]]];
return YES;
} else if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"twitter://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"twitter://user?screen_name=" stringByAppendingString:[[url pathComponents] objectAtIndex:1]]]];
return YES;
}
} else if ([[url host] isEqualToString:@"www.facebook.com"] && [[url pathComponents] count] == 2 && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fb://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"fb://profileForLinkOpener/" stringByAppendingString:[[url pathComponents]objectAtIndex:1]]]];
return YES;
//////////////////////Edited by bensge to add imdb app support
} else if (([[url host] isEqualToString:@"imdb.com"] || [[url host] isEqualToString:@"www.imdb.com"]) && [[url pathComponents] count] == 3 && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"imdb://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"imdb:///title/" stringByAppendingString:[[url pathComponents] objectAtIndex:2]]]];
return YES;
/////////////////////// You should've paid a million for this! I swear, if someone steals this and takes money for it, i swear i'll kill him....
} else if (([[url host] hasPrefix:@"ebay.co"] || [[url host] hasPrefix:@"www.ebay.co"]) && [[url pathComponents] count] == 4 && [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"ebay://"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"ebay://launch?itm=" stringByAppendingString:[[url pathComponents] objectAtIndex:3]]]];
return YES;
} else if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"vnd.youtube://"]]) {
BOOL isMobile = NO;
if (([[url scheme] isEqualToString:@"http"] || [[url scheme] isEqualToString:@"https"]) && ([[url host] isEqualToString:@"youtube.com"] || [[url host] isEqualToString:@"www.youtube.com"] || (isMobile = [[url host] isEqualToString:@"m.youtube.com"])) && isMobile ? [[url fragment] rangeOfString:@"/watch"].length > 0 : [[url path] isEqualToString:@"/watch"]) {
NSArray *params = [(isMobile ? [[url fragment] stringByReplacingOccurrencesOfString:@"/watch?" withString:@""] : [url query]) componentsSeparatedByString:@"&"];
for (NSString *i in params) {
if ([i rangeOfString:@"v="].location == 0) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"vnd.youtube://" stringByAppendingString:[i stringByReplacingOccurrencesOfString:@"v=" withString:@""]]]];
return YES;
}
}
} else if ([[url host] isEqualToString:@"youtu.be"] && [[url pathComponents] count] > 1) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"vnd.youtube://" stringByAppendingString:[[url pathComponents] objectAtIndex:1]]]];
return YES;
} else if ([[url scheme] isEqualToString:@"youtube"]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[@"vnd." stringByAppendingString:[url absoluteString]]]];
return YES;
}
}

}
return NO;
}
return NO;
}

%hook SpringBoard
// iOS < 6
-(void)_openURLCore:(NSURL *)url display:(id)display publicURLsOnly:(BOOL)publicOnly animating:(BOOL)animated additionalActivationFlag:(unsigned int)flags {
if (!LOOpenURL(url)) {
%orig;
}
if (!LOOpenURL(url)) {
%orig;
}
}
// iOS 6+ - thanks to rpetrich for telling us the new method!
-(void)_openURLCore:(NSURL *)url display:(id)display animating:(BOOL)animating sender:(id)sender additionalActivationFlags:(id)activationFlags {
if (!LOOpenURL(url)) {
%orig;
}
if (!LOOpenURL(url)) {
%orig;
}
}
%end
%end

%group LOFacebook
%hook AppDelegate
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApp annotation:(id)annotation {
if ([[url host] isEqualToString:@"profileForLinkOpener"] && [[url pathComponents] count] == 2) {
// This is a terrible way to do this, however Facebook crashes if we do this asynchronously. Don't ever do this elsewhere.
NSData *output = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[@"https://graph.facebook.com/" stringByAppendingString:[[url pathComponents] objectAtIndex:1]]] cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:60] returningResponse:nil error:nil];
if (output == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops, something went wrong." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
} else {
NSDictionary *json = [output objectFromJSONData];
return %orig(application, [NSURL URLWithString:[@"fb://profile/" stringByAppendingString:[json objectForKey:@"id"]]], sourceApp, annotation);
}
return NO;
} else {
return %orig;
}
if ([[url host] isEqualToString:@"profileForLinkOpener"] && [[url pathComponents] count] == 2) {
// This is a terrible way to do this, however Facebook crashes if we do this asynchronously. Don't ever do this elsewhere.
NSData *output = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[@"https://graph.facebook.com/" stringByAppendingString:[[url pathComponents] objectAtIndex:1]]] cachePolicy:NSURLRequestReloadRevalidatingCacheData timeoutInterval:60] returningResponse:nil error:nil];
if (output == nil) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops, something went wrong." message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
} else {
NSDictionary *json = [output objectFromJSONData];
return %orig(application, [NSURL URLWithString:[@"fb://profile/" stringByAppendingString:[json objectForKey:@"id"]]], sourceApp, annotation);
}
return NO;
} else {
return %orig;
}
}
%end
%end

%ctor {
%init;
if ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.springboard"]) {
%init(LOSpringBoard);
} else {
%init(LOFacebook);
}
%init;
if ([[[NSBundle mainBundle] bundleIdentifier] isEqualToString:@"com.apple.springboard"]) {
%init(LOSpringBoard);
} else {
%init(LOFacebook);
}
}

0 comments on commit d29efe9

Please sign in to comment.