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

Reddit.xm 22KB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. #import "Reddit.h"
  2. #import "assets/TFHelper.h"
  3. static BOOL isEnabled;
  4. static BOOL isRedditEnabled;
  5. static BOOL isTFDeletedOnly;
  6. static CGFloat pushshiftRequestTimeoutValue;
  7. int firstVersionPart = 0;
  8. int secondVersionPart = 0;
  9. %group Reddit_v4_current
  10. UIColor * getCurrentTextColor() {
  11. ThemeManager *themeManager;
  12. id isNightMode;
  13. UIColor *textColor;
  14. if (firstVersionPart == 2020) {
  15. if (secondVersionPart <= 40) {
  16. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  17. AppSettings *appSettings = [%c(AppSettings) sharedSettings];
  18. AccountManager *accountManager = secondVersionPart >= 29 ? [appDelegate accountManager] : [%c(AccountManager) sharedManager];
  19. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:appSettings];
  20. isNightMode = [[accountManager defaults] objectForKey:@"kUseNightKey"];
  21. if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"13.0") && [appSettings isAutoDarkModeEnabled]) {
  22. NSInteger sysInterfaceStyle = [[UITraitCollection _currentTraitCollection] userInterfaceStyle];
  23. if (sysInterfaceStyle == UIUserInterfaceStyleDark){
  24. textColor = [[themeManager darkTheme] bodyTextColor];
  25. } else {
  26. textColor = [[themeManager lightTheme] bodyTextColor];
  27. }
  28. } else {
  29. if (isNightMode) {
  30. textColor = [[themeManager darkTheme] bodyTextColor];
  31. } else {
  32. textColor = [[themeManager lightTheme] bodyTextColor];
  33. }
  34. }
  35. [themeManager release];
  36. } else {
  37. RUIThemeGuidance *themeGuidance = [%c(RUIThemeGuidance) sharedGuidance];
  38. textColor = [[themeGuidance currentTheme] bodyTextColor];
  39. }
  40. } else {
  41. if (secondVersionPart >= 45) {
  42. themeManager = [[%c(ThemeManager) alloc] initWithAppSettings:[%c(AppSettings) sharedSettings]];
  43. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  44. if (isNightMode) {
  45. textColor = [[themeManager darkTheme] bodyTextColor];
  46. } else {
  47. textColor = [[themeManager lightTheme] bodyTextColor];
  48. }
  49. [themeManager release];
  50. } else if (secondVersionPart >= 37) {
  51. themeManager = [[%c(ThemeManager) alloc] initWithTraitCollection:nil appSettings:[%c(AppSettings) sharedSettings]];
  52. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  53. if (isNightMode) {
  54. textColor = [[themeManager nightTheme] bodyTextColor];
  55. } else {
  56. textColor = [[themeManager dayTheme] bodyTextColor];
  57. }
  58. [themeManager release];
  59. } else {
  60. themeManager = [%c(ThemeManager) sharedManager];
  61. isNightMode = [[[%c(AccountManager) sharedManager] defaults] objectForKey:@"kUseNightKey"];
  62. if (isNightMode) {
  63. textColor = [[themeManager nightTheme] bodyTextColor];
  64. } else {
  65. textColor = [[themeManager dayTheme] bodyTextColor];
  66. }
  67. }
  68. }
  69. return textColor;
  70. }
  71. %hook CommentTreeNode
  72. %property(assign,nonatomic)id commentTreeHeaderNode;
  73. %property(assign,nonatomic)id commentTreeCommandBarNode;
  74. %end
  75. %hook CommentTreeHeaderView
  76. - (void)layoutSubviews {
  77. %orig;
  78. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  79. }
  80. %end
  81. %hook CommentTreeHeaderNode
  82. - (void)didLoad {
  83. %orig;
  84. [[self commentTreeNode] setCommentTreeHeaderNode:self];
  85. }
  86. %end
  87. %hook CommentTreeCommandBarNode
  88. - (void)didLoad {
  89. %orig;
  90. [[self commentTreeNode] setCommentTreeCommandBarNode:self];
  91. }
  92. %end
  93. %hook CommentActionSheetViewController
  94. - (void)setItems:(id)arg1 {
  95. NSString *author = [[self comment] author];
  96. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  97. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  98. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  99. CGFloat scale = origImage.size.width / existingImageSize.width;
  100. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  101. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  102. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  103. [undeleteItem release];
  104. }
  105. %orig;
  106. }
  107. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  108. %orig;
  109. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  110. [self dismissViewControllerAnimated:YES completion:nil];
  111. id commentTreeNode = [self commentTreeNode];
  112. Comment *comment = [commentTreeNode comment];
  113. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  114. }
  115. }
  116. %new
  117. - (void)completeUndeleteCommentAction:(NSDictionary *)data {
  118. id commentTreeNode = [self commentTreeNode];
  119. Comment *comment = [commentTreeNode comment];
  120. NSString *author = data[@"author"];
  121. NSString *body = data[@"body"];
  122. UIColor *textColor = getCurrentTextColor();
  123. NSMutableAttributedString *bodyMutableAttributedText;
  124. bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  125. [bodyMutableAttributedText beginEditing];
  126. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  127. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  128. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  129. }];
  130. [bodyMutableAttributedText endEditing];
  131. [comment setAuthor:author];
  132. [comment setBodyText:body];
  133. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  134. if ((firstVersionPart == 2020 && secondVersionPart <= 39) || firstVersionPart == 4) {
  135. [comment setBodyAttributedText:bodyMutableAttributedText];
  136. }
  137. CommentTreeHeaderNode *headerNode = [commentTreeNode commentTreeHeaderNode];
  138. [headerNode updateContentViewsForData:comment];
  139. [headerNode configureNodes];
  140. [bodyMutableAttributedText release];
  141. }
  142. %end
  143. /*
  144. %hook Post
  145. - (id)previewTextWithTheme:(id)arg1 {
  146. %log;
  147. id orig = %orig;
  148. HBLogDebug(@"previewTextWithTheme: orig: %@", orig);
  149. return orig;
  150. }
  151. - (id)previewFeedPostTextString {
  152. %log;
  153. id orig = %orig;
  154. HBLogDebug(@"previewFeedPostTextString orig: %@", orig);
  155. return orig;
  156. }
  157. - (id)previewPostText:(id)arg1 {
  158. %log;
  159. id orig = %orig;
  160. HBLogDebug(@"previewPostText: orig: %@", orig);
  161. return orig;
  162. }
  163. %end
  164. */
  165. %hook PostDetailViewController
  166. %property(strong,nonatomic) id feedPostTextWithThumbnailNode;
  167. %property(strong,nonatomic) id feedPostDetailCellNode;
  168. %end
  169. %hook FeedPostDetailCellNode
  170. - (void)didLoad {
  171. %orig;
  172. [[[self delegate] viewController] setFeedPostDetailCellNode:self];
  173. }
  174. %end
  175. %hook PostActionSheetViewController
  176. - (void)setItems:(id)arg1 {
  177. Post *post = [self post];
  178. NSString *author = [post author];
  179. if ([post isSelfPost]) {
  180. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  181. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  182. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  183. CGFloat scale = origImage.size.width / existingImageSize.width;
  184. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  185. id undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  186. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  187. [undeleteItem release];
  188. }
  189. }
  190. %orig;
  191. }
  192. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  193. %orig;
  194. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  195. [self dismissViewControllerAnimated:YES completion:nil];
  196. Post *post = [self post];
  197. if ([post isSelfPost]){
  198. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  199. }
  200. }
  201. }
  202. %new
  203. - (void)completeUndeletePostAction:(NSDictionary *)data {
  204. Post *post = [self post];
  205. NSString *author = data[@"author"];
  206. NSString *body = data[@"body"];
  207. UIColor *textColor = getCurrentTextColor();
  208. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  209. [bodyMutableAttributedText beginEditing];
  210. [bodyMutableAttributedText enumerateAttribute:NSForegroundColorAttributeName inRange:NSMakeRange(0, bodyMutableAttributedText.length) options:0 usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
  211. [bodyMutableAttributedText removeAttribute:NSForegroundColorAttributeName range:range];
  212. [bodyMutableAttributedText addAttribute:NSForegroundColorAttributeName value:textColor range:range];
  213. }];
  214. [bodyMutableAttributedText endEditing];
  215. [post setSelfText:body];
  216. [post setAuthor:author];
  217. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  218. FeedPostTitleNode *titleNode = [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode];
  219. Post *feedPost = [titleNode post];
  220. [feedPost setAuthor:author];
  221. if (firstVersionPart == 2020) {
  222. if (secondVersionPart >= 42) {
  223. RichTextDisplayNode *selfTextNode = [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] selfTextNode];
  224. [selfTextNode setAttributedText:bodyMutableAttributedText];
  225. [selfTextNode configureDisplayNodes];
  226. } else {
  227. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  228. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
  229. }
  230. if (secondVersionPart >= 41) {
  231. [titleNode configureNodes];
  232. }
  233. } else {
  234. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  235. if (secondVersionPart >= 44) {
  236. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] contentNode] configureSelfTextNode];
  237. } else if (secondVersionPart >= 38) {
  238. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  239. } else {
  240. [[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] configureSelfTextNode];
  241. [[[[[self postActionSheetDelegate] controller] feedPostDetailCellNode] titleNode] configureNodes];
  242. }
  243. }
  244. [bodyMutableAttributedText release];
  245. }
  246. %end
  247. %end
  248. %group Reddit_v4_ios10
  249. %hook CommentsViewController
  250. %new
  251. - (void)updateComments {
  252. [self reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  253. }
  254. %new
  255. - (void)updatePostText {
  256. if (secondVersionPart >= 2){
  257. [self reloadPostSection:YES];
  258. } else {
  259. [self feedPostViewDidUpdatePost:[self postData] shouldReloadFeed:NO];
  260. }
  261. }
  262. %end
  263. %hook CommentActionSheetViewController
  264. - (void)setItems:(id)arg1 {
  265. NSString *author = [[self comment] author];
  266. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  267. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  268. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  269. CGFloat scale = origImage.size.width / existingImageSize.width;
  270. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  271. id undeleteItem;
  272. if (secondVersionPart >= 18) {
  273. undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  274. } else {
  275. undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self comment]];
  276. }
  277. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  278. [undeleteItem release];
  279. }
  280. %orig;
  281. }
  282. // >= 4.21
  283. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  284. %orig;
  285. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  286. [self dismissViewControllerAnimated:YES completion:nil];
  287. Comment *comment = [self comment];
  288. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  289. }
  290. }
  291. // <= 4.20
  292. - (void)actionSheetViewController:(id)arg1 didSelectItem:(id)arg2 {
  293. %orig;
  294. if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]){
  295. [self dismissViewControllerAnimated:YES completion:nil];
  296. Comment *comment = [self comment];
  297. [%c(TFHelper) getUndeleteDataWithID:[[comment pk] componentsSeparatedByString:@"_"][1] isComment:YES timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeleteCommentAction:)];
  298. }
  299. }
  300. %new
  301. - (void)completeUndeleteCommentAction:(NSDictionary *)data {
  302. Comment *comment = [self comment];
  303. NSString *body = data[@"body"];
  304. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  305. [comment setAuthor:data[@"author"]];
  306. [comment setBodyText:body];
  307. [comment setBodyAttributedText:bodyMutableAttributedText];
  308. if (secondVersionPart >= 12) {
  309. [comment setBodyRichTextAttributed:bodyMutableAttributedText];
  310. }
  311. [[self commentActionSheetDelegate] updateComments];
  312. [bodyMutableAttributedText release];
  313. }
  314. %end
  315. %hook PostActionSheetViewController
  316. - (void)setItems:(id)arg1{
  317. Post *post = [self post];
  318. NSString *author = [post author];
  319. if ([post isSelfPost]) {
  320. if ([%c(TFHelper) shouldShowUndeleteButtonWithInfo:author isDeletedOnly:isTFDeletedOnly]) {
  321. UIImage* origImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  322. CGSize existingImageSize = [[arg1[0] leftIconImage] size];
  323. CGFloat scale = origImage.size.width / existingImageSize.width;
  324. UIImage *newImage = [UIImage imageWithCGImage:[origImage CGImage] scale:scale orientation:origImage.imageOrientation];
  325. id undeleteItem;
  326. if (secondVersionPart >= 18) {
  327. undeleteItem = [[%c(RUIActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  328. } else {
  329. undeleteItem = [[%c(ActionSheetItem) alloc] initWithLeftIconImage:newImage text:@"TF did that say?" identifier:@"undeleteItemIdentifier" context:[self post]];
  330. }
  331. arg1 = [arg1 arrayByAddingObject:undeleteItem];
  332. [undeleteItem release];
  333. }
  334. }
  335. %orig;
  336. }
  337. // >= 4.21
  338. - (void)handleDidSelectActionSheetItem:(id)arg1 {
  339. %orig;
  340. if ([[arg1 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  341. [self dismissViewControllerAnimated:YES completion:nil];
  342. Post *post = [self post];
  343. if ([post isSelfPost]) {
  344. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  345. }
  346. }
  347. }
  348. // <= 4.20
  349. - (void)actionSheetViewController:(id)arg1 didSelectItem:(id)arg2 {
  350. %orig;
  351. if ([[arg2 identifier] isEqualToString:@"undeleteItemIdentifier"]) {
  352. [self dismissViewControllerAnimated:YES completion:nil];
  353. Post *post = [self post];
  354. if ([post isSelfPost]){
  355. [%c(TFHelper) getUndeleteDataWithID:[[post pk] componentsSeparatedByString:@"_"][1] isComment:NO timeout:pushshiftRequestTimeoutValue extraData:nil completionTarget:self completionSelector:@selector(completeUndeletePostAction:)];
  356. }
  357. }
  358. }
  359. %new
  360. - (void)completeUndeletePostAction:(NSDictionary *)data {
  361. Post *post = [self post];
  362. NSString *body = data[@"body"];
  363. NSMutableAttributedString *bodyMutableAttributedText = [[NSMutableAttributedString alloc] initWithAttributedString:[%c(NSAttributedStringMarkdownParser) attributedStringUsingCurrentConfig:body]];
  364. [post setAuthor:data[@"author"]];
  365. [post setSelfText:body];
  366. [post setSelfTextAttributed:bodyMutableAttributedText];
  367. if (secondVersionPart >= 8) {
  368. [post setSelfPostRichTextAttributed:bodyMutableAttributedText];
  369. }
  370. if (secondVersionPart >= 15) {
  371. [post setPreviewFeedPostTextString:bodyMutableAttributedText];
  372. }
  373. [[self postActionSheetDelegate] updatePostText];
  374. [bodyMutableAttributedText release];
  375. }
  376. %end
  377. %end
  378. //outdated and unchanged from first version of this tweak...
  379. //TODO: move button to menu, add post support, make async requests once I feel like doing it
  380. %group Reddit_v3
  381. %hook CommentView
  382. %new
  383. -(void) buttonAction {
  384. id commentsViewController = [self delegate];
  385. id comment = [self comment];
  386. NSError* error;
  387. NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  388. [request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.pushshift.io/reddit/search/comment/?ids=%@&fields=author,body",[comment pkWithoutPrefix]]]];
  389. [request setHTTPMethod:@"GET"];
  390. NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
  391. NSString *author = @"[author]";
  392. NSString *body = @"[body]";
  393. if (data != nil && error == nil){
  394. id jsonData = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
  395. author = [[jsonData objectForKey:@"data"][0] objectForKey:@"author"];
  396. body = [[jsonData objectForKey:@"data"][0] objectForKey:@"body"];
  397. if ([body isEqualToString:@"[deleted]"] || [body isEqualToString:@"[removed]"]){
  398. body = @"[comment was unable to be archived]";
  399. }
  400. } else if (error != nil || data == nil){
  401. body = @"[an error occured]";
  402. }
  403. [comment setValue:author forKey:@"author"];
  404. [comment setValue:[%c(MarkDownParser) attributedStringFromMarkdownString: body] forKey:@"bodyAttributedText"];
  405. [comment setValue:body forKey:@"bodyText"];
  406. [commentsViewController reloadCommentsWithNewCommentsHighlight:NO autoScroll:NO animated:NO];
  407. }
  408. -(id) initWithFrame:(id)arg1{
  409. id orig = %orig;
  410. id commandView = [self commandView];
  411. UIButton *undeleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
  412. [undeleteButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
  413. UIImage* undeleteImage = [UIImage imageWithContentsOfFile:@"/var/mobile/Library/Application Support/TFDidThatSay/eye160dark.png"];
  414. [undeleteButton setImage:undeleteImage forState:UIControlStateNormal];
  415. [commandView setUndeleteButton:undeleteButton];
  416. [commandView addSubview:undeleteButton];
  417. return orig;
  418. }
  419. %end
  420. %hook CommentCommandView
  421. %property (assign, nonatomic) id undeleteButton;
  422. -(void) layoutSubviews{
  423. %orig;
  424. UIButton *button = [self undeleteButton];
  425. button.frame = CGRectMake([[self overflowButton ] frame].origin.x - 32, 0, 32, 32);
  426. }
  427. %end
  428. %end
  429. static void loadPrefs(){
  430. NSMutableDictionary *prefs = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/User/Library/Preferences/com.lint.undelete.prefs.plist"];
  431. if (prefs){
  432. isEnabled = [prefs objectForKey:@"isEnabled"] ? [[prefs objectForKey:@"isEnabled"] boolValue] : YES;
  433. isRedditEnabled = [prefs objectForKey:@"isRedditEnabled"] ? [[prefs objectForKey:@"isRedditEnabled"] boolValue] : YES;
  434. isTFDeletedOnly = [prefs objectForKey:@"isTFDeletedOnly"] ? [[prefs objectForKey:@"isTFDeletedOnly"] boolValue] : YES;
  435. pushshiftRequestTimeoutValue = [prefs objectForKey:@"requestTimeoutValue"] ? [[prefs objectForKey:@"requestTimeoutValue"] doubleValue] : 10;
  436. } else {
  437. isEnabled = YES;
  438. isRedditEnabled = YES;
  439. isTFDeletedOnly = YES;
  440. pushshiftRequestTimeoutValue = 10;
  441. }
  442. }
  443. static void prefsChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
  444. loadPrefs();
  445. }
  446. %ctor{
  447. loadPrefs();
  448. NSString* processName = [[NSProcessInfo processInfo] processName];
  449. @try {
  450. NSArray *redditVersion = [[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"] componentsSeparatedByString:@"."];
  451. firstVersionPart = [redditVersion[0] intValue];
  452. secondVersionPart = [redditVersion[1] intValue];
  453. }
  454. @catch (NSException *exc) {
  455. firstVersionPart = 0;
  456. secondVersionPart = 0;
  457. }
  458. if ([processName isEqualToString:@"Reddit"]){
  459. if (isRedditEnabled && isEnabled) {
  460. CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback)prefsChanged, CFSTR("com.lint.undelete.prefs.changed"), NULL, CFNotificationSuspensionBehaviorCoalesce);
  461. /*
  462. if (firstVersionPart == 4 || firstVersionPart == 2020) {
  463. if (secondVersionPart <= 32 && firstVersionPart != 2020) {
  464. %init(Reddit_v4_ios10);
  465. } else{
  466. %init(Reddit_v4_current);
  467. }
  468. } else if (firstVersionPart == 3) {
  469. %init(Reddit_v3);
  470. }
  471. */
  472. if (firstVersionPart >= 2020 || (firstVersionPart == 4 && secondVersionPart > 32)) {
  473. %init(Reddit_v4_current);
  474. } else if (firstVersionPart == 4 && secondVersionPart <= 32) {
  475. %init(Reddit_v4_ios10);
  476. } else if (firstVersionPart == 3) {
  477. %init(Reddit_v3);
  478. }
  479. }
  480. }
  481. }