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.

Reddit.xm 11KB

5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
5 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. }