Blocking google thumbnails/images with my add-on

(Leonardo Sedevcic) #1

hi i would like to block bad image contents with my Firefox add-on “Stop-it”
i have some differents ideas :

Thumbnails are hosted in those 10 urls from google sservers:

those 10 urls are those who show the thumbnails we see when we do an image search, i would like to block xxx image thumbnails showing from those urls or just replace the thumbnails by for example a picture:

maybe by replacing with an i-frame or something.
maybe we can do this too, when someone is typing a bad word like “porn” or “bdsm” etc the user is directed to google search or the history sent the user to host.

thanks to all

(Niklas Gollenstede) #2

I suggest you have a look at the

I’d focus on making sure that can’t be switched off (probably sets a cookie).

(Leonardo Sedevcic) #3

i know safe search, my question is clear i think for everyone, i want to add a new function to my add-on, not activate safe-search on google engine, thanks anyway !

(Martin Giger) #4

I mean, yes you can block images or send different content using the webRequest API, so not really sure what you are trying to find out about.

(Leonardo Sedevcic) #5

Well everytime i was looking on google search it was like everyone was saying it’s impossible to block google images thumbnails.
everyone is also saying it’s impossible to replace those thumbnails by another picture.

my add-on blocks tons of urls and i would like to implement that feature:
when someone is trying to look for porn pictures in google image, the pictures doesn’t show & instead show another picture a car, a cat or anything else.

so thats my dream for 2018 :smiley: i would like to achieve that, implement that function in my add-on, but i need help.

(Niklas Gollenstede) #6

my question is clear i think for everyone

There is not a single question mark in your first post, ergo you didn’t ask a question at all.
Your implied question is probably “How can I do that?”.

As @freaktechnik points out, blocking or redirecting images (by URL) is not a problem.
What is a problem is to find out which URLs to block (and that, by the way, is not really an extension development question).

AFAIK, the thumbnail URLs in question are just hashes etc, so they contain zero information about the image content. A URL based filter won’t work.
Now, you could try something like if the tab that request one of these thumbnails is a Google search with blacklisted terms, block it. But I think that is a pretty bad idea. There are tons of therms to search for, in dozens of languages, Google could always change or extend its search term format, and Google searches are somewhat context sensitive (think: search for porn first (blocked), then search for something that could be porn, Google will infer the pornographic meaning from the recent search history and display porn, you don’t block it).

For that reason, don’t even bother. Whatever you come up with would never be as reliable as Googles own SafaSearch filter. If you would give me 50.000 USD for an implementation that is better than Googles, I wouldn’t waste my time attempting it.

So, I’d “force-enable” the build-in SafeSearch. That can be done and shouldn’t be to difficult either.

(Leonardo Sedevcic) #7

so its possible to force the build-in SafeSearch t be allways on with my add-on ?

(Niklas Gollenstede) #8

I think so, yes. I expect they implement it by setting a (value in a) cookie.
You’d need to find out what that is and set it whenever it is missing.

(Leonardo Sedevcic) #9

i found this:
In the Google Search Settings, the Filter explicit results setting enables safe search functionality. When enabled, the setting is stored in a browser cookie as FF= and passed to the server each time the user performs a Google search.
Appending safe=active to a Google search query URL also enables the strictest safe search settings.
Safe Search Enforcement for Google and YouTube Searches using a Virtual IP Address
Google provides servers that Lock SafeSearch ( settings in every Google and YouTube search. By adding a DNS entry for and (and other relevant Google and YouTube country subdomains) that includes a CNAME record pointing to to your DNS server configuration, you can ensure that all users on your network are using strict safe search settings every time they perform a Google or YouTube search.

and this code:

maybe this can be implemented in the add-on ?

or maybe this: += ‘&safe=on’; void 0

(Leonardo Sedevcic) #10

Maybe this is the solution ?

// ==UserScript== // @name Lewd Google Image Search // @namespace 156 // @include* // @version 1 // @grant none // ==/UserScript== var url = window.location.href; var safe = "&safe=off"; if(url.indexOf(safe) == -1){ url += safe; window.location = url; }

(Niklas Gollenstede) #11

According to the documentation you linked, the DNS based solution offered by Google is defensively the most elegant one, but I don’t think WebExtensions can mess with DNS (yet).
If you have (admin) access to the computers in question, you can probably do this with the hosts file. If you can manage HDCP in the network, you can set up a DNS resolver.

If you have to do this with an extension, you can enforce both URL parameters and cookies, but user/content scripts are definitely not the best place to do it. I’d probably manipulate the Cookie header and/or the URL in a webRequest.onBeforeRequest handler.

(Leonardo Sedevcic) #12

The DNS settings of a router can be overwritten with JavaScript code .

so i would like to add a function to change the DNS to: (or

when my add-on is installed it need to change the dns once, but i don’t know how to achieve that.

(Niklas Gollenstede) #13

Please clarify pretty much every line of that comment, at least I do not get what you are saying.

(Leonardo Sedevcic) #14

well i would like my add-on to have a function who can CHANGE the DNS to (or

(Niklas Gollenstede) #15

Well, DNS is not an IP-address, so you can’t “CHANGE the DNS to”, and WebExtensions can generally not change the network routers settings.

So, again, what exactly is it you want to know how to do?

(Leonardo Sedevcic) #16

well, my add-on block urls, but it doesn’t BLOCK xxx Google Images Thumbnails

that’s my problem, so i need to find a solution to block those thumbnails.

it would be excellent if i can block also xxx images/thumbnails from google image search.

(Niklas Gollenstede) #17

Sure. I got your general goal, I just don’t know what makes you claim that

The DNS settings of a router can be overwritten with JavaScript code

and what you mean by

change the DNS to: (or

Do you want to change the recursive resolver in the router to resolvers at those IPs? Or resolve to those IPs?

(Leonardo Sedevcic) #18

i saw that on a hacker website newspaper where they where talking about how javascript can change the dns of a router, so it is feasible!

but what i want is just block image thumbnails xxx from google image search !
my add-on blocks access to urls, but not to image thumbnails in google image search !

that’s the only thing i want and i need :smiley:

(Niklas Gollenstede) #19

Hackers being able to change the DNS settings of “a router” is a long way from a reliable solution.

I don’t have the feeling this dicussion is moving anywhere productive, so unless you have specific (and well defined) questions, you’ll just have to try things out yourself.

(Leonardo Sedevcic) #20

well my question is clear i think:

What i want is just block image thumbnails xxx from google image search !
my actual add-on block access to urls, but not to image thumbnails in google image search !

that’s the only thing i want to implement in my add-on code :smiley: