feat(YouTube/Hide comments components): add Hide highlighted search links
setting
#2435
Closed
5 tasks done
Labels
Feature request
Requesting a new feature
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 LithoViewThere is one Method that generates Spanned
Any SpannableString with the flag
SPAN_INCLUSIVE_INCLUSIVE
goes through this MethodThis 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:
The original text is:
(The highlight keyword is
cybertruck
)Unlike the original text, the debug log
SpannableString.toString()
shows the following:There are two empty strings between the highlight keyword
cybertruck
and the dotTo check what the two empty strings are, I printed the debug log of StringEscapeUtils.escapeJava(SpannableString.toString()) and the result is as follows:
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 foundI 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:To fix this, we need to apply
Span
to all strings except the search highlightI 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
Motivation
Search highlights were so annoying but no one implemented this patch for me
Acknowledgements
The text was updated successfully, but these errors were encountered: