Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(YouTube/Hide comments components): add Hide highlighted search links setting #2435

Closed
5 tasks done
inotia00 opened this issue Oct 14, 2024 · 1 comment
Closed
5 tasks done
Labels
Feature request Requesting a new feature

Comments

@inotia00
Copy link
Owner

inotia00 commented Oct 14, 2024

Application

YouTube

Feature description

This is not a patch request, but a description of the feature that will be introduce in the next release.

This patch removes the search highlights (links) in comments

I think you all already know what this patch does

Here is a brief document I wrote while implementing the patch, so anyone interested can read it

──────────────────────────────────────────────────

I don't know much about Android development, so it took me a long time to implement the patch

Most of the LithoViews used in YouTube that contain text are SpannableStrings

Like and Dislike buttons labels, video titles, video descriptions, and comments are also SpannableStrings

Similar to the Return YouTube Dislike patch, we can theoretically change almost any text in a LithoView

There is one Method that generates Spanned

Any SpannableString with the flag SPAN_INCLUSIVE_INCLUSIVE goes through this Method

This Method uses Spannable#setSpan(Object what, int start, int end, int flags), so it's perfect for hooking

Here is a screenshot of the search highlights:

original

The original text is:

The cybercab looks like a car version of the cybertruck.

(The highlight keyword is cybertruck)

Unlike the original text, the debug log SpannableString.toString() shows the following:

The cybercab looks like a car version of the cybertruck⁠ .

There are two empty strings between the highlight keyword cybertruck and the dot

To check what the two empty strings are, I printed the debug log of StringEscapeUtils.escapeJava(SpannableString.toString()) and the result is as follows:

The cybercab looks like a car version of the cybertruck\u2060 .

There is still one empty string between the highlight keyword cybertruck and the dot, but at least I was able to find the unicode character 'WORD JOINER' (U+2060) that I had not found

I did not find out exactly what the last remaining empty string is, but I guess it is where the magnifying glass icon is placed

That is, all highlight keywords contain the unicode character 'WORD JOINER' (U+2060)

So, if the comment contains the unicode character 'WORD JOINER' (U+2060), can I remove the search highlight of the comment by not applying Spannable#setSpan(Object what, int start, int end, int flags)?

Yes, the search highlight is removed

The downside of this method is that no Span is applied, so it appears as raw text, as in the following screenshot:

no_span

To fix this, we need to apply Span to all strings except the search highlight

I was able to get the following information by printing the debug log of all parameters of Spannable#setSpan(Object what, int start, int end, int flags)

Object what is the Span to apply and is invoked in the following order:

Object type: ClickableSpan, length: 58, start: 45, end: 57, start char: 'c', end char: '.'
Object type: ForegroundColorSpan, length: 58, start: 0, end: 57
Object type: AbsoluteSizeSpan, length: 58, start: 0, end: 57
Object type: TypefaceSpan, length: 58, start: 0, end: 57
Object type: ForegroundColorSpan, length: 58, start: 45, end: 57, start char: 'c', end char: '.'
Object type: ImageSpan, length: 58, start: 56, end: 57, start char: ' ', end char: '.'

※ The index of unicode character U+2060 is 55

We can see through the debug log that Span is applied to the highlight keyword when the difference between the index of end and the index of U+2060 is 2

Using this principle, we can avoid applying Span only to the highlight keyword

results

Motivation

Search highlights were so annoying but no one implemented this patch for me

Acknowledgements

  • This is not a feature request for YouTube.
  • This issue is not a duplicate of an existing feature request.
  • I have chosen an appropriate title.
  • All requested information has been provided properly.
  • I have written the title and contents in English.
@inotia00 inotia00 added the Feature request Requesting a new feature label Oct 14, 2024
@inotia00 inotia00 changed the title feat(YouTube): add Hide search highlights patch feat(YouTube/Hide comments components): add Hide highlighted search links setting Oct 18, 2024
inotia00 added a commit to inotia00/revanced-integrations that referenced this issue Oct 18, 2024
inotia00 added a commit to inotia00/revanced-patches that referenced this issue Oct 18, 2024
@inotia00
Copy link
Owner Author

reflected in revanced-patches-4.15.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request Requesting a new feature
Projects
None yet
Development

No branches or pull requests

1 participant