forked from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reddit):
layout-reddit-ads
patch
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/kotlin/app/revanced/patches/reddit/ad/layout/annotations/LayoutAdsCompatibility.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package app.revanced.patches.reddit.ad.layout.annotations | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
|
||
@Compatibility( | ||
[Package( | ||
"com.reddit.frontpage", arrayOf("2023.05.0") | ||
)] | ||
) | ||
@Target(AnnotationTarget.CLASS) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
internal annotation class LayoutAdsCompatibility |
43 changes: 43 additions & 0 deletions
43
src/main/kotlin/app/revanced/patches/reddit/ad/layout/patch/LayoutAdsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package app.revanced.patches.reddit.ad.layout.patch | ||
|
||
import app.revanced.patcher.annotation.Description | ||
import app.revanced.patcher.annotation.Name | ||
import app.revanced.patcher.annotation.Version | ||
import app.revanced.patcher.data.ResourceContext | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patcher.patch.ResourcePatch | ||
import app.revanced.patcher.patch.annotations.Patch | ||
import app.revanced.patches.reddit.ad.layout.annotations.LayoutAdsCompatibility | ||
|
||
@Patch | ||
@Name("layout-reddit-ads") | ||
@Description("Removes layout ads from the Reddit frontpage and subreddits.") | ||
@LayoutAdsCompatibility | ||
@Version("0.0.1") | ||
class LayoutAdsPatch : ResourcePatch { | ||
override fun execute(context: ResourceContext): PatchResult { | ||
arrayOf( | ||
"height", | ||
"width" | ||
).forEach { replacements -> | ||
context.xmlEditor[RESOURCE_FILE_PATH].use { | ||
val children = it.file.getElementsByTagName("merge").item(0).childNodes | ||
|
||
for (i in 1 until children.length) { | ||
val view = children.item(i) | ||
if (!(view.hasAttributes() && view.attributes.getNamedItem("android:id").nodeValue.endsWith("ad_view_stub"))) continue | ||
view.attributes.getNamedItem("android:layout_$replacements").nodeValue = "0.0dip" | ||
break | ||
} | ||
} | ||
} | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
private companion object { | ||
const val RESOURCE_FILE_PATH = "res/layout/merge_listheader_link_detail.xml" | ||
} | ||
} | ||
|
5816679
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If someone wants to use this to leave a PR on the official repo, feel free to use it as is.
(because this fork repo is under the GPL v3)
If you do, please add some code comments or minor fixes.
5816679
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OMG :)