選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

352 行
11KB

  1. #import "Reddit.h"
  2. %group Redditv4
  3. %hook CommentTreeNode
  4. %property(assign,nonatomic)id commentTreeHeaderNode;
  5. %property(assign,nonatomic)id commentTreeCommandBarNode;
  6. %end
  7. %hook CommentTreeHeaderNode
  8. -(void) didLoad{
  9. %orig;
  10. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  11. }
  12. %end
  13. %hook CommentTreeCommandBarNode
  14. %property(assign,nonatomic) id activityIndicator;
  15. %property(assign,nonatomic) id undeleteButton;
  16. -(void) didLoad{
  17. %orig;
  18. [[self commentTreeNode] setCommentTreeCommandBarNode:self];
  19. }
  20. %end
  21. %hook CommentActionSheetViewController
  22. -(void) setItems:(id) arg1{
  23. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  24. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  25. CGFloat scale = origImage.size.width / existingImageSize.width;
  26. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  27. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  28. %orig([arg1 arrayByAddingObject:undeleteItem]);
  29. [undeleteItem release];
  30. }
  31. -(void) handleDidSelectActionSheetItem:(id) arg1{
  32. %orig;
  33. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  34. [self dismissViewControllerAnimated:YES completion:nil];
  35. id commentTreeNode = [self commentTreeNode];
  36. id comment = [commentTreeNode comment];
  37. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  38. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  39. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[[comment pk] componentsSeparatedByString:@"_"][1]]]];
  40. [request setHTTPMethod:@"GET"];
  41. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  42. NSString *author = @"[author]";
  43. NSString *body = @"[body]";
  44. if (data != nil && error == nil){
  45. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  46. if ([[jsonData objectForKey:@"data"] count] != 0){
  47. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  48. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  49. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  50. body = @"[pushshift was unable to archive this]";
  51. }
  52. } else {
  53. body = @"[pushshift has not archived this yet]";
  54. }
  55. } else if (error != nil || data == nil){
  56. body = @"[an error occured]";
  57. }
  58. id themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  59. id isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  60. id textColor;
  61. if (isNightMode) {
  62. textColor = [[themeManager nightTheme] bodyTextColor];
  63. } else{
  64. textColor = [[themeManager dayTheme] bodyTextColor];
  65. }
  66. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  67. [bodyMutableAttributedText beginEditing];
  68. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  69. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  70. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  71. }];
  72. [bodyMutableAttributedText endEditing];
  73. [comment setValue:bodyMutableAttributedText forKey:@"bodyRichTextAttributed"];
  74. [comment setValue:author forKey:@"author"];
  75. [comment setValue:body forKey:@"bodyText"];
  76. [comment setValue:bodyMutableAttributedText forKey:@"bodyAttributedText"];
  77. [[commentTreeNode commentTreeHeaderNode] updateContentViewsForData:comment];
  78. [request release];
  79. [queue release];
  80. [bodyMutableAttributedText release];
  81. [themeManager release];
  82. }];
  83. }
  84. }
  85. %end
  86. %hook PostDetailViewController
  87. %property(assign,nonatomic) id feedPostTextWithThumbnailNode;
  88. %property(assign,nonatomic) id feedPostDetailCellNode;
  89. %end
  90. %hook FeedPostDetailCellNode
  91. -(void) didLoad{
  92. %orig;
  93. [[[self delegate] viewController] setFeedPostDetailCellNode:self];
  94. }
  95. %end
  96. %hook PostActionSheetViewController
  97. -(void) setItems:(id) arg1{
  98. id post = [self post];
  99. if ([post isSelfPost]){
  100. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  101. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  102. CGFloat scale = origImage.size.width / existingImageSize.width;
  103. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  104. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  105. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  106. [undeleteItem release];
  107. }
  108. %orig;
  109. }
  110. -(void) handleDidSelectActionSheetItem:(id) arg1{
  111. %orig;
  112. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  113. [self dismissViewControllerAnimated:YES completion:nil];
  114. id post = [self post];
  115. if ([post isSelfPost]){
  116. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  117. NSOperationQueue *queue = [[NSOperationQueue alloc] init];
  118. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/submission/?ids=%@&fields=author,selftext",[[post pk] componentsSeparatedByString:@"_"][1]]]];
  119. [request setHTTPMethod:@"GET"];
  120. [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
  121. NSString *author = @"[author]";
  122. NSString *body = @"[body]";
  123. if (data != nil && error == nil){
  124. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  125. if ([[jsonData objectForKey:@"data"] count] != 0){
  126. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  127. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"selftext"];
  128. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  129. body = @"[pushshift was unable to archive this]";
  130. }
  131. } else {
  132. body = @"[pushshift has not archived this yet]";
  133. }
  134. } else if (error != nil || data == nil){
  135. body = @"[an error occured]";
  136. }
  137. id themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  138. id isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  139. id textColor;
  140. if (isNightMode) {
  141. textColor = [[themeManager nightTheme] bodyTextColor];
  142. } else{
  143. textColor = [[themeManager dayTheme] bodyTextColor];
  144. }
  145. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  146. [bodyMutableAttributedText beginEditing];
  147. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  148. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  149. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  150. }];
  151. [bodyMutableAttributedText endEditing];
  152. [post setValue:bodyMutableAttributedText forKey:@"selfPostRichTextAttributed"];
  153. [post setValue:bodyMutableAttributedText forKey:@"previewFeedPostTextString"];
  154. [post setAuthor:author];
  155. [post setValue:body forKey:@"selfText"];
  156. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  157. [request release];
  158. [queue release];
  159. [bodyMutableAttributedText release];
  160. [themeManager release];
  161. }];
  162. }
  163. }
  164. }
  165. %end
  166. %end
  167. %group Redditv3
  168. %hook CommentView
  169. %new
  170. -(void) buttonAction {
  171. id commentsViewController = [self delegate];
  172. id comment = [self comment];
  173. NSError* error;
  174. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  175. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment pkWithoutPrefix]]]];
  176. [request setHTTPMethod:@"GET"];
  177. NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
  178. NSString *author = @"[author]";
  179. NSString *body = @"[body]";
  180. if (data != nil && error == nil){
  181. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  182. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  183. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  184. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  185. body = @"[comment was unable to be archived]";
  186. }
  187. } else if (error != nil || data == nil){
  188. body = @"[an error occured]";
  189. }
  190. [comment setValue:author forKey:@"author"];
  191. [comment setValue:[%c(MarkDownParser) attributedStringFromMarkdownString: body] forKey:@"bodyAttributedText"];
  192. [comment setValue:body forKey:@"bodyText"];
  193. [commentsViewController reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  194. }
  195. -(id) initWithFrame:(id)arg1{
  196. id orig = %orig;
  197. id commandView = [self commandView];
  198. UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
  199. [undeleteButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
  200. UIImage* undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  201. [undeleteButton setImage:undeleteImage forState:UIControlStateNormal];
  202. [commandView setUndeleteButton:undeleteButton];
  203. [commandView addSubview:undeleteButton];
  204. return orig;
  205. }
  206. %end
  207. %hook CommentCommandView
  208. %property (assign, nonatomic) id undeleteButton;
  209. -(void) layoutSubviews{
  210. %orig;
  211. UIButton *button = [self undeleteButton];
  212. button.frame = CGRectMake([[self overflowButton ] frame].origin.x - 32, 0, 32, 32);
  213. }
  214. %end
  215. %end
  216. %ctor{
  217. NSString* processName = [[NSProcessInfo processInfo] processName];
  218. NSString* version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  219. NSArray* versionArray = [version componentsSeparatedByString:@"."];
  220. if ([processName isEqualToString:@"Reddit"]){
  221. if ([versionArray[0] isEqualToString:@"4"]){
  222. %init(Redditv4);
  223. } else if ([versionArray[0] isEqualToString:@"3"]) {
  224. %init(Redditv3);
  225. }
  226. }
  227. }