Browse Source

Create helper class to avoid duplicated code

master
lint 4 years ago
parent
commit
70190c98bd
30 changed files with 614 additions and 982 deletions
  1. +1
    -1
      Makefile
  2. +40
    -76
      tweak/AlienBlue.xm
  3. +40
    -79
      tweak/Antenna.xm
  4. +66
    -103
      tweak/Apollo.xm
  5. +26
    -70
      tweak/BaconReader.xm
  6. +39
    -83
      tweak/Beam.xm
  7. +51
    -110
      tweak/Narwhal.xm
  8. +4
    -0
      tweak/Reddit.h
  9. +198
    -351
      tweak/Reddit.xm
  10. +93
    -109
      tweak/Slide.xm
  11. +0
    -0
      tweak/assets/MMMarkdown/MMDocument.h
  12. +0
    -0
      tweak/assets/MMMarkdown/MMDocument.m
  13. +0
    -0
      tweak/assets/MMMarkdown/MMDocument_Private.h
  14. +0
    -0
      tweak/assets/MMMarkdown/MMElement.h
  15. +0
    -0
      tweak/assets/MMMarkdown/MMElement.m
  16. +0
    -0
      tweak/assets/MMMarkdown/MMGenerator.h
  17. +0
    -0
      tweak/assets/MMMarkdown/MMGenerator.m
  18. +0
    -0
      tweak/assets/MMMarkdown/MMHTMLParser.h
  19. +0
    -0
      tweak/assets/MMMarkdown/MMHTMLParser.m
  20. +0
    -0
      tweak/assets/MMMarkdown/MMMarkdown-Prefix.pch
  21. +0
    -0
      tweak/assets/MMMarkdown/MMMarkdown.h
  22. +0
    -0
      tweak/assets/MMMarkdown/MMMarkdown.m
  23. +0
    -0
      tweak/assets/MMMarkdown/MMParser.h
  24. +0
    -0
      tweak/assets/MMMarkdown/MMParser.m
  25. +0
    -0
      tweak/assets/MMMarkdown/MMScanner.h
  26. +0
    -0
      tweak/assets/MMMarkdown/MMScanner.m
  27. +0
    -0
      tweak/assets/MMMarkdown/MMSpanParser.h
  28. +0
    -0
      tweak/assets/MMMarkdown/MMSpanParser.m
  29. +6
    -0
      tweak/assets/TFHelper.h
  30. +50
    -0
      tweak/assets/TFHelper.m

+ 1
- 1
Makefile View File

@@ -3,7 +3,7 @@ ARCHS = armv7 armv7s arm64 arm64e
include $(THEOS)/makefiles/common.mk

TWEAK_NAME = tfdidthatsay
tfdidthatsay_FILES = $(wildcard tweak/*.xm tweak/assets/*.m)
tfdidthatsay_FILES = $(wildcard tweak/*.xm tweak/assets/*.m tweak/assets/MMMarkdown/*.m)
tfdidthatsay_CFLAGS = -fobjc-arc
tweak/Reddit.xm_CFLAGS = -fno-objc-arc
tweak/Apollo.xm_CFLAGS = -fno-objc-arc

+ 40
- 76
tweak/AlienBlue.xm View File

@@ -1,6 +1,7 @@

#import "AlienBlue.h"
#import "assets/MMMarkdown.h"
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"

static BOOL isAlienBlueEnabled;
static BOOL isTFDeletedOnly;
@@ -56,43 +57,25 @@ static CGFloat pushshiftRequestTimeoutValue;
id comment = [[self node] comment];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment ident]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];

[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";

if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[comment setAuthor:author];
[comment setBody:body];
[comment setBodyHTML:bodyHTML];
[[self delegate] performSelectorOnMainThread:@selector(respondToStyleChange) withObject:nil waitUntilDone:NO];
[sender setEnabled:YES];
}];
[%c(TFHelper) getUndeleteDataWithID:[comment ident] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}

%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = [[self node] comment];
NSString *body = data[@"body"];
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[comment setAuthor:data[@"author"]];
[comment setBody:body];
[comment setBodyHTML:bodyHTML];
[[self delegate] respondToStyleChange];
[data[@"sender"] setEnabled:YES];
}

%new
@@ -101,45 +84,27 @@ static CGFloat pushshiftRequestTimeoutValue;
[sender setEnabled:NO];
id post = [[self node] post];
id postComment = [[self node] comment]; //Don't know why he used a comment to store info about a post, but it exists
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[post ident]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[%c(TFHelper) getUndeleteDataWithID:[post ident] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}

[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";

if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[post setAuthor:author];
[post setSelftext:body];
[postComment setBodyHTML:bodyHTML];
[[self delegate] performSelectorOnMainThread:@selector(respondToStyleChange) withObject:nil waitUntilDone:NO];
[sender setEnabled:YES];
}];
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
id post = [[self node] post];
id postComment = [[self node] comment]; //Don't know why he used a comment to store info about a post, but it exists
NSString *body = data[@"body"];
NSString *bodyHTML = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[post setAuthor:data[@"author"]];
[post setSelftext:body];
[postComment setBodyHTML:bodyHTML];
[[self delegate] respondToStyleChange];
[data[@"sender"] setEnabled:YES];
}

%end
@@ -196,4 +161,3 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
}
}
}


+ 40
- 79
tweak/Antenna.xm View File

@@ -1,6 +1,7 @@
#import "Antenna.h"
#import "assets/MMMarkdown.h"
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isAntennaEnabled;
static BOOL isTFDeletedOnly;
@@ -48,48 +49,28 @@ id tfAntennaCommentCell;
%new
-(void) handleUndeleteCommentAction{
[%c(TFHelper) getUndeleteDataWithID:[[tfAntennaCommentCell comment] itemId] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = [tfAntennaCommentCell comment];
id commentText = [comment commentText];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment itemId]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *body = data[@"body"];
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[comment setAuthor:author];
[commentText setBody:body];
[commentText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[commentText setBodyAttributedString:nil];
[commentText setBodyAttributedStringForPreview:nil];
[commentText setTextHeightCache:nil];
[self setCommentHeightCache:nil];
[tfAntennaCommentCell performSelectorOnMainThread:@selector(updateWithModelObject:) withObject:comment waitUntilDone:YES];
[[[self delegate] tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}];
[comment setAuthor:data[@"author"]];
[commentText setBody:body];
[commentText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[commentText setBodyAttributedString:nil];
[commentText setBodyAttributedStringForPreview:nil];
[commentText setTextHeightCache:nil];
[self setCommentHeightCache:nil];
[tfAntennaCommentCell updateWithModelObject:comment];
[[[self delegate] tableView] reloadData];
}
%end
@@ -178,49 +159,29 @@ id tfAntennaCommentCell;
[sender setEnabled:NO];
[%c(TFHelper) getUndeleteDataWithID:[[self post] itemId] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
id post = [self post];
id postText = [post selfCommentText];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[post itemId]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[post setAuthor:author];
[postText setBody:body];
[postText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[postText setBodyAttributedString:nil];
[postText setBodyAttributedStringForPreview:nil];
[postText setTextHeightCache:nil];
[self performSelectorOnMainThread:@selector(loadView) withObject:nil waitUntilDone:YES];
[[self tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[sender setEnabled:YES];
}];
NSString *body = data[@"body"];
[post setAuthor:data[@"author"]];
[postText setBody:body];
[postText setBodyHTML:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[postText setBodyAttributedString:nil];
[postText setBodyAttributedStringForPreview:nil];
[postText setTextHeightCache:nil];
[self loadView];
[[self tableView] reloadData];
[data[@"sender"] setEnabled:YES];
}
%end

+ 66
- 103
tweak/Apollo.xm View File

@@ -1,5 +1,6 @@
#import "Apollo.h"
#import "assets/TFHelper.h"
static BOOL isTFDeletedOnly;
static BOOL isApolloEnabled;
@@ -38,59 +39,6 @@ NSDictionary* apolloBodyAttributes = nil;
%hook ApolloCommentCellNode
%property(strong,nonatomic) id undeleteButton;
%new
-(void) didTapUndeleteButton:(id) sender{
[sender setEnabled:NO];
id bodyNode = MSHookIvar<id>(self, "bodyNode");
id authorNode = MSHookIvar<id>(self, "authorNode");
id authorTextNode = [authorNode subnodes][0];
id comment = MSHookIvar<id>(self, "comment");
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
id prevAuthorAttributedString = [authorTextNode attributedString];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString* newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes];
[authorTextNode setAttributedText:newAuthorAttributedString];
[authorTextNode setAttributedString:newAuthorAttributedString];
[comment setAuthor:author];
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:body withAttributes:apolloBodyAttributes]];
[sender setEnabled:YES];
}];
}
-(void) didLoad {
%orig;
@@ -128,70 +76,48 @@ NSDictionary* apolloBodyAttributes = nil;
CGFloat nodeSpacing =[ageNode frame].origin.x - nodeFrame.origin.x - nodeFrame.size.width;
[[self undeleteButton] setFrame:CGRectMake(nodeFrame.origin.x - imageSize - nodeSpacing, centerHeight - (imageSize / 2), imageSize, imageSize)];
}
}
%end
%hook ApolloCommentsHeaderCellNode
%property(strong, nonatomic) id undeleteButton;
%new
-(void) didTapUndeleteButton:(id) sender{
[sender setEnabled:NO];
id comment = MSHookIvar<id>(self, "comment");
[%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = MSHookIvar<id>(self, "comment");
id bodyNode = MSHookIvar<id>(self, "bodyNode");
id postInfoNode = MSHookIvar<id>(self, "postInfoNode");
id authorNode = MSHookIvar<id>(postInfoNode, "authorButtonNode");
id authorNode = MSHookIvar<id>(self, "authorNode");
id authorTextNode = [authorNode subnodes][0];
id post = MSHookIvar<id>(self, "link");
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
NSString *author = data[@"author"];
id prevAuthorAttributedString = [authorTextNode attributedString];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString *newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
//MSHookIvar<NSString*>(post, "_author") = author; //Crashes when clicking on author name. You will have to search the author name to go find the profile.
[authorTextNode setAttributedText:newAuthorAttributedString];
[authorTextNode setAttributedString:newAuthorAttributedString];
[comment setAuthor:author];
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:data[@"body"] withAttributes:apolloBodyAttributes]];
[data[@"sender"] setEnabled:YES];
}
author = [NSString stringWithFormat:@"by %@", author];
%end
id prevAuthorAttributedString = [authorTextNode attributedString];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString* newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes];
[authorTextNode setAttributedText:newAuthorAttributedString];
[authorTextNode setAttributedString:newAuthorAttributedString];
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:body withAttributes:apolloBodyAttributes]];
[sender setEnabled:YES];
}];
}
%hook ApolloCommentsHeaderCellNode
%property(strong, nonatomic) id undeleteButton;
-(void) didLoad{
%orig;
@@ -234,6 +160,43 @@ NSDictionary* apolloBodyAttributes = nil;
}
}
%new
-(void) didTapUndeleteButton:(id) sender{
[sender setEnabled:NO];
id post = MSHookIvar<id>(self, "link");
[%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
id bodyNode = MSHookIvar<id>(self, "bodyNode");
id postInfoNode = MSHookIvar<id>(self, "postInfoNode");
id authorNode = MSHookIvar<id>(postInfoNode, "authorButtonNode");
id authorTextNode = [authorNode subnodes][0];
NSString *author = data[@"author"];
//id post = MSHookIvar<id>(self, "link");
//MSHookIvar<NSString*>(post, "_author") = author; //Crashes when clicking on author name. You will have to search the author name to go find the profile.
author = [NSString stringWithFormat:@"by %@", author];
id prevAuthorAttributedString = [authorTextNode attributedString];
NSDictionary *authorStringAttributes = [prevAuthorAttributedString attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [prevAuthorAttributedString length])];
NSAttributedString* newAuthorAttributedString = [[NSAttributedString alloc] initWithString:author attributes:authorStringAttributes];
[authorTextNode setAttributedText:newAuthorAttributedString];
[authorTextNode setAttributedString:newAuthorAttributedString];
[bodyNode setAttributedString:[%c(MarkdownRenderer) attributedStringFromMarkdown:data[@"body"] withAttributes:apolloBodyAttributes]];
[data[@"sender"] setEnabled:YES];
}
%end
%end

+ 26
- 70
tweak/BaconReader.xm View File

@@ -1,6 +1,7 @@
#import "BaconReader.h"
#import "assets/MMMarkdown.h"
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isBaconReaderEnabled;
static BOOL isTFDeletedOnly;
@@ -126,85 +127,40 @@ id tfStoryController;
%new
-(void) handleUndeleteCommentAction{
[%c(TFHelper) getUndeleteDataWithID:[[tfCommentCellView comment] serverID] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = [tfCommentCellView comment];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", [comment serverID]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *body = data[@"body"];
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[comment setAuthor:author];
[comment setBody:body];
[comment setBody_html:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[comment setAttributedDescriptionString:nil];
NSAttributedString *commentAttrString = [%c(BRUtils) attributedDescriptionForComment:comment];
[comment setAttributedDescriptionString:commentAttrString];
[[[self detailPage] tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
}];
[comment setAuthor:data[@"author"]];
[comment setBody:body];
[comment setBody_html:[%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil]];
[comment setAttributedDescriptionString:nil];
NSAttributedString *commentAttrString = [%c(BRUtils) attributedDescriptionForComment:comment];
[comment setAttributedDescriptionString:commentAttrString];
[[[self detailPage] tableView] reloadData];
}
%new
-(void) handleUndeletePostAction{
id post = [self story];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext", [post serverID]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[%c(TFHelper) getUndeleteDataWithID:[[self story] serverID] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
tfPostAuthor = author;
tfPostSelftext = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
[[self detailPage] performSelectorOnMainThread:@selector(refreshTouched) withObject:nil waitUntilDone:NO];
}];
tfPostAuthor = data[@"author"];
tfPostSelftext = [%c(MMMarkdown) HTMLStringWithMarkdown:data[@"body"] extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
[[self detailPage] refreshTouched];
}
%end

+ 39
- 83
tweak/Beam.xm View File

@@ -1,5 +1,6 @@
#import "Beam.h"
#import "assets/TFHelper.h"
static BOOL isBeamEnabled;
static BOOL isTFDeletedOnly;
@@ -25,8 +26,6 @@ static CGFloat pushshiftRequestTimeoutValue;
NSString *commentBody = [[self comment] content];
HBLogDebug(@"body: %@", commentBody);
if ((isTFDeletedOnly && ([commentBody isEqualToString:@"[deleted]"] || [commentBody isEqualToString:@"[removed]"])) || !isTFDeletedOnly){
CGFloat authorTextHeight = [[self authorButton] frame].size.height;
@@ -51,45 +50,23 @@ static CGFloat pushshiftRequestTimeoutValue;
[sender setEnabled:NO];
[%c(TFHelper) getUndeleteDataWithID:[[self comment] identifier] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = [self comment];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", [comment identifier]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[comment setAuthor:author];
[comment setContent:body];
[comment setMarkdownString:nil];
[self setCommentDidChange:YES];
[self performSelectorOnMainThread:@selector(reloadContents) withObject:nil waitUntilDone:YES];
[[MSHookIvar<id>(self, "delegate") tableView] performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
[sender setEnabled:YES];
}];
[comment setAuthor:data[@"author"]];
[comment setContent:data[@"body"]];
[comment setMarkdownString:nil];
[self setCommentDidChange:YES];
[self reloadContents];
[[MSHookIvar<id>(self, "delegate") tableView] reloadData];
[data[@"sender"] setEnabled:YES];
}
%end
@@ -173,51 +150,31 @@ static CGFloat pushshiftRequestTimeoutValue;
id post = [self post];
if (post){
[%c(TFHelper) getUndeleteDataWithID:[post identifier] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext", [post identifier]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[post setAuthor:author];
[post setContent:body];
[post setMarkdownString:nil];
if ([self selfTextView]){
[[self selfTextView] performSelectorOnMainThread:@selector(reloadContents) withObject:nil waitUntilDone:YES];
}
if ([self metadataView]){
[[self metadataView] performSelectorOnMainThread:@selector(setPost:) withObject:post waitUntilDone:YES];
}
[[self tableView] performSelectorOnMainThread:@selector(reloadData) withObject:post waitUntilDone:NO];
[sender setEnabled:YES];
}];
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
id post = [self post];
[post setAuthor:data[@"author"]];
[post setContent:data[@"body"]];
[post setMarkdownString:nil];
if ([self selfTextView]){
[[self selfTextView] reloadContents];
}
if ([self metadataView]){
[[self metadataView] setPost:post];
}
[[self tableView] reloadData];
[data[@"sender"] setEnabled:YES];
}
%end
@@ -274,4 +231,3 @@ static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStrin
}
}
}

+ 51
- 110
tweak/Narwhal.xm View File

@@ -1,5 +1,6 @@
#import "Narwhal.h"
#import "assets/TFHelper.h"
static BOOL isNarwhalEnabled;
static BOOL isTFDeletedOnly;
@@ -11,38 +12,8 @@ BOOL shouldHaveUndeleteAction = NO;
id tfComment;
id tfController;
void getUndeleteCommentData(id controller, id comment){
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";

if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[controller performSelectorOnMainThread:@selector(completeUndeleteComment:) withObject:@{@"body":body, @"author":author, @"comment":comment} waitUntilDone:NO];
}];
void getUndeleteCommentData(id controller, id comment){
[%c(TFHelper) getUndeleteDataWithID:[[comment fullName] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"comment" : comment} completionTarget:controller completionSelector:@selector(completeUndeleteCommentAction:)];
}
@@ -61,7 +32,6 @@ void getUndeleteCommentData(id controller, id comment){
}
[arg1 addAction:undeleteAction];
}
%orig;
@@ -70,71 +40,7 @@ void getUndeleteCommentData(id controller, id comment){
%end
%hook NRTLinkViewController

%new
-(void) completeUndeleteComment:(id) data{

id comment = data[@"comment"];

if (comment){

MSHookIvar<NSString*>(comment, "_author") = data[@"author"];
MSHookIvar<NSString*>(comment, "_body") = data[@"body"];
[[self commentsManager] updateComment:comment fromEdited:comment];
}
}

%new
-(void) completeUndeletePost:(id) data{

id post = data[@"post"];

MSHookIvar<NSString*>(post, "_author") = data[@"author"];
NSAttributedString* postBodyAttributedString = [%c(NRTMarkdownManager) attributedStringFromMarkdown:data[@"body"] type:0];
[self setLinkText:postBodyAttributedString];
[[self tableView] reloadData];
}
%new
-(void) handleUndeletePostAction{
id post = [self link];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post fullName] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
[self performSelectorOnMainThread:@selector(completeUndeletePost:) withObject:@{@"body":body, @"author":author, @"post":post} waitUntilDone:NO];
}];
}
%hook NRTLinkViewController
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
@@ -174,25 +80,46 @@ void getUndeleteCommentData(id controller, id comment){
shouldHaveUndeleteAction = NO;
}
%end
%new
-(void) handleUndeletePostAction{
id post = [self link];
[%c(TFHelper) getUndeleteDataWithID:[[post fullName] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:@{@"post" : post} completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
id post = data[@"post"];
MSHookIvar<NSString*>(post, "_author") = data[@"author"];
NSAttributedString* postBodyAttributedString = [%c(NRTMarkdownManager) attributedStringFromMarkdown:data[@"body"] type:0];
[self setLinkText:postBodyAttributedString];
[[self tableView] reloadData];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = data[@"comment"];
if (comment){
%hook NRTMediaTableViewDataSource

%new
-(void) completeUndeleteComment:(id) data{

id comment = data[@"comment"];

if (comment){

MSHookIvar<NSString*>(comment, "_author") = data[@"author"];
MSHookIvar<NSString*>(comment, "_body") = data[@"body"];
[[self commentsManager] updateComment:comment fromEdited:comment];
}
[[self commentsManager] updateComment:comment fromEdited:comment];
}
}
%end
%hook NRTMediaTableViewDataSource
-(void) swipeCell:(id) arg1 didEndDragWithState:(NSUInteger) arg2{
if (arg2 == 2){
@@ -213,6 +140,20 @@ void getUndeleteCommentData(id controller, id comment){
shouldHaveUndeleteAction = NO;
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id comment = data[@"comment"];
if (comment){
MSHookIvar<NSString*>(comment, "_author") = data[@"author"];
MSHookIvar<NSString*>(comment, "_body") = data[@"body"];
[[self commentsManager] updateComment:comment fromEdited:comment];
}
}
%end
%end

+ 4
- 0
tweak/Reddit.h View File

@@ -21,6 +21,10 @@
-(void) reloadPostSection:(BOOL) arg1;
-(void) feedPostViewDidUpdatePost:(id) arg1 shouldReloadFeed:(BOOL) arg2;
-(void) updateFloatingViews;
//custom elements
-(void) updateComments;
-(void) updatePostText;
@end
@interface CommentActionSheetViewController : UIViewController

+ 198
- 351
tweak/Reddit.xm View File

@@ -1,5 +1,6 @@
#import "Reddit.h"
#import "assets/TFHelper.h"
static BOOL isRedditEnabled;
static BOOL isTFDeletedOnly;
@@ -93,98 +94,80 @@ int getRedditVersionPart(int index){
id commentTreeNode = [self commentTreeNode];
Comment *comment = [commentTreeNode comment];
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
}
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableAttributedString *bodyMutableAttributedText;
id themeManager;
id isNightMode;
id textColor;
if (getRedditVersionPart(1) >= 45){
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else{
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else if (getRedditVersionPart(1) >= 37){
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
textColor = [[themeManager dayTheme] bodyTextColor];
}
[themeManager release];
} else {
themeManager = [%c(ThemeManager) sharedManager];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
textColor = [[themeManager dayTheme] bodyTextColor];
}
}
bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[bodyMutableAttributedText beginEditing];
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
}];
[bodyMutableAttributedText endEditing];
[comment setAuthor:author];
[comment setBodyText:body];
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
[comment setBodyAttributedText:bodyMutableAttributedText];
[[commentTreeNode commentTreeHeaderNode] performSelectorOnMainThread:@selector(updateContentViewsForData:) withObject:comment waitUntilDone:NO];
[request release];
[queue release];
[bodyMutableAttributedText release];
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
id commentTreeNode = [self commentTreeNode];
Comment *comment = [commentTreeNode comment];
NSString *author = data[@"author"];
NSString *body = data[@"body"];
NSMutableAttributedString *bodyMutableAttributedText;
}];
id themeManager;
id isNightMode;
id textColor;
if (getRedditVersionPart(1) >= 45){
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else{
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else if (getRedditVersionPart(1) >= 37){
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
textColor = [[themeManager dayTheme] bodyTextColor];
}
[themeManager release];
} else {
themeManager = [%c(ThemeManager) sharedManager];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
textColor = [[themeManager dayTheme] bodyTextColor];
}
}
bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[bodyMutableAttributedText beginEditing];
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
}];
[bodyMutableAttributedText endEditing];
[comment setAuthor:author];
[comment setBodyText:body];
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
[comment setBodyAttributedText:bodyMutableAttributedText];
[[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment];
[bodyMutableAttributedText release];
}
%end
@@ -242,102 +225,83 @@ int getRedditVersionPart(int index){
if ([post isSelfPost]){
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
id themeManager;
id isNightMode;
id textColor;
if (getRedditVersionPart(1) >= 45){
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else{
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else if (getRedditVersionPart(1) >= 37){
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
textColor = [[themeManager dayTheme] bodyTextColor];
}
[themeManager release];
} else {
themeManager = [%c(ThemeManager) sharedManager];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
textColor = [[themeManager dayTheme] bodyTextColor];
}
}
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[bodyMutableAttributedText beginEditing];
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
}];
[bodyMutableAttributedText endEditing];
[post setSelfText:body];
[post setAuthor:author];
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
if (getRedditVersionPart(1) >= 44){
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
} else if (getRedditVersionPart(1) >= 38) {
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
} else {
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
}
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
Post *post = [self post];
NSString *author = data[@"author"];
NSString *body = data[@"body"];
id themeManager;
id isNightMode;
id textColor;
if (getRedditVersionPart(1) >= 45){
themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager darkTheme] bodyTextColor];
} else{
textColor = [[themeManager lightTheme] bodyTextColor];
}
[themeManager release];
} else if (getRedditVersionPart(1) >= 37){
themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
textColor = [[themeManager dayTheme] bodyTextColor];
}
[themeManager release];
} else {
themeManager = [%c(ThemeManager) sharedManager];
isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
if (isNightMode) {
textColor = [[themeManager nightTheme] bodyTextColor];
} else{
textColor = [[themeManager dayTheme] bodyTextColor];
}
}
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[bodyMutableAttributedText beginEditing];
[bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
[bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
[bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
}];
[bodyMutableAttributedText endEditing];
[post setSelfText:body];
[post setAuthor:author];
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
if (getRedditVersionPart(1) >= 44){
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
} else if (getRedditVersionPart(1) >= 38) {
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
} else {
[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
[[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
}
[bodyMutableAttributedText release];
}
%end
%end
@@ -404,47 +368,8 @@ int getRedditVersionPart(int index){
[self dismissViewControllerAnimated:YES completion:nil];
Comment *comment = [self comment];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[comment setAuthor:author];
[comment setBodyText:body];
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
[comment setBodyAttributedText:bodyMutableAttributedText];
[[self commentActionSheetDelegate] performSelectorOnMainThread:@selector(updateComments) withObject:nil waitUntilDone:NO];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
}
@@ -457,51 +382,31 @@ int getRedditVersionPart(int index){
[self dismissViewControllerAnimated:YES completion:nil];
Comment *comment = [self comment];
[%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
}
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[comment setAuthor:author];
[comment setBodyText:body];
[comment setBodyAttributedText:bodyMutableAttributedText];
if (getRedditVersionPart(1) >= 12) {
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
}
[[self commentActionSheetDelegate] performSelectorOnMainThread:@selector(updateComments) withObject:nil waitUntilDone:NO];
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
Comment *comment = [self comment];
NSString *body = data[@"body"];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[comment setAuthor:data[@"author"]];
[comment setBodyText:body];
[comment setBodyAttributedText:bodyMutableAttributedText];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
if (getRedditVersionPart(1) >= 12) {
[comment setBodyRichTextAttributed:bodyMutableAttributedText];
}
[[self commentActionSheetDelegate] updateComments];
[bodyMutableAttributedText release];
}
%end
@@ -552,46 +457,7 @@ int getRedditVersionPart(int index){
if ([post isSelfPost]){
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[post setSelfText:body];
[post setAuthor:author];
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
[[self postActionSheetDelegate] performSelectorOnMainThread:@selector(updatePostText) withObject:nil waitUntilDone:NO];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
}
@@ -608,56 +474,37 @@ int getRedditVersionPart(int index){
if ([post isSelfPost]){
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[post setAuthor:author];
[post setSelfText:body];
[post setSelfTextAttributed:bodyMutableAttributedText];
if (getRedditVersionPart(1) >= 8) {
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
}
if (getRedditVersionPart(1) >= 15) {
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
}
[[self postActionSheetDelegate] performSelectorOnMainThread:@selector(updatePostText) withObject:nil waitUntilDone:NO];
[request release];
[queue release];
[bodyMutableAttributedText release];
}];
[%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
}
}
}
%new
-(void) completeUndeletePostAction:(NSDictionary *) data{
Post *post = [self post];
NSString *body = data[@"body"];
NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
[post setAuthor:data[@"author"]];
[post setSelfText:body];
[post setSelfTextAttributed:bodyMutableAttributedText];
if (getRedditVersionPart(1) >= 8) {
[post setSelfPostRichTextAttributed:bodyMutableAttributedText];
}
if (getRedditVersionPart(1) >= 15) {
[post setPreviewFeedPostTextString:bodyMutableAttributedText];
}
[[self postActionSheetDelegate] updatePostText];
[bodyMutableAttributedText release];
}
%end
%end

+ 93
- 109
tweak/Slide.xm View File

@@ -1,6 +1,7 @@
#import "Slide.h"
#import "assets/MMMarkdown.h"
#import "assets/TFHelper.h"
#import "assets/MMMarkdown/MMMarkdown.h"
static BOOL isSlideEnabled;
static BOOL isTFDeletedOnly;
@@ -288,129 +289,112 @@ static UIButton * createUndeleteButton(){
-(void) handleUndeleteComment:(id) sender{
[sender setEnabled:NO];
id comment = MSHookIvar<id>(self, "comment");
[%c(TFHelper) getUndeleteDataWithID:[[comment id] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:@{@"sender" : sender} completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
}
%new
-(void) completeUndeleteCommentAction:(NSDictionary *) data{
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
id textStackDisplayView = MSHookIvar<id>(self, "commentBody");
id comment = MSHookIvar<id>(self, "comment");
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment id] componentsSeparatedByString:@"_"][1]]]];
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:pushshiftRequestTimeoutValue];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = data[@"author"];
NSString *body = data[@"body"];
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
if ([[jsonData objectForKey:@"data"] count] != 0){
author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
//Attributed string generation rewrote from Slide_for_Reddit.TextDisplayStackView.createAttributedChunk(...)
//Attributed string generation rewrote from Slide_for_Reddit.TextDisplayStackView.createAttributedChunk(...)
UIFont *font = [%c(FontGenerator) fontOfSize:MSHookIvar<CGFloat>(textStackDisplayView, "fontSize") submission:NO willOffset:YES];
UIFont *font = [%c(FontGenerator) fontOfSize:MSHookIvar<CGFloat>(textStackDisplayView, "fontSize") submission:NO willOffset:YES];
NSString *themeName = [userDefaults stringForKey:@"theme"];
UIColor *fontColor = [%c(ColorUtil) fontColorForTheme:themeName];
UIColor *accentColor = [%c(ColorUtil) accentColorForSub:[comment subreddit]];
NSString *html = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
html = [[html stringByReplacingOccurrencesOfString:@"<sup>" withString:@"<font size=\"1\">"] stringByReplacingOccurrencesOfString:@"</sup>" withString:@"</font>"];
html = [[html stringByReplacingOccurrencesOfString:@"<del>" withString:@"<font color=\"green\">"] stringByReplacingOccurrencesOfString:@"</del>" withString:@"</font>"];
html = [[html stringByReplacingOccurrencesOfString:@"<code>" withString:@"<font color=\"blue\">"] stringByReplacingOccurrencesOfString:@"</code>" withString:@"</font>"];
html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
DTHTMLAttributedStringBuilder *dthtmlBuilder = [[%c(DTHTMLAttributedStringBuilder) alloc] initWithHTML:[html dataUsingEncoding:NSUTF8StringEncoding] options:@{@"DTUseiOS6Attributes": @YES, @"DTDefaultTextColor": fontColor, @"DTDefaultFontSize": @([font pointSize])} documentAttributes:nil];
NSMutableAttributedString *htmlAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[dthtmlBuilder generatedAttributedString]];
NSRange htmlStringRange = NSMakeRange(0, [htmlAttributedString length]);
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t•\t" withString:@" • " options:0 range: htmlStringRange];
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t◦\t" withString:@"  ◦ " options:0 range: htmlStringRange];
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t▪\t" withString:@" ▪ " options:0 range: htmlStringRange];
[htmlAttributedString removeAttribute:@"CTForegroundColorFromContext" range:htmlStringRange];
[htmlAttributedString enumerateAttributesInRange:htmlStringRange options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
for (NSString *key in attributes){
NSString *themeName = [userDefaults stringForKey:@"theme"];
UIColor *fontColor = [%c(ColorUtil) fontColorForTheme:themeName];
UIColor *accentColor = [%c(ColorUtil) accentColorForSub:[comment subreddit]];
NSString *html = [%c(MMMarkdown) HTMLStringWithMarkdown:body extensions:MMMarkdownExtensionsGitHubFlavored error:nil];
html = [[html stringByReplacingOccurrencesOfString:@"<sup>" withString:@"<font size=\"1\">"] stringByReplacingOccurrencesOfString:@"</sup>" withString:@"</font>"];
html = [[html stringByReplacingOccurrencesOfString:@"<del>" withString:@"<font color=\"green\">"] stringByReplacingOccurrencesOfString:@"</del>" withString:@"</font>"];
html = [[html stringByReplacingOccurrencesOfString:@"<code>" withString:@"<font color=\"blue\">"] stringByReplacingOccurrencesOfString:@"</code>" withString:@"</font>"];
html = [html stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
DTHTMLAttributedStringBuilder *dthtmlBuilder = [[%c(DTHTMLAttributedStringBuilder) alloc] initWithHTML:[html dataUsingEncoding:NSUTF8StringEncoding] options:@{@"DTUseiOS6Attributes": @YES, @"DTDefaultTextColor": fontColor, @"DTDefaultFontSize": @([font pointSize])} documentAttributes:nil];
NSMutableAttributedString *htmlAttributedString = [[NSMutableAttributedString alloc] initWithAttributedString:[dthtmlBuilder generatedAttributedString]];
NSRange htmlStringRange = NSMakeRange(0, [htmlAttributedString length]);
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t•\t" withString:@" • " options:0 range: htmlStringRange];
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t◦\t" withString:@"  ◦ " options:0 range: htmlStringRange];
[[htmlAttributedString mutableString] replaceOccurrencesOfString:@"\t▪\t" withString:@" ▪ " options:0 range: htmlStringRange];
[htmlAttributedString removeAttribute:@"CTForegroundColorFromContext" range:htmlStringRange];
[htmlAttributedString enumerateAttributesInRange:htmlStringRange options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired usingBlock:^(NSDictionary *attributes, NSRange range, BOOL *stop) {
for (NSString *key in attributes){
if ([(UIColor *) attributes[key] isKindOfClass:[UIColor class]]){
UIColor *attrColor = (UIColor *) attributes[key];
if ([[attrColor hexString] isEqualToString:@"#0000FF"]){
UIFont *tempFont = [UIFont fontWithName:@"Courier" size:font.pointSize];
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: accentColor, NSBackgroundColorAttributeName: [%c(ColorUtil) backgroundColorForTheme:themeName], NSFontAttributeName: (tempFont ? tempFont : font)} range:range];
} else if ([[attrColor hexString] isEqualToString:@"#008000"]) {
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: fontColor, NSFontAttributeName:font} range:range];
}
} else if ([(NSURL *) attributes[key] isKindOfClass:[NSURL class]]){
NSURL *attrUrl = (NSURL *)attributes[key];
if (([userDefaults objectForKey:@"ENLARGE_LINKS"] == nil) ? YES : [userDefaults boolForKey:@"ENLARGE_LINKS"]){
[htmlAttributedString addAttribute:NSFontAttributeName value:[%c(FontGenerator) boldFontOfSize:18 submission:NO willOffset:YES] range:range];
}
if ([(UIColor *) attributes[key] isKindOfClass:[UIColor class]]){
UIColor *attrColor = (UIColor *) attributes[key];
if ([[attrColor hexString] isEqualToString:@"#0000FF"]){
UIFont *tempFont = [UIFont fontWithName:@"Courier" size:font.pointSize];
[htmlAttributedString addAttribute:NSForegroundColorAttributeName value:accentColor range:range];
[htmlAttributedString addAttribute:NSUnderlineColorAttributeName value:[UIColor clearColor] range:range];
//skipping showLinkContentType b/c not necessary and spoilers b/c MMMarkdown doesn't support them
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: accentColor, NSBackgroundColorAttributeName: [%c(ColorUtil) backgroundColorForTheme:themeName], NSFontAttributeName: (tempFont ? tempFont : font)} range:range];
} else if ([[attrColor hexString] isEqualToString:@"#008000"]) {
[htmlAttributedString setAttributes:@{NSForegroundColorAttributeName: fontColor, NSFontAttributeName:font} range:range];
}
} else if ([(NSURL *) attributes[key] isKindOfClass:[NSURL class]]){
NSURL *attrUrl = (NSURL *)attributes[key];
[htmlAttributedString yy_setTextHighlightRange:range color: accentColor backgroundColor:nil userInfo:@{@"url": attrUrl}];
break;
}
}
}];
[htmlAttributedString beginEditing];
[htmlAttributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, [htmlAttributedString length]) options:0 usingBlock:^(id value, NSRange range, BOOL *stop){
UIFont *attrFont = (UIFont *)value;
BOOL isBold = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold) != 0;
BOOL isItalic = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitItalic) != 0;
UIFont *newFont = font;
if (isBold){
newFont = [%c(FontGenerator) boldFontOfSize:attrFont.pointSize submission:NO willOffset:NO];
} else if (isItalic){
newFont = [%c(FontGenerator) italicFontOfSize:attrFont.pointSize submission:NO willOffset:NO];
}
[htmlAttributedString removeAttribute:NSFontAttributeName range:range];
[htmlAttributedString addAttribute:NSFontAttributeName value:newFont range:range];
}];
[htmlAttributedString endEditing];
NSMutableAttributedString *newCommentText = [MSHookIvar<NSMutableAttributedString *>(self, "cellContent") initWithAttributedString:htmlAttributedString];
NSAttributedString *tempAttributedString = [[NSAttributedString alloc] initWithString:@""];
[newCommentText appendAttributedString:tempAttributedString]; //to keep the compiler happy
if (([userDefaults objectForKey:@"ENLARGE_LINKS"] == nil) ? YES : [userDefaults boolForKey:@"ENLARGE_LINKS"]){
[htmlAttributedString addAttribute:NSFontAttributeName value:[%c(FontGenerator) boldFontOfSize:18 submission:NO willOffset:YES] range:range];
}
[htmlAttributedString addAttribute:NSForegroundColorAttributeName value:accentColor range:range];
[htmlAttributedString addAttribute:NSUnderlineColorAttributeName value:[UIColor clearColor] range:range];
//skipping showLinkContentType b/c not necessary and spoilers b/c MMMarkdown doesn't support them
[htmlAttributedString yy_setTextHighlightRange:range color: accentColor backgroundColor:nil userInfo:@{@"url": attrUrl}];
break;
}
}
}];
[htmlAttributedString beginEditing];
[htmlAttributedString enumerateAttribute:NSFontAttributeName inRange:NSMakeRange(0, [htmlAttributedString length]) options:0 usingBlock:^(id value, NSRange range, BOOL *stop){
[comment setAuthor:author];
[comment setBody:body];
UIFont *attrFont = (UIFont *)value;
id controller = MSHookIvar<id>(self, "parent");
BOOL isBold = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold) != 0;
BOOL isItalic = (attrFont.fontDescriptor.symbolicTraits & UIFontDescriptorTraitItalic) != 0;
[self performSelectorOnMainThread:@selector(showMenu:) withObject:nil waitUntilDone:YES];
[MSHookIvar<id>(controller, "tableView") performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
UIFont *newFont = font;
[sender setEnabled:YES];
if (isBold){
newFont = [%c(FontGenerator) boldFontOfSize:attrFont.pointSize submission:NO willOffset:NO];
} else if (isItalic){
newFont = [%c(FontGenerator) italicFontOfSize:attrFont.pointSize submission:NO willOffset:NO];
}
[htmlAttributedString removeAttribute:NSFontAttributeName range:range];
[htmlAttributedString addAttribute:NSFontAttributeName value:newFont range:range];
}];
[htmlAttributedString endEditing];
NSMutableAttributedString *newCommentText = [MSHookIvar<NSMutableAttributedString *>(self, "cellContent") initWithAttributedString:htmlAttributedString];
NSAttributedString *tempAttributedString = [[NSAttributedString alloc] initWithString:@""];
[newCommentText appendAttributedString:tempAttributedString]; //to keep the compiler happy
[comment setAuthor:author];
[comment setBody:body];
id controller = MSHookIvar<id>(self, "parent");
[self showMenu:nil];
[MSHookIvar<id>(controller, "tableView") reloadData];
[data[@"sender"] setEnabled:YES];
}
%end

tweak/assets/MMDocument.h → tweak/assets/MMMarkdown/MMDocument.h View File


tweak/assets/MMDocument.m → tweak/assets/MMMarkdown/MMDocument.m View File


tweak/assets/MMDocument_Private.h → tweak/assets/MMMarkdown/MMDocument_Private.h View File


tweak/assets/MMElement.h → tweak/assets/MMMarkdown/MMElement.h View File


tweak/assets/MMElement.m → tweak/assets/MMMarkdown/MMElement.m View File


tweak/assets/MMGenerator.h → tweak/assets/MMMarkdown/MMGenerator.h View File


tweak/assets/MMGenerator.m → tweak/assets/MMMarkdown/MMGenerator.m View File


tweak/assets/MMHTMLParser.h → tweak/assets/MMMarkdown/MMHTMLParser.h View File


tweak/assets/MMHTMLParser.m → tweak/assets/MMMarkdown/MMHTMLParser.m View File


tweak/assets/MMMarkdown-Prefix.pch → tweak/assets/MMMarkdown/MMMarkdown-Prefix.pch View File


tweak/assets/MMMarkdown.h → tweak/assets/MMMarkdown/MMMarkdown.h View File


tweak/assets/MMMarkdown.m → tweak/assets/MMMarkdown/MMMarkdown.m View File


tweak/assets/MMParser.h → tweak/assets/MMMarkdown/MMParser.h View File


tweak/assets/MMParser.m → tweak/assets/MMMarkdown/MMParser.m View File


tweak/assets/MMScanner.h → tweak/assets/MMMarkdown/MMScanner.h View File


tweak/assets/MMScanner.m → tweak/assets/MMMarkdown/MMScanner.m View File


tweak/assets/MMSpanParser.h → tweak/assets/MMMarkdown/MMSpanParser.h View File


tweak/assets/MMSpanParser.m → tweak/assets/MMMarkdown/MMSpanParser.m View File


+ 6
- 0
tweak/assets/TFHelper.h View File

@@ -0,0 +1,6 @@
@interface TFHelper : NSObject
+(void) getUndeleteDataWithID:(NSString *) ident isComment:(BOOL) isComment timeout:(CGFloat) timeout extraData:(NSDictionary *) extra completionTarget:(id) target completionSelector:(SEL) sel;
@end

+ 50
- 0
tweak/assets/TFHelper.m View File

@@ -0,0 +1,50 @@
#import "TFHelper.h"
@implementation TFHelper
+(void) getUndeleteDataWithID:(NSString *) ident isComment:(BOOL) isComment timeout:(CGFloat) timeout extraData:(NSDictionary *) extra completionTarget:(id) target completionSelector:(SEL) sel{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
if (isComment){
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body", ident]]];
} else {
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext", ident]]];
}
[request setHTTPMethod:@"GET"];
[request setTimeoutInterval:timeout];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
NSString *author = @"[author]";
NSString *body = @"[body]";
if (data != nil && error == nil){
id jsonData = [[NSJSONSerialization JSONObjectWithData:data options:0 error:&error] objectForKey:@"data"];
if ([jsonData count] != 0){
author = [jsonData[0] objectForKey:@"author"];
body = isComment ? [jsonData[0] objectForKey:@"body"] : [jsonData[0] objectForKey:@"selftext"];
if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
body = @"[pushshift was unable to archive this]";
}
} else {
body = @"[pushshift has not archived this yet]";
}
} else if (error != nil || data == nil){
body = [NSString stringWithFormat:@"[an error occured while attempting to contact pushshift api (%@)]", [error localizedDescription]];
}
NSMutableDictionary *result = [@{@"author" : author, @"body" : body} mutableCopy];
if (extra){
[result addEntriesFromDictionary:extra];
}
[target performSelectorOnMainThread:sel withObject:result waitUntilDone:NO];
}];
}
@end

Loading…
Cancel
Save