Blocking google thumbnails/images with my add-on

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:

encrypted-tbn0.gstatic.com
encrypted-tbn1.gstatic.com
encrypted-tbn2.gstatic.com
encrypted-tbn3.gstatic.com
encrypted-tbn4.gstatic.com
encrypted-tbn5.gstatic.com
encrypted-tbn6.gstatic.com
encrypted-tbn7.gstatic.com
encrypted-tbn9.gstatic.com
encrypted-tbn9.gstatic.com
encrypted-tbn10.gstatic.com

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: https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcR3cuh5zK82K_1j6DvwkFFqazqrC_kkT9_1tHvgfuPPWRaXMe_5

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

I suggest you have a look at the
SafeSearch

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

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 !

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.

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.

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.

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

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.

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 (forcesafesearch.google.com) settings in every Google and YouTube search. By adding a DNS entry for www.google.com and www.youtube.com (and other relevant Google and YouTube country subdomains) that includes a CNAME record pointing to forcesafesearch.google.com 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.

https://www.paloaltonetworks.com/documentation/71/pan-os/pan-os/url-filtering/safe-search-enforcement

and this code:
https://pastebin.com/VYyr1bpL

maybe this can be implemented in the add-on ?

or maybe this:

javascript:window.location.search += ‘&safe=on’; void 0
or
https://www.google.com/search?tbm=isch&q=%s&safe=on

Maybe this is the solution ?

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

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.

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:

185.228.168.168 (or 185.228.168.169).

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

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

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

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

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

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.

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: 185.228.168.168 (or 185.228.168.169).

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

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:

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.

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: