-
Notifications
You must be signed in to change notification settings - Fork 17
/
Tweak.x
195 lines (143 loc) · 5.26 KB
/
Tweak.x
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
#import <YouTubeHeader/_ASDisplayView.h>
#import <YouTubeHeader/YTIElementRenderer.h>
#import <YouTubeHeader/YTInnerTubeCollectionViewController.h>
#import <YouTubeHeader/YTISectionListRenderer.h>
#import <YouTubeHeader/YTReelModel.h>
#import <HBLog.h>
%hook YTVersionUtils
// Works down to 16.29.4
+ (NSString *)appVersion {
NSString *appVersion = %orig;
if ([appVersion compare:@"17.33.2" options:NSNumericSearch] == NSOrderedAscending)
return @"17.33.2";
return appVersion;
}
%end
%hook YTGlobalConfig
- (BOOL)shouldBlockUpgradeDialog { return YES; }
%end
%hook YTIPlayerResponse
- (BOOL)isMonetized { return NO; }
%new(@@:)
- (NSMutableArray *)playerAdsArray {
return [NSMutableArray array];
}
%new(@@:)
- (NSMutableArray *)adSlotsArray {
return [NSMutableArray array];
}
%end
%hook YTIPlayabilityStatus
- (BOOL)isPlayableInBackground { return YES; }
%end
%hook YTIClientMdxGlobalConfig
%new(B@:)
- (BOOL)enableSkippableAd { return YES; }
%end
%hook MLVideo
- (BOOL)playableInBackground { return YES; }
%end
%hook YTAdShieldUtils
+ (id)spamSignalsDictionary { return @{}; }
+ (id)spamSignalsDictionaryWithoutIDFA { return @{}; }
%end
%hook YTDataUtils
+ (id)spamSignalsDictionary { return @{}; }
+ (id)spamSignalsDictionaryWithoutIDFA { return @{}; }
%end
%hook YTAdsInnerTubeContextDecorator
- (void)decorateContext:(id)context { %orig(nil); }
%end
%hook YTAccountScopedAdsInnerTubeContextDecorator
- (void)decorateContext:(id)context { %orig(nil); }
%end
%hook YTLocalPlaybackController
- (id)createAdsPlaybackCoordinator { return nil; }
%end
%hook MDXSession
- (void)adPlaying:(id)ad {}
%end
%hook YTReelInfinitePlaybackDataSource
- (YTReelModel *)makeContentModelForEntry:(id)entry {
YTReelModel *model = %orig;
if ([model respondsToSelector:@selector(videoType)] && model.videoType == 3)
return nil;
return model;
}
%end
NSString *getAdString(NSString *description) {
for (NSString *str in @[
@"brand_promo",
@"carousel_footered_layout",
@"carousel_headered_layout",
@"eml.expandable_metadata",
@"feed_ad_metadata",
@"full_width_portrait_image_layout",
@"full_width_square_image_layout",
@"landscape_image_wide_button_layout",
@"post_shelf",
@"product_carousel",
@"product_engagement_panel",
@"product_item",
@"shopping_carousel",
@"shopping_item_card_list",
@"statement_banner",
@"square_image_layout",
@"text_image_button_layout",
@"text_search_ad",
@"video_display_full_layout",
@"video_display_full_buttoned_layout"
])
if ([description containsString:str]) return str;
return nil;
}
static BOOL isAdRenderer(YTIElementRenderer *elementRenderer, int kind) {
if ([elementRenderer respondsToSelector:@selector(hasCompatibilityOptions)] && elementRenderer.hasCompatibilityOptions && elementRenderer.compatibilityOptions.hasAdLoggingData) {
HBLogDebug(@"YTX adLogging %d %@", kind, elementRenderer);
return YES;
}
NSString *description = [elementRenderer description];
NSString *adString = getAdString(description);
if (adString) {
HBLogDebug(@"YTX getAdString %d %@ %@", kind, adString, elementRenderer);
return YES;
}
return NO;
}
static NSMutableArray <YTIItemSectionRenderer *> *filteredArray(NSArray <YTIItemSectionRenderer *> *array) {
NSMutableArray <YTIItemSectionRenderer *> *newArray = [array mutableCopy];
NSIndexSet *removeIndexes = [newArray indexesOfObjectsPassingTest:^BOOL(YTIItemSectionRenderer *sectionRenderer, NSUInteger idx, BOOL *stop) {
if (![sectionRenderer isKindOfClass:%c(YTIItemSectionRenderer)])
return NO;
NSMutableArray <YTIItemSectionSupportedRenderers *> *contentsArray = sectionRenderer.contentsArray;
if (contentsArray.count > 1) {
NSIndexSet *removeContentsArrayIndexes = [contentsArray indexesOfObjectsPassingTest:^BOOL(YTIItemSectionSupportedRenderers *sectionSupportedRenderers, NSUInteger idx2, BOOL *stop2) {
YTIElementRenderer *elementRenderer = sectionSupportedRenderers.elementRenderer;
return isAdRenderer(elementRenderer, 3);
}];
[contentsArray removeObjectsAtIndexes:removeContentsArrayIndexes];
}
YTIItemSectionSupportedRenderers *firstObject = [contentsArray firstObject];
YTIElementRenderer *elementRenderer = firstObject.elementRenderer;
return isAdRenderer(elementRenderer, 2);
}];
[newArray removeObjectsAtIndexes:removeIndexes];
return newArray;
}
%hook _ASDisplayView
- (void)didMoveToWindow {
%orig;
if (([self.accessibilityIdentifier isEqualToString:@"eml.expandable_metadata.vpp"]))
[self removeFromSuperview];
}
%end
%hook YTInnerTubeCollectionViewController
- (void)displaySectionsWithReloadingSectionControllerByRenderer:(id)renderer {
NSMutableArray *sectionRenderers = [self valueForKey:@"_sectionRenderers"];
[self setValue:filteredArray(sectionRenderers) forKey:@"_sectionRenderers"];
%orig;
}
- (void)addSectionsFromArray:(NSArray <YTIItemSectionRenderer *> *)array {
%orig(filteredArray(array));
}
%end