amitbl / blocktube

YouTube™ content blocker
GNU General Public License v3.0
856 stars 59 forks source link

[Question] How do I use advanced blocking to block videos with [ in the title? #335

Closed Konuchi closed 8 months ago

Konuchi commented 9 months ago

This does not work:

(video, objectType) => {
 if (video.title.match("["))
     {
       return true;
  }
  return false;
}
cobaltdr commented 9 months ago

Why not use a regex instead if all you want to do is block videos with [ in the title?

/\[/gm

In the video title box on its own line should achieve this. Unless you're looking to understand how the advanced blocking feature works (I've not used it, so cannot comment).

\ takes the next character literally gm for global multiline match

Konuchi commented 9 months ago

Because I don't want to block the videos on the channel pages or in search.

cobaltdr commented 9 months ago

(video, objectType) => { if (video.title.match("[")) { return true; } return false; }

Works here.

Konuchi commented 9 months ago

It's not working for me. notworking

cobaltdr commented 9 months ago

Is it an actual [ character or have they been sneaky and used a visually similar but different character?

Konuchi commented 9 months ago

It's an actual [ character. I copied and pasted to be sure.

ewonais commented 8 months ago

"$" is also a special character for matching, you nead to dubbel escape it: if (video.title.match("\$20") return true; blocks videos containing "$20" in the title probobly the same shuld work for "["

Konuchi commented 8 months ago

That also does not work.

ClawhammerLobotomy commented 8 months ago

Have you tried using double backslash? (video, objectType) => { if (video.title.match("\\[")) { return true; } return false; } I just tested this with your example which did not work, but adding double backslash did for me.

string.match() uses a regex pattern and you need to escape both the bracket and the backslash for it to match a literal bracket.

Konuchi commented 8 months ago

That works. Thank you so much, also for explaining why it works.