This repository was archived by the owner on Oct 9, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathTweak.xm
More file actions
324 lines (284 loc) · 13.2 KB
/
Tweak.xm
File metadata and controls
324 lines (284 loc) · 13.2 KB
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#import "Tweak.h"
/**
* Load Preferences
*/
BOOL noads;
BOOL canSaveVideo;
BOOL canSaveStory;
BOOL canSaveOnlyMeProfilePicture;
BOOL disableStorySeen;
BOOL hideNewsFeedComposer;
BOOL hideNewsFeedStories;
static void reloadPrefs() {
NSDictionary *settings = [[NSMutableDictionary alloc] initWithContentsOfFile:@PLIST_PATH] ?: [@{} mutableCopy];
noads = [[settings objectForKey:@"noads"] ?: @(YES) boolValue];
canSaveVideo = [[settings objectForKey:@"canSaveVideo"] ?: @(YES) boolValue];
canSaveStory = [[settings objectForKey:@"canSaveStory"] ?: @(YES) boolValue];
canSaveOnlyMeProfilePicture = [[settings objectForKey:@"canSaveOnlyMeProfilePicture"] ?: @(YES) boolValue];
disableStorySeen = [[settings objectForKey:@"disableStorySeen"] ?: @(YES) boolValue];
hideNewsFeedComposer = [[settings objectForKey:@"hideNewsFeedComposer"] ?: @(NO) boolValue];
hideNewsFeedStories = [[settings objectForKey:@"hideNewsFeedStories"] ?: @(NO) boolValue];
}
static void showDownloadVideoAlert(NSURL *HDPlaybackURL, NSURL *SDPlaybackURL, UIViewController *viewController) {
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:IS_iPAD ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
[alert addAction:[UIAlertAction actionWithTitle:@"Download Video - HD" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSURL *videoURL = HDPlaybackURL;
if (!videoURL) {
[HCommon showAlertMessage:@"This video doesn't have HD quality, please select other quality" withTitle:@"No HD quality" viewController:viewController];
return;
}
NSString *videoURLString = videoURL.absoluteString;
[[[HDownloadMediaWithProgress alloc] init] checkPermissionToPhotosAndDownload:videoURLString appendExtension:nil mediaType:Video toAlbum:@"Facebook" viewController:viewController];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Download Video - SD" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSURL *videoURL = SDPlaybackURL;
if (!videoURL) {
[HCommon showAlertMessage:@"This video doesn't have SD quality, please select other quality" withTitle:@"No SD quality" viewController:viewController];
return;
}
NSString *videoURLString = videoURL.absoluteString;
[[[HDownloadMediaWithProgress alloc] init] checkPermissionToPhotosAndDownload:videoURLString appendExtension:nil mediaType:Video toAlbum:@"Facebook" viewController:viewController];
}]];
[alert addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:nil]];
[viewController presentViewController:alert animated:YES completion:nil];
}
%group NoAds
%hook FBMemNewsFeedEdge
- (id)initWithFBTree:(void *)arg1 {
id orig = %orig;
id category = [orig category];
return category ? [category isEqualToString:@"ORGANIC"] ? orig : nil : orig;
}
%end
%hook FBMemFeedStory
- (id)initWithFBTree:(void *)arg1 {
id orig = %orig;
return [orig sponsoredData] == nil ? orig : nil;
}
%end
%hook FBVideoChannelPlaylistItem
- (id)Bi:(id)arg1 :(id)arg2 :(id)arg3 :(id)arg4 :(id)arg5 :(id)arg6 :(id)arg7 {
id orig = %orig;
return [orig isSponsored] ? nil : orig;
}
%end
%end
%group HideNewsFeedComposer
%hook FBNewsFeedViewControllerConfiguration
- (BOOL)shouldHideComposer {
return TRUE;
}
%end
%end
%group HideNewsFeedChatRoomStories
%hook FBComponentCollectionViewDataSource
- (id)collectionView:(id)arg1 cellForItemAtIndexPath:(NSIndexPath *)arg2 {
id orig = %orig;
if (![arg1 isKindOfClass:%c(FBNewsFeedCollectionView)]) {
return orig;
}
if ([self shouldHideSectionNumber:arg2.section]) {
[orig setHidden: YES];
} else {
[orig setHidden: NO];
}
return orig;
}
- (CGSize)collectionView:(id)arg1 layout:(id)arg2 sizeForItemAtIndexPath:(NSIndexPath *)arg3 {
CGSize orig = %orig;
if (![arg1 isKindOfClass:%c(FBNewsFeedCollectionView)]) {
return orig;
}
if ([self shouldHideSectionNumber:arg3.section]) {
orig.height = 1;
orig.width = 1;
}
return orig;
}
%new
- (BOOL)shouldHideSectionNumber:(int)sectionNumber {
if (hideNewsFeedComposer) {
if (([self dataSourceState].sections.count == 3 && sectionNumber == 0) || ([self dataSourceState].sections.count == 4 && (sectionNumber == 0 || sectionNumber == 1))) {
return TRUE;
}
} else {
if (([self dataSourceState].sections.count == 4 && sectionNumber == 1) || ([self dataSourceState].sections.count == 5 && (sectionNumber == 1 || sectionNumber == 2))) {
return TRUE;
}
}
return FALSE;
}
%end
%end
%group CanSaveVideo
%hook VideoContainerView
- (id)syc:(CGRect)arg1:(id)arg2 {
id orig = %orig;
[orig addHandleLongPress];
return orig;
}
- (id)nyc:(CGRect)arg1:(id)arg2 {
id orig = %orig;
[orig addHandleLongPress];
return orig;
}
%new
- (void)addHandleLongPress {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 0.5;
[self addGestureRecognizer:longPress];
}
%new
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
FBVideoPlaybackItem *videoPlaybackItem = [self.controller currentVideoPlaybackItem];
if (!videoPlaybackItem) {
[HCommon showAlertMessage:@"Can't find Video source, please report to developer" withTitle:@"Error" viewController:nil];
return;
}
showDownloadVideoAlert(videoPlaybackItem.HDPlaybackURL, videoPlaybackItem.SDPlaybackURL, [self reactViewController]);
}
}
%end
%hook FBVideoOverlayPluginComponentBackgroundView
- (id)initWithFrame:(struct CGRect)arg1 {
id orig = %orig;
[orig addHandleLongPress];
return orig;
}
%new
- (void)addHandleLongPress {
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 0.5;
[self addGestureRecognizer:longPress];
}
%new
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender {
if (sender.state == UIGestureRecognizerStateBegan) {
UIView *view = self.superview.superview.superview.superview;
if (![view isKindOfClass:%c(VideoContainerView)]) {
@try {
view = self.superview.subviews[1].subviews[0].subviews[0];
} @catch (NSException *exception) { }
}
if (![view isKindOfClass:%c(VideoContainerView)]) {
@try {
view = self.superview.subviews[2].subviews[0].subviews[0];
} @catch (NSException *exception) { }
}
if (![view isKindOfClass:%c(VideoContainerView)]) {
@try {
view = self.superview.subviews[3].subviews[0].subviews[0];
} @catch (NSException *exception) { }
}
if (![view isKindOfClass:%c(VideoContainerView)]) {
[HCommon showAlertMessage:@"Can't find Video container, please report to developer" withTitle:@"Error" viewController:nil];
return;
}
VideoContainerView *videoContainerView = (VideoContainerView *)view;
FBVideoPlaybackItem *videoPlaybackItem = [videoContainerView.controller currentVideoPlaybackItem];
if (!videoPlaybackItem) {
[HCommon showAlertMessage:@"Can't find Video source, please report to developer" withTitle:@"Error" viewController:nil];
return;
}
showDownloadVideoAlert(videoPlaybackItem.HDPlaybackURL, videoPlaybackItem.SDPlaybackURL, [self reactViewController]);
}
}
%end
%end
%group CanSaveStory
%hook FBSnacksMediaContainerView
%property (nonatomic, retain) UIButton *hDownloadButton;
- (id)initWithThread:(id)arg1 bucket:(id)arg2 mediaViewDelegate:(id)arg3 mediaViewGenerator:(id *)arg4 toolbox:(id)arg5 {
self = %orig;
self.hDownloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.hDownloadButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
[self.hDownloadButton addTarget:self action:@selector(hDownloadButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.hDownloadButton setBackgroundImage:[UIImage imageWithContentsOfFile:@"/Library/Application Support/facebooknoads/download.png"] forState:UIControlStateNormal];
self.hDownloadButton.frame = IS_iPAD ? CGRectMake([[UIApplication sharedApplication] keyWindow].frame.size.width / 2 + 60, [[UIApplication sharedApplication] keyWindow].frame.size.height - 140.0, 24.0, 24.0) : CGRectMake([[UIApplication sharedApplication] keyWindow].frame.size.width - 40, [[UIApplication sharedApplication] keyWindow].frame.size.height - ([HCommon isNotch] ? 190.0 : 90.0), 24.0, 24.0);
[self addSubview:self.hDownloadButton];
return self;
}
%new
- (void)hDownloadButtonPressed:(UIButton *)sender {
if ([self.mediaView isKindOfClass:%c(FBSnacksPhotoView)]) {
@try {
FBSnacksWebPhotoView *_snacksWebPhotoView = MSHookIvar<FBSnacksWebPhotoView *>(self.mediaView, "_photoView");
FBWebPhotoView *_photoView = MSHookIvar<FBWebPhotoView *>(_snacksWebPhotoView, "_photoView");
id imageSpecifier = _photoView.imageSpecifier;
if ([imageSpecifier isKindOfClass:%c(FBWebImageNetworkSpecifier)]) {
NSURL *url = ((FBWebImageNetworkSpecifier *)imageSpecifier).allInfoURLsSortedByDescImageFlag[0];
[[[HDownloadMediaWithProgress alloc] init] checkPermissionToPhotosAndDownloadURL:url appendExtension:nil mediaType:Image toAlbum:@"Facebook" view:self];
}
else if ([imageSpecifier isKindOfClass:%c(FBWebImageMemorySpecifier)]) {
UIImageWriteToSavedPhotosAlbum(((FBWebImageMemorySpecifier *)imageSpecifier).image, nil, nil, nil);
[HCommon showToastMessage:@"" withTitle:@"Done!" timeout:0.5 viewController:nil];
}
} @catch(NSException *exception) {
[HCommon showAlertMessage:exception.reason withTitle:@"Error" viewController:nil];
}
} else if ([self.mediaView isKindOfClass:%c(FBSnacksNewVideoView)]) {
FBVideoPlaybackItem *videoPlaybackItem = [((FBSnacksNewVideoView *)self.mediaView).manager currentVideoPlaybackItem];
showDownloadVideoAlert(videoPlaybackItem.HDPlaybackURL, videoPlaybackItem.SDPlaybackURL, [self reactViewController]);
} else {
[HCommon showAlertMessage:@"This story has no media to download. Seems like it's a bug. Please report to the developer" withTitle:@"Error" viewController:nil];
}
}
%end
%end
%group CanSaveOnlyMeProfilePicture
%hook FBPhotoViewController
%property (nonatomic, retain) UIButton *hDownloadButton;
- (void)viewDidAppear:(BOOL)arg1 {
%orig;
NSUInteger _actionSheetOptions = MSHookIvar<NSUInteger>(self, "_actionSheetOptions");
if (_actionSheetOptions != 0 || (self.hDownloadButton && [self.hDownloadButton isDescendantOfView:self.view])) {
return;
}
self.hDownloadButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.hDownloadButton.titleLabel setFont:[UIFont systemFontOfSize:15]];
[self.hDownloadButton addTarget:self action:@selector(hDownloadButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
[self.hDownloadButton setBackgroundImage:[UIImage imageWithContentsOfFile:@"/Library/Application Support/facebooknoads/download.png"] forState:UIControlStateNormal];
self.hDownloadButton.frame = CGRectMake([[UIApplication sharedApplication] keyWindow].frame.size.width - 40, [[UIApplication sharedApplication] keyWindow].frame.size.height - ([HCommon isNotch] ? 190.0 : 90.0), 24.0, 24.0);
[self.view addSubview:self.hDownloadButton];
}
%new
- (void)hDownloadButtonPressed:(UIButton *)sender {
UIImageWriteToSavedPhotosAlbum(self.displayedImage, nil, nil, nil);
[HCommon showToastMessage:@"" withTitle:@"Done!" timeout:0.5 viewController:nil];
}
%end
%end
%group DisableStorySeen
%hook FBSnacksBucketsSeenStateManager
- (void)_sendSeenThreadIDsWithBucket:(id)arg1 session:(id)arg2 {
}
%end
%end
%ctor {
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), NULL, (CFNotificationCallback) reloadPrefs, CFSTR(PREF_CHANGED_NOTIF), NULL, CFNotificationSuspensionBehaviorDeliverImmediately);
reloadPrefs();
dlopen([[[NSBundle mainBundle].bundlePath stringByAppendingPathComponent:@"Frameworks/FBSharedDynamicFramework.framework/FBSharedDynamicFramework"] UTF8String], RTLD_NOW);
// dlopen([[[NSBundle mainBundle].bundlePath stringByAppendingPathComponent:@"Frameworks/FBMessagingFramework.framework/FBMessagingFramework"] UTF8String], RTLD_NOW);
if (noads) {
%init(NoAds);
}
if (canSaveVideo) {
%init(CanSaveVideo);
}
if (canSaveStory) {
%init(CanSaveStory);
}
if (canSaveOnlyMeProfilePicture) {
%init(CanSaveOnlyMeProfilePicture);
}
if (disableStorySeen) {
%init(DisableStorySeen);
}
if (hideNewsFeedComposer) {
%init(HideNewsFeedComposer);
}
if (hideNewsFeedStories) {
%init(HideNewsFeedChatRoomStories);
}
}