This repository has been archived by the owner on Mar 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tweak.xm
298 lines (238 loc) · 7.92 KB
/
Tweak.xm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <MBProgressHUD/MBProgressHUD.h>
#import <instap4tch0-Swift.h>
#define HAS_FEATURE(X) [IPFeatureManager isFeatureEnabled:IPFeature##X]
#import "Categories.h"
UIViewController *topMostVC() {
id rootVC = [[[UIApplication sharedApplication] keyWindow] rootViewController];
return [rootVC topMostViewController];
}
%hook IGAppDelegate
- (void)registerForPushWithUserSession:(id)arg1 { }
%end
%hook UIApplication
- (void)registerForRemoteNotifications { }
%end
%hook IGMainFeedItemConfiguration
- (BOOL)shouldHideFeedItem:(id)feedItem {
if (HAS_FEATURE(HideSponsoredContent)) {
return %orig || [feedItem valueForKey:@"_sponsoredPostInfo"] != nil;
}
return %orig;
}
%end
%hook IGListAdapter
- (void)collectionView:(id)collectionView
willDisplayCell:(id)cell
forItemAtIndexPath:(id)indexPath {
if ([cell isKindOfClass:%c(IGHiddenReasonListCell)] && HAS_FEATURE(HideSponsoredContent)) {
UITableView *tableView = [cell valueForKey:@"_tableView"];
// Tap "Not relevant" on tombstone cell
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
[tableView.delegate tableView:tableView
didSelectRowAtIndexPath:indexPath];
} else {
%orig;
}
}
%end
%hook IGStoryViewerViewController
-(BOOL)_canFetchAd {
return %orig && !HAS_FEATURE(HideSponsoredContent);
}
%end
%hook UIImage
+ (UIImage *)imageNamed:(NSString *)name {
if ([name isEqualToString:@"logotype-feed"]) {
return [[UIImage alloc] initWithResource: IPImageResourceLogo];
}
return %orig;
}
%end
%hook IGFeedItemPhotoCell
- (void)feedPhotoDidDoubleTapToLike:(id)tap locationInfo:(id)locationInfo {
if (!HAS_FEATURE(DoubleTapGuardPhoto)) { %orig; return; }
[[UIAlertController likeAlertWithPostType:IPPostTypePhoto success: ^{
%orig;
}] showOnViewController:topMostVC()];
}
- (void)didMoveToWindow {
id photoView = [self valueForKey:@"_photoView"];
BOOL hasLongPressGR = NO;
for (UIGestureRecognizer *gr in [photoView gestureRecognizers]) {
if ([gr isKindOfClass:%c(UILongPressGestureRecognizer)]) {
hasLongPressGR = YES;
break;
}
}
if (!hasLongPressGR) {
UILongPressGestureRecognizer *longGestureRecognizer =
[[UILongPressGestureRecognizer alloc] initWithTarget: self
action: @selector(didLongPressOnPhoto:)];
[photoView addGestureRecognizer: longGestureRecognizer];
}
}
%new
- (void)didLongPressOnPhoto:(id)sender {
static BOOL guard = NO;
if (!HAS_FEATURE(DownloadPhoto)) { return; }
if (guard) { return; }
guard = YES;
[sender setEnabled: NO];
IGFeedItem *feedItem = [self valueForKey:@"_post"];
NSURL *url = [feedItem highestResolutionPhotoURL];
if (url) {
[[IPDownloader sharedInstance] downloadPost:IPPostTypePhoto
withURL:url
completion: ^(NSError *error){
if (error) {
[[UIAlertController errorAlertForError:error] showOnViewController:topMostVC()];
} else {
[[UIAlertController localizedAlertWithTitle:@"generic.success"
message: @"alert.success.photo_downloaded"] showOnViewController:topMostVC()];
}
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC);
dispatch_after(delay, dispatch_get_main_queue(), ^{
guard = NO;
[sender setEnabled: YES];
});
}];
}
}
%end
%hook IGFeedItemPageCell
- (void)pageMediaViewDidDoubleTap:(id)tap {
if (!HAS_FEATURE(DoubleTapGuardPage)) { %orig; return; }
[[UIAlertController likeAlertWithPostType:IPPostTypePage success: ^{
%orig;
}] showOnViewController:topMostVC()];
}
%end
%hook IGFeedItemVideoCell
- (void)didDoubleTapFeedItemVideoView:(id)tap {
if (!HAS_FEATURE(DoubleTapGuardVideo)) { %orig; return; }
[[UIAlertController likeAlertWithPostType:IPPostTypeVideo success: ^{
%orig;
}] showOnViewController:topMostVC()];
}
- (void)didMoveToWindow {
id videoView = [self valueForKey:@"_videoView"];
BOOL hasLongPressGR = NO;
for (UIGestureRecognizer *gr in [videoView gestureRecognizers]) {
if ([gr isKindOfClass:[UILongPressGestureRecognizer class]]) {
hasLongPressGR = YES;
break;
}
}
if (!hasLongPressGR) {
UILongPressGestureRecognizer *longGestureRecognizer =
[[UILongPressGestureRecognizer alloc] initWithTarget: self
action: @selector(didLongPressOnVideo:)];
[videoView addGestureRecognizer: longGestureRecognizer];
}
}
%new
- (void)didLongPressOnVideo:(id)sender {
static BOOL guard = NO;
if (!HAS_FEATURE(DownloadVideo)) { return; }
if (guard) { return; }
guard = YES;
[sender setEnabled: NO];
IGFeedItem *feedItem = [self valueForKey:@"_post"];
NSURL *url = [feedItem highestResolutionVideoURL];
if (url) {
[[IPDownloader sharedInstance] downloadPost:IPPostTypeVideo
withURL:url
completion: ^(NSError *error){
if (error) {
[[UIAlertController errorAlertForError:error] showOnViewController:topMostVC()];
} else {
[[UIAlertController localizedAlertWithTitle:@"generic.success"
message: @"alert.success.video_downloaded"] showOnViewController:topMostVC()];
}
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC);
dispatch_after(delay, dispatch_get_main_queue(), ^{
guard = NO;
[sender setEnabled: YES];
});
}];
}
}
%end
%hook IGMainAppHeaderView
- (void)didMoveToWindow {
%orig;
static dispatch_once_t once;
dispatch_once(&once, ^{
id logoButton = [self valueForKey:@"_logoButton"];
UILongPressGestureRecognizer *longGestureRecognizer =
[[UILongPressGestureRecognizer alloc] initWithTarget: self
action: @selector(didLongPressLogoButton:)];
[logoButton addGestureRecognizer: longGestureRecognizer];
});
}
%new
- (void)didLongPressLogoButton:(id)sender {
IPSettingsViewController *settingsVC =
[[IPSettingsViewController alloc] initWithNibName: nil bundle: nil];
UINavigationController *navigationController =
[[UINavigationController alloc] initWithRootViewController: settingsVC];
UIViewController *rootVC =
[[[UIApplication sharedApplication] keyWindow] rootViewController];
[rootVC presentViewController: navigationController animated: YES completion: nil];
}
%end
%hook IGStoryFullscreenSectionController
- (void)_markItemAsSeen {
if (!HAS_FEATURE(SeeStoriesAsJohnCena)) { %orig; }
}
%end
%hook IGDirectThreadLastSeenMessageTracker
- (void)beginTracking {
if (!HAS_FEATURE(SeeDirectMessagesAsJohnCena)) { %orig; }
}
%end
%hook Appirater
- (void)showRatingAlert { }
%end
%hook IGMainAppScrollingContainerViewController
- (BOOL)gestureRecognizerShouldBegin:(id)gestureRecognizer {
return %orig && HAS_FEATURE(MainFeedSideScrolling);
}
%end
%hook IGActionSheetConfiguration
+ (void)_configureActionSheetShareOptionsWithButtons:(id)arg1 feedItem:(id)arg2 userSession:(id)arg3 {
// TODO: Keep me for future reference
%orig;
}
%end
%hook IGStoryViewerViewController
- (void)fullscreenSectionControllerDidLongPress:(id)arg1 {
%orig;
id focusedViewModel = [self valueForKey:@"_focusedModelItem"];
if (HAS_FEATURE(DownloadStory) && ![focusedViewModel isLive]) {
[self performSelector:@selector(_downloadStory)];
}
}
%new
- (void)_downloadStory {
id storyVC = topMostVC();
IGFeedItem *currentStoryItem = [storyVC currentStoryItem];
IPPostType postType = IPPostTypeVideo;
NSURL *url = [currentStoryItem highestResolutionVideoURL];
if (!url) { url = [currentStoryItem highestResolutionPhotoURL]; postType = IPPostTypePhoto; }
if (url) {
[[IPDownloader sharedInstance] downloadPost:postType
withURL:url
completion: ^(NSError *error){
if (error) {
[[UIAlertController errorAlertForError:error] showOnViewController:topMostVC()];
} else {
[[UIAlertController localizedAlertWithTitle:@"generic.success"
message: @"alert.success.story_downloaded"] showOnViewController:topMostVC()];
}
}];
}
}
%end