You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Reddit.xm 12KB

5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
5 yıl önce
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. if ([[[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."][1] integerValue] >= 44){
  157. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
  158. } else {
  159. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  160. }
  161. [request release];
  162. [queue release];
  163. [bodyMutableAttributedText release];
  164. [themeManager release];
  165. }];
  166. }
  167. }
  168. }
  169. %end
  170. %end
  171. %group Redditv3
  172. %hook CommentView
  173. %new
  174. -(void) buttonAction {
  175. id commentsViewController = [self delegate];
  176. id comment = [self comment];
  177. NSError* error;
  178. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  179. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment pkWithoutPrefix]]]];
  180. [request setHTTPMethod:@"GET"];
  181. NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
  182. NSString *author = @"[author]";
  183. NSString *body = @"[body]";
  184. if (data != nil && error == nil){
  185. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  186. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  187. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  188. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  189. body = @"[comment was unable to be archived]";
  190. }
  191. } else if (error != nil || data == nil){
  192. body = @"[an error occured]";
  193. }
  194. [comment setValue:author forKey:@"author"];
  195. [comment setValue:[%c(MarkDownParser) attributedStringFromMarkdownString: body] forKey:@"bodyAttributedText"];
  196. [comment setValue:body forKey:@"bodyText"];
  197. [commentsViewController reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  198. }
  199. -(id) initWithFrame:(id)arg1{
  200. id orig = %orig;
  201. id commandView = [self commandView];
  202. UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
  203. [undeleteButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
  204. UIImage* undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  205. [undeleteButton setImage:undeleteImage forState:UIControlStateNormal];
  206. [commandView setUndeleteButton:undeleteButton];
  207. [commandView addSubview:undeleteButton];
  208. return orig;
  209. }
  210. %end
  211. %hook CommentCommandView
  212. %property (assign, nonatomic) id undeleteButton;
  213. -(void) layoutSubviews{
  214. %orig;
  215. UIButton *button = [self undeleteButton];
  216. button.frame = CGRectMake([[self overflowButton ] frame].origin.x - 32, 0, 32, 32);
  217. }
  218. %end
  219. %end
  220. %ctor{
  221. NSString* processName = [[NSProcessInfo processInfo] processName];
  222. NSString* version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
  223. NSArray* versionArray = [version componentsSeparatedByString:@"."];
  224. if ([processName isEqualToString:@"Reddit"]){
  225. if ([versionArray[0] isEqualToString:@"4"]){
  226. %init(Redditv4);
  227. } else if ([versionArray[0] isEqualToString:@"3"]) {
  228. %init(Redditv3);
  229. }
  230. }
  231. }