Skip to content
This repository was archived by the owner on Oct 9, 2023. It is now read-only.

Commit a7cd88e

Browse files
committed
Block ads in video feed view, get video playback item better, fix hide stories for who has room chat on news feed
1 parent e8b43e3 commit a7cd88e

8 files changed

Lines changed: 75 additions & 16 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ make do
3737

3838
Contributions of any kind welcome!
3939

40+
## Copyright Notice
41+
42+
The "Remove Ads" function is based on [FBSpNOsor](https://github.com/jacobcxdev/FBSpNOsor) by [jacobcxdev](https://github.com/jacobcxdev).
43+
4044
## License
4145

4246
Licensed under the [GPLv3 License](./LICENSE), Copyright © 2020-present Hao Nguyen <hao.ict56@gmail.com>

Tweak.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44
#define PLIST_PATH "/var/mobile/Library/Preferences/com.haoict.facebooknoadspref.plist"
55
#define PREF_CHANGED_NOTIF "com.haoict.facebooknoadspref/PrefChanged"
66

7+
@interface FBMemNewsFeedEdge : NSObject
8+
- (id)category;
9+
@end;
10+
11+
@interface FBMemFeedStory : NSObject
12+
- (id)sponsoredData;
13+
@end
14+
15+
@interface FBVideoChannelPlaylistItem : NSObject
16+
- (BOOL)isSponsored;
17+
@end
18+
719
@interface CKDataSourceState : NSObject
820
@property(readonly, copy, nonatomic) NSArray *sections;
921
@end

Tweak.xm

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
BOOL noads;
77
BOOL canSaveVideo;
88
BOOL hideNewsFeedComposer;
9-
BOOL hideNewsFeedRoom;
109
BOOL hideNewsFeedStories;
1110

1211
static void reloadPrefs() {
@@ -15,14 +14,29 @@ static void reloadPrefs() {
1514
noads = [[settings objectForKey:@"noads"] ?: @(YES) boolValue];
1615
canSaveVideo = [[settings objectForKey:@"canSaveVideo"] ?: @(YES) boolValue];
1716
hideNewsFeedComposer = [[settings objectForKey:@"hideNewsFeedComposer"] ?: @(NO) boolValue];
18-
hideNewsFeedRoom = [[settings objectForKey:@"hideNewsFeedRoom"] ?: @(NO) boolValue];
1917
hideNewsFeedStories = [[settings objectForKey:@"hideNewsFeedStories"] ?: @(NO) boolValue];
2018
}
2119

2220
%group NoAds
23-
%hook FBMemSponsoredData
21+
%hook FBMemNewsFeedEdge
2422
- (id)initWithFBTree:(void *)arg1 {
25-
return nil;
23+
id orig = %orig;
24+
id category = [orig category];
25+
return category ? [category isEqualToString:@"ORGANIC"] ? orig : nil : orig;
26+
}
27+
%end
28+
29+
%hook FBMemFeedStory
30+
- (id)initWithFBTree:(void *)arg1 {
31+
id orig = %orig;
32+
return [orig sponsoredData] == nil ? orig : nil;
33+
}
34+
%end
35+
36+
%hook FBVideoChannelPlaylistItem
37+
- (id)Bi:(id)arg1 :(id)arg2 :(id)arg3 :(id)arg4 :(id)arg5 :(id)arg6 :(id)arg7 {
38+
id orig = %orig;
39+
return [orig isSponsored] ? nil : orig;
2640
}
2741
%end
2842
%end
@@ -67,11 +81,11 @@ static void reloadPrefs() {
6781
%new
6882
- (BOOL)shouldHideSectionNumber:(int)sectionNumber {
6983
if (hideNewsFeedComposer) {
70-
if (sectionNumber == 0) {
84+
if (([self dataSourceState].sections.count == 3 && sectionNumber == 0) || ([self dataSourceState].sections.count == 4 && sectionNumber == 1)) {
7185
return TRUE;
7286
}
7387
} else {
74-
if (sectionNumber == 1) {
88+
if (([self dataSourceState].sections.count == 4 && sectionNumber == 1) || ([self dataSourceState].sections.count == 5 && sectionNumber == 2)) {
7589
return TRUE;
7690
}
7791
}
@@ -98,11 +112,17 @@ static void reloadPrefs() {
98112
%new
99113
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender {
100114
if (sender.state == UIGestureRecognizerStateBegan) {
115+
FBVideoPlaybackItem *videoPlaybackItem = [self.controller currentVideoPlaybackItem];
116+
if (!videoPlaybackItem) {
117+
[HCommon showAlertMessage:@"Can't find Video source, please report to developer" withTitle:@"Error" viewController:nil];
118+
return;
119+
}
120+
101121
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
102122
[alert addAction:[UIAlertAction actionWithTitle:@"Download Video" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
103-
NSURL *videoURL = [self.controller currentVideoPlaybackItem].HDPlaybackURL;
123+
NSURL *videoURL = videoPlaybackItem.HDPlaybackURL;
104124
if (!videoURL) {
105-
videoURL = [self.controller currentVideoPlaybackItem].SDPlaybackURL;
125+
videoURL = videoPlaybackItem.SDPlaybackURL;
106126
}
107127
NSString *videoURLString = videoURL.absoluteString;
108128
[HCommon showToastMessage:@"Downloading in background..." withTitle:@"Please wait" timeout:1.0 viewController:nil];
@@ -133,15 +153,36 @@ static void reloadPrefs() {
133153
if (sender.state == UIGestureRecognizerStateBegan) {
134154
UIView *view = self.superview.superview.superview.superview;
135155
if (![view isKindOfClass:%c(VideoContainerView)]) {
136-
view = self.superview.subviews[1].subviews[0].subviews[0];
156+
@try {
157+
view = self.superview.subviews[1].subviews[0].subviews[0];
158+
} @catch (NSException *exception) { }
159+
}
160+
if (![view isKindOfClass:%c(VideoContainerView)]) {
161+
@try {
162+
view = self.superview.subviews[2].subviews[0].subviews[0];
163+
} @catch (NSException *exception) { }
164+
}
165+
if (![view isKindOfClass:%c(VideoContainerView)]) {
166+
@try {
167+
view = self.superview.subviews[3].subviews[0].subviews[0];
168+
} @catch (NSException *exception) { }
169+
}
170+
if (![view isKindOfClass:%c(VideoContainerView)]) {
171+
[HCommon showAlertMessage:@"Can't find Video container, please report to developer" withTitle:@"Error" viewController:nil];
172+
return;
137173
}
138174
VideoContainerView *videoContainerView = (VideoContainerView *)view;
175+
FBVideoPlaybackItem *videoPlaybackItem = [videoContainerView.controller currentVideoPlaybackItem];
176+
if (!videoPlaybackItem) {
177+
[HCommon showAlertMessage:@"Can't find Video source, please report to developer" withTitle:@"Error" viewController:nil];
178+
return;
179+
}
139180

140181
UIAlertController* alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? UIAlertControllerStyleAlert : UIAlertControllerStyleActionSheet];
141182
[alert addAction:[UIAlertAction actionWithTitle:@"Download Video" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
142-
NSURL *videoURL = [videoContainerView.controller currentVideoPlaybackItem].HDPlaybackURL;
183+
NSURL *videoURL = videoPlaybackItem.HDPlaybackURL;
143184
if (!videoURL) {
144-
videoURL = [videoContainerView.controller currentVideoPlaybackItem].SDPlaybackURL;
185+
videoURL = videoPlaybackItem.SDPlaybackURL;
145186
}
146187
NSString *videoURLString = videoURL.absoluteString;
147188
[HCommon showToastMessage:@"Downloading in background..." withTitle:@"Please wait" timeout:1.0 viewController:nil];
@@ -170,7 +211,7 @@ static void reloadPrefs() {
170211
%init(HideNewsFeedComposer);
171212
}
172213

173-
if (hideNewsFeedRoom || hideNewsFeedStories) {
214+
if (hideNewsFeedStories) {
174215
%init(HideNewsFeedChatRoomStories);
175216
}
176217
}

control

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: com.haoict.facebooknoads
22
Name: Facebook No Ads
33
Depends: mobilesubstrate, preferenceloader, com.haoict.libhdev (>= 2.0.0), firmware (>= 10)
4-
Version: 1.0.0
4+
Version: 1.0.2
55
Architecture: iphoneos-arm
66
Description: Free & Open Source Tweak for Facebook
77
Free & Open Source Tweak for Facebook
@@ -15,6 +15,8 @@ Description: Free & Open Source Tweak for Facebook
1515
- Support iOS 10 (not tested) - 11 (tested) - 12 (tested) - 13 (tested)
1616
- Support latest Facebook version (If it doesn't work, you should update the app to latest version >= 260.0)
1717
.
18+
I collect uuid for better support and statistic purpose
19+
.
1820
I work very hard to make good, free and open source tweaks for everyone
1921
If you want to support, you can buy me a coffee at https://www.paypal.me/haoict
2022
.

pref/Resources/base.lproj/Root.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"LONG_PRESS_ON_VIDEO_TO_SAVE" = "Long press on video to save";
1212
"HIDE_COMPOSER" = "Hide Composer";
1313
"HIDE_COMPOSER_ON_NEWS_FEED" = "Hide Composer on News Feed";
14-
"HIDE_STORIES" = "Hide Stories";
14+
"HIDE_STORIES" = "Hide Stories (beta)";
1515
"HIDE_STORIES_ON_NEWS_FEED" = "Hide Stories on News Feed";
1616
"OTHER_PREFERENCES" = "Other Preferences";
1717
"RESET_SETTINGS" = "Reset Settings";

pref/Resources/en.lproj/Root.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"LONG_PRESS_ON_VIDEO_TO_SAVE" = "Long press on video to save";
1212
"HIDE_COMPOSER" = "Hide Composer";
1313
"HIDE_COMPOSER_ON_NEWS_FEED" = "Hide Composer on News Feed";
14-
"HIDE_STORIES" = "Hide Stories";
14+
"HIDE_STORIES" = "Hide Stories (beta)";
1515
"HIDE_STORIES_ON_NEWS_FEED" = "Hide Stories on News Feed";
1616
"OTHER_PREFERENCES" = "Other Preferences";
1717
"RESET_SETTINGS" = "Reset Settings";

pref/Resources/vi.lproj/Root.strings

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"LONG_PRESS_ON_VIDEO_TO_SAVE" = "Ấn và giữ video để lưu";
1212
"HIDE_COMPOSER" = "Ẩn Bạn đang nghĩ gì";
1313
"HIDE_COMPOSER_ON_NEWS_FEED" = "Ẩn Bạn đang nghĩ gì ở Bảng tin";
14-
"HIDE_STORIES" = "Ẩn Story";
14+
"HIDE_STORIES" = "Ẩn Story (beta)";
1515
"HIDE_STORIES_ON_NEWS_FEED" = "Ẩn Story ở Bảng tin";
1616
"OTHER_PREFERENCES" = "Tùy chỉnh phụ";
1717
"RESET_SETTINGS" = "Đặt lại tùy chỉnh";
247 KB
Binary file not shown.

0 commit comments

Comments
 (0)