mirror of
https://github.com/arichornlover/uYouEnhanced.git
synced 2026-04-21 16:02:00 +00:00
Make changes persist with page refresh
This commit is contained in:
parent
12c6c4fb5a
commit
4a02d265eb
2 changed files with 34 additions and 16 deletions
|
|
@ -100,6 +100,7 @@
|
||||||
- (bool)hasCompactListItemRenderer;
|
- (bool)hasCompactListItemRenderer;
|
||||||
@end
|
@end
|
||||||
@interface YTAppCollectionViewController : YTInnerTubeCollectionViewController
|
@interface YTAppCollectionViewController : YTInnerTubeCollectionViewController
|
||||||
|
- (void)uYouEnhancedFakePremiumModel:(YTISectionListRenderer *)model;
|
||||||
@end
|
@end
|
||||||
@interface YTInnerTubeCollectionViewController (uYouEnhanced)
|
@interface YTInnerTubeCollectionViewController (uYouEnhanced)
|
||||||
@property(readonly, nonatomic) YTISectionListRenderer *model;
|
@property(readonly, nonatomic) YTISectionListRenderer *model;
|
||||||
|
|
|
||||||
|
|
@ -316,8 +316,16 @@ BOOL isAd(YTIElementRenderer *self) {
|
||||||
// Fake premium in the You tab - @bhackel
|
// Fake premium in the You tab - @bhackel
|
||||||
%group gYouTabFakePremium
|
%group gYouTabFakePremium
|
||||||
%hook YTAppCollectionViewController
|
%hook YTAppCollectionViewController
|
||||||
- (void)loadWithModel:(YTISectionListRenderer *)model {
|
/**
|
||||||
NSUInteger yourVideosIndex = -1;
|
* Modify a given renderer data model to fake premium in the You tab
|
||||||
|
* Replaces the "Get YouTube Premium" cell with a "Your Premium benefits" cell
|
||||||
|
* and adds a "Downloads" cell below the "Your videos" cell
|
||||||
|
* @param model The model for the You tab
|
||||||
|
* TODO Add localization support for the Get Youtube Premium and Downloads text
|
||||||
|
*/
|
||||||
|
%new
|
||||||
|
- (void)uYouEnhancedFakePremiumModel:(YTISectionListRenderer *)model {
|
||||||
|
NSUInteger yourVideosCellIndex = -1;
|
||||||
NSMutableArray <YTISectionListSupportedRenderers *> *overallContentsArray = model.contentsArray;
|
NSMutableArray <YTISectionListSupportedRenderers *> *overallContentsArray = model.contentsArray;
|
||||||
// Check each item in the overall array - this represents the whole You page
|
// Check each item in the overall array - this represents the whole You page
|
||||||
YTISectionListSupportedRenderers *supportedRenderers;
|
YTISectionListSupportedRenderers *supportedRenderers;
|
||||||
|
|
@ -327,22 +335,22 @@ BOOL isAd(YTIElementRenderer *self) {
|
||||||
NSMutableArray <YTIItemSectionSupportedRenderers *> *subContentsArray = itemSectionRenderer.contentsArray;
|
NSMutableArray <YTIItemSectionSupportedRenderers *> *subContentsArray = itemSectionRenderer.contentsArray;
|
||||||
YTIItemSectionSupportedRenderers *itemSectionSupportedRenderers;
|
YTIItemSectionSupportedRenderers *itemSectionSupportedRenderers;
|
||||||
for (itemSectionSupportedRenderers in subContentsArray) {
|
for (itemSectionSupportedRenderers in subContentsArray) {
|
||||||
// Check for a specific type of cell of type CompactLinkRenderer
|
// Check for Get Youtube Premium cell, which is of type CompactLinkRenderer
|
||||||
if ([itemSectionSupportedRenderers hasCompactLinkRenderer]) {
|
if ([itemSectionSupportedRenderers hasCompactLinkRenderer]) {
|
||||||
YTICompactLinkRenderer *compactLinkRenderer = [itemSectionSupportedRenderers compactLinkRenderer];
|
YTICompactLinkRenderer *compactLinkRenderer = [itemSectionSupportedRenderers compactLinkRenderer];
|
||||||
// Check for an icon in this cell
|
// Check for an icon in this cell
|
||||||
if ([compactLinkRenderer hasIcon]) {
|
if ([compactLinkRenderer hasIcon]) {
|
||||||
YTIIcon *icon = [compactLinkRenderer icon];
|
YTIIcon *icon = [compactLinkRenderer icon];
|
||||||
// Check if the icon is for the premium promo
|
// Check if the icon is for the premium advertisement - 117 is magic number for the icon
|
||||||
if ([icon hasIconType] && icon.iconType == 117) {
|
if ([icon hasIconType] && icon.iconType == 117) {
|
||||||
// Modify the icon type to be Premium
|
// Modify the icon type to be Premium
|
||||||
icon.iconType = 741;
|
icon.iconType = 741; // Magic number for premium icon
|
||||||
// Modify the text
|
// Modify the text
|
||||||
((YTIStringRun *)(compactLinkRenderer.title.runsArray.firstObject)).text = @"Your Premium benefits";
|
((YTIStringRun *)(compactLinkRenderer.title.runsArray.firstObject)).text = @"Your Premium benefits";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check for a specific type of cell of type CompactListItemRenderer
|
// Check for Your Videos cell using similar logic explained above
|
||||||
if ([itemSectionSupportedRenderers hasCompactListItemRenderer]) {
|
if ([itemSectionSupportedRenderers hasCompactListItemRenderer]) {
|
||||||
YTICompactListItemRenderer *compactListItemRenderer = itemSectionSupportedRenderers.compactListItemRenderer;
|
YTICompactListItemRenderer *compactListItemRenderer = itemSectionSupportedRenderers.compactListItemRenderer;
|
||||||
if ([compactListItemRenderer hasThumbnail]) {
|
if ([compactListItemRenderer hasThumbnail]) {
|
||||||
|
|
@ -352,26 +360,35 @@ BOOL isAd(YTIElementRenderer *self) {
|
||||||
if ([iconThumbnailRenderer hasIcon]) {
|
if ([iconThumbnailRenderer hasIcon]) {
|
||||||
YTIIcon *icon = iconThumbnailRenderer.icon;
|
YTIIcon *icon = iconThumbnailRenderer.icon;
|
||||||
if ([icon hasIconType] && icon.iconType == 658) {
|
if ([icon hasIconType] && icon.iconType == 658) {
|
||||||
// Note the index of this cell in the array
|
// Store the index of this cell
|
||||||
yourVideosIndex = [subContentsArray indexOfObject:itemSectionSupportedRenderers];
|
yourVideosCellIndex = [subContentsArray indexOfObject:itemSectionSupportedRenderers];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (yourVideosIndex != -1) {
|
if (yourVideosCellIndex != -1) {
|
||||||
// Create a new cell with the same properties as the original cell
|
// Create the fake Downloads page by copying the Your Videos page and modifying it
|
||||||
YTIItemSectionSupportedRenderers *newItemSectionSupportedRenderers = [subContentsArray[yourVideosIndex] copy];
|
// Note that this must be done outside the loop to avoid a runtime exception
|
||||||
// Modify the text
|
// TODO Link this to the uYou downloads page
|
||||||
|
YTIItemSectionSupportedRenderers *newItemSectionSupportedRenderers = [subContentsArray[yourVideosCellIndex] copy];
|
||||||
((YTIStringRun *)(newItemSectionSupportedRenderers.compactListItemRenderer.title.runsArray.firstObject)).text = @"Downloads";
|
((YTIStringRun *)(newItemSectionSupportedRenderers.compactListItemRenderer.title.runsArray.firstObject)).text = @"Downloads";
|
||||||
// Modify the icon
|
|
||||||
newItemSectionSupportedRenderers.compactListItemRenderer.thumbnail.iconThumbnailRenderer.icon.iconType = 147;
|
newItemSectionSupportedRenderers.compactListItemRenderer.thumbnail.iconThumbnailRenderer.icon.iconType = 147;
|
||||||
// Insert the new cell at the index of the original cell
|
// Insert this cell after the Your Videos cell
|
||||||
[subContentsArray insertObject:newItemSectionSupportedRenderers atIndex:yourVideosIndex + 1];
|
[subContentsArray insertObject:newItemSectionSupportedRenderers atIndex:yourVideosCellIndex + 1];
|
||||||
yourVideosIndex = -1;
|
yourVideosCellIndex = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
- (void)loadWithModel:(YTISectionListRenderer *)model {
|
||||||
|
// This method is called on first load of the You page
|
||||||
|
[self uYouEnhancedFakePremiumModel:model];
|
||||||
|
%orig;
|
||||||
|
}
|
||||||
|
- (void)setupSectionListWithModel:(YTISectionListRenderer *)model isLoadingMore:(BOOL)isLoadingMore isRefreshingFromContinuation:(BOOL)isRefreshingFromContinuation {
|
||||||
|
// This method is called on refresh of the You page
|
||||||
|
[self uYouEnhancedFakePremiumModel:model];
|
||||||
%orig;
|
%orig;
|
||||||
}
|
}
|
||||||
%end
|
%end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue