Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

299 lines
9.7KB

  1. #include "Tweak.h"
  2. %group Redditv4
  3. %hook CommentTreeNode
  4. %property(assign,nonatomic)id commentTreeHeaderNode;
  5. %property(assign,nonatomic)id commentTreeCommandBarNode;
  6. %property(assign,nonatomic)BOOL isLoadingArchivedComment;
  7. %end
  8. %hook CommentTreeHeaderNode
  9. -(void) didLoad{
  10. %orig;
  11. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  12. }
  13. %end
  14. %hook CommentTreeCommandBarNode
  15. %property(assign,nonatomic) id activityIndicator;
  16. %property(assign,nonatomic) id undeleteButton;
  17. -(void) didLoad{
  18. %orig;
  19. [[self commentTreeNode] setCommentTreeCommandBarNode:self];
  20. [[self commentTreeNode] setIsLoadingArchivedComment:NO];
  21. }
  22. %end
  23. /*
  24. %hook ASCollectionView
  25. -(id) dequeueReusableCellWithReuseIdentifier: (id) arg1 forIndexPath:(id) arg2{
  26. id orig = %orig;
  27. if ([orig isKindOfClass:[%c(_ASCollectionViewCell) class]]){
  28. id node = [[orig node] contentNode];
  29. if ([node isKindOfClass:[%c(CommentTreeDisplayNode) class]]) {
  30. id commentNode = [node commentNode];
  31. if ([commentNode isLoadingArchivedComment]){
  32. //[[[commentNode commentTreeCommandBarNode] activityIndicator] startAnimating];
  33. }
  34. }
  35. }
  36. return orig;
  37. }
  38. %end
  39. */
  40. %hook CommentActionSheetViewController
  41. -(void) setItems:(id) arg1{
  42. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  43. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  44. CGFloat scale = origImage.size.width / existingImageSize.width;
  45. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  46. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  47. %orig([arg1 arrayByAddingObject:undeleteItem]);
  48. [undeleteItem release];
  49. }
  50. -(void) handleDidSelectActionSheetItem:(id) arg1{
  51. %orig;
  52. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  53. [self dismissViewControllerAnimated:YES completion:nil];
  54. id commentTreeNode = [self commentTreeNode];
  55. id comment = [commentTreeNode comment];
  56. [commentTreeNode setIsLoadingArchivedComment:YES];
  57. /*
  58. id isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  59. if (isNightMode){
  60. UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
  61. } else {
  62. UIActivityIndicatorView* activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
  63. }
  64. [self setActivityIndicator:activityIndicator];
  65. [activityIndicator startAnimating];
  66. [sender addSubview:activityIndicator];
  67. */
  68. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  69. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  70. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
  71. [request setHTTPMethod:@"GET"];
  72. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  73. NSString *author = @"[author]";
  74. NSString *body = @"[body]";
  75. if (data != nil && error == nil){
  76. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  77. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  78. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  79. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  80. body = @"[comment was unable to be archived]";
  81. }
  82. } else if (error != nil || data == nil){
  83. body = @"[an error occured]";
  84. }
  85. id textColor = [[comment bodyRichTextAttributed] attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [[comment bodyRichTextAttributed] length])][@"NSColor"];
  86. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  87. [bodyMutableAttributedText beginEditing];
  88. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  89. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  90. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  91. }];
  92. [bodyMutableAttributedText endEditing];
  93. [comment setValue:bodyMutableAttributedText forKey:@"bodyRichTextAttributed"];
  94. [comment setValue:author forKey:@"author"];
  95. [comment setValue:body forKey:@"bodyText"];
  96. [comment setValue:bodyMutableAttributedText forKey:@"bodyAttributedText"];
  97. [[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment];
  98. [commentTreeNode setIsLoadingArchivedComment:NO];
  99. //[activityIndicator stopAnimating];
  100. [request release];
  101. [queue release];
  102. [bodyMutableAttributedText release];
  103. }];
  104. }
  105. }
  106. %end
  107. %hook PostDetailViewController
  108. %property(assign,nonatomic) id feedPostTextWithThumbnailNode;
  109. %property(assign,nonatomic) id feedPostDetailCellNode;
  110. %end
  111. %hook FeedPostDetailCellNode
  112. -(void) didLoad{
  113. %orig;
  114. [[[self delegate] viewController] setFeedPostTextWithThumbnailNode:[self textNode]];
  115. [[[self delegate] viewController] setFeedPostDetailCellNode:self];
  116. }
  117. %end
  118. %hook PostActionSheetViewController
  119. -(void) setItems:(id) arg1{
  120. id post = [self post];
  121. if ([post isSelfPost]){
  122. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  123. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  124. CGFloat scale = origImage.size.width / existingImageSize.width;
  125. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  126. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  127. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  128. [undeleteItem release];
  129. }
  130. %orig;
  131. }
  132. -(void) handleDidSelectActionSheetItem:(id) arg1{
  133. %orig;
  134. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  135. [self dismissViewControllerAnimated:YES completion:nil];
  136. id post = [self post];
  137. if ([post isSelfPost]){
  138. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  139. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  140. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
  141. [request setHTTPMethod:@"GET"];
  142. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  143. NSString *author = @"[author]";
  144. NSString *body = @"[body]";
  145. if (data != nil && error == nil){
  146. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  147. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  148. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
  149. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  150. body = @"[comment was unable to be archived]";
  151. }
  152. } else if (error != nil || data == nil){
  153. body = @"[an error occured]";
  154. }
  155. id textColor = [[post selfPostRichTextAttributed] attributesAtIndex:0 longestEffectiveRange:nil inRange:NSMakeRange(0, [[post selfPostRichTextAttributed] length])][@"NSColor"];
  156. if (textColor == nil){
  157. textColor = [UIColor colorWithRed:0.843137 green:0.854902 blue:0.862745 alpha:1.0];
  158. }
  159. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  160. [bodyMutableAttributedText beginEditing];
  161. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  162. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  163. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  164. }];
  165. [bodyMutableAttributedText endEditing];
  166. [post setValue:bodyMutableAttributedText forKey:@"selfPostRichTextAttributed"];
  167. [post setValue:bodyMutableAttributedText forKey:@"previewFeedPostTextString"];
  168. [post setAuthor:author];
  169. [post setValue:body forKey:@"selfText"];
  170. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  171. [request release];
  172. [queue release];
  173. [bodyMutableAttributedText release];
  174. }];
  175. }
  176. }
  177. }
  178. %end
  179. %end
  180. %ctor{
  181. NSString* version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  182. NSArray* versionArray = [version componentsSeparatedByString:@"."];
  183. if ([versionArray[0] isEqualToString:@"4"]){
  184. %init(Redditv4);
  185. } else if ([versionArray[0] isEqualToString:@"3"]) {
  186. }
  187. }