-
Notifications
You must be signed in to change notification settings - Fork 13
/
Tweak.x
186 lines (141 loc) · 5.85 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
#import <YouTubeHeader/YTIElementRenderer.h>
#import <YouTubeHeader/YTInnerTubeCollectionViewController.h>
#import <YouTubeHeader/YTISectionListRenderer.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
NSString *getAdString(NSString *description) {
if ([description containsString:@"brand_promo"])
return @"brand_promo";
if ([description containsString:@"carousel_footered_layout"])
return @"carousel_footered_layout";
if ([description containsString:@"carousel_headered_layout"])
return @"carousel_headered_layout";
if ([description containsString:@"feed_ad_metadata"])
return @"feed_ad_metadata";
if ([description containsString:@"full_width_portrait_image_layout"])
return @"full_width_portrait_image_layout";
if ([description containsString:@"full_width_square_image_layout"])
return @"full_width_square_image_layout";
if ([description containsString:@"landscape_image_wide_button_layout"])
return @"landscape_image_wide_button_layout";
if ([description containsString:@"post_shelf"])
return @"post_shelf";
if ([description containsString:@"product_carousel"])
return @"product_carousel";
if ([description containsString:@"product_engagement_panel"])
return @"product_engagement_panel";
if ([description containsString:@"product_item"])
return @"product_item";
if ([description containsString:@"shopping_carousel"])
return @"shopping_carousel";
if ([description containsString:@"shopping_item_card_list"])
return @"shopping_item_card_list";
if ([description containsString:@"statement_banner"])
return @"statement_banner";
if ([description containsString:@"square_image_layout"])
return @"square_image_layout";
if ([description containsString:@"text_image_button_layout"])
return @"text_image_button_layout";
if ([description containsString:@"text_search_ad"])
return @"text_search_ad";
if ([description containsString:@"video_display_full_layout"])
return @"video_display_full_layout";
if ([description containsString:@"video_display_full_buttoned_layout"])
return @"video_display_full_buttoned_layout";
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 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