Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to the Power Users community on Codidact!

Power Users is a Q&A site for questions about the usage of computer software and hardware. We are still a small site and would like to grow, so please consider joining our community. We are looking forward to your questions and answers; they are the building blocks of a repository of knowledge we are building together.

Comments on How can I get my browser to block a specific SVG (Discord server icon)?

Parent

How can I get my browser to block a specific SVG (Discord server icon)?

+4
−0

I am on several Discord servers. One of them has, as its server logo, an image I would rather not see every time I use Discord. I had previously used AdBlock to suppress it, but it came back recently and it now appears that Discord is embedding an SVG rather than referencing an image URL, so I don't know how to block that. I tried using AdBlock again, but it disabled all access to the server -- I couldn't click on it. I only want to block the image; I still want to be able to click on the space where the image would have been to get to the server.

I thought to use a CSS override (using the Stylus browser extension), but I can't figure out how to do it. (I don't know if CSS is the right tool for this job. Also, I'm not very good at figuring out CSS selectors.) Here's what I see in developer tools:

web console

The structure shows a div containing an svg containing a defs containing a path with an id attribute. I want to find that ID (but not any others) and replace or obscure its d (definition?) attribute. I don't want to affect any other server icons (or other graphics for that matter).

Is CSS the right tool for this job? If so, how do I express what I want to do? I'm looking for the selector to use and a way to express "if id=(that) then d = (black box or null or something)". If CSS isn't the right tool for the job, then what is -- how should I go about blocking the image?

In case it matters: Chrome on MacOS 11.6 (priority), Firefox on Windows 10 (nice to have).

History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+2
−0

One possibility is to use an ad-blocker that can hide HTML elements based on a filter expression. I haven't used AdBlock for many years, so i can't say whether AdBlock can do it. However, uBlock Origin (also an ad-blocker) can do this.

uBlock Origin can filter out unwanted HTML elements based on CSS selectors, as long as such elements are part of the HTML document as transmitted by the web server (this excludes elements dynamically created by JS, for example).

Define the filter in the "My filters" tab pane in the add-on's settings.

I am not sure whether the class name "svg-1X37T1" for the <svg> element is static, or whether the server will generate another class name for every page load, but you might try a filter like this:

discord.com##^.svg-1X37T1

The leading ^ in the expression ^.svg-1X37T1 indicates that what follows ^ is a CSS selector. .svg-1X37T1 is an ordinary class selector. (Documentation reference: https://github.com/gorhill/uBlock/wiki/Static-filter-syntax#html-filters)


Such HTML element filters are of course not constrained to class selectors. Any CSS selector could be used, whether it's a type selector, a class selector, an attribute selector, or some other CSS selector or combination thereof. (An overview of CSS selectors: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors)

An example of an attribute selector filter that is also constrained to <svg> elements (using the :is() pseudo-class):

discord.com##^:is(svg)[width="48"]

As a side note with respect to Chrome being the priority: With the coming extension API change affecting Chrome extensions, it is to be seen whether such element filtering would still be possible once Google is making the Manifest v3 API mandatory and removing the previous API for Chrome extensions (removal of the Manifest v2 API has been announced to happen beginning of 2023).

History
Why does this post require moderator attention?
You might want to add some details to your flag.

2 comment threads

Tried and discovered a deeper problem. :-( (5 comments)
Chrome (1 comment)
Tried and discovered a deeper problem. :-(
Monica Cellio‭ wrote over 2 years ago

I installed Ublock Origin and entered that as the filter (with discord.com as the URL), but it didn't have any effect. Then I noticed, while combining this answer with the other one and trying through Stylus, that all the icons use the same svg-1X37T1 class. Any idea how to target just one of them? Maybe using the name attribute somehow?

elgonzo‭ wrote over 2 years ago

You could use a CSS attribute selector that matches against a value of a chosen attribute. However, regardless of whether you match against some attribute, some ID or some class, you will have to first find something that distinguishes the unwanted <svg> element from similar <svg> elements on discord. (If the only distinguishing property of the <svg> element is the graphics path itself, i unfortunately don't know any solution...)

Monica Cellio‭ wrote over 2 years ago

A containing div (two layers up) has a data-dnd-name attribute that is the name of the server. Is there a way to select that and then change the visibility of the svg nested inside that?

elgonzo‭ wrote over 2 years ago · edited over 2 years ago

You could try it with an attribute selector. I have expanded my answer with an example using an attribute selector (my example combined an attribute selector with an :is() selector).

You don't need to specify a visibility change explicitly, as that's what uBlock Origin does -- suppressing/removing/hiding the element(s) or content specified by the filter rules.

If that "data-dnd-name" attribute does not work, check whether the id attribute of the <path> element is unique to the undesired icon. If it does identify this icon, you might try using it in an attribute selector (or an ID selector, although i am not entirely sure whether an ID selector would work with <path> elements). Of course only and only if that <path> element is part of the the source HTML document text as transmitted by the server...

Monica Cellio‭ wrote over 2 years ago

Thanks for your help! I feel like all the answers here together helped me get to a solution. Teamwork for the win! :-)