Userscripts - How to redirect without connecting to target website first?

4 Antworten [Letzter Beitrag]
GNUser
Offline
Beigetreten: 07/17/2013

Hi.

I have seen some userscripts that redirect websites like Youtube to Invidious, Twitter to Nitter, etc. Example below, and I am running them with ViolentMonkey.
Now my problem with these is that I notice they still allow the browser to connect to Youtube, Instagram, Twitter, etc, they will even load the page for a few seconds, before actually redirecting to Invidious, Bibliogram, Nitter, etc. That is very bad from a privacy perspective, so I would like to know if it's possible to write a script that will actually intercept the connection attempt BEFORE connecting and redirect safely.

I know there are other options like LibRedirect and etc, but I think userscripts have other interesting functionalities that I would like to take advantage of. Also, I am curious if this is even possible to do :)
Thanks for all help you might provide!

Example:
https://greasyfork.org/en/scripts/437398-twitter-to-nitter

andermetalsh
Offline
Beigetreten: 01/04/2013

Add youtube, twitter and so on to your /etc/hosts file :)

Append at the end:

127.0.0.1 .youtube.com

And so on.

GNUser
Offline
Beigetreten: 07/17/2013

That... is actually a good idea, I had not thought of that!
However, I want it to be a usable solution with the Tor Browser, which will not work through my hosts file.

The idea is pretty good in any case ;) thanks for the suggestion!

Lèyon di li N.
Offline
Beigetreten: 02/11/2017

That's an old trick.

Lèyon di li N.
Offline
Beigetreten: 02/11/2017

Personally, I would make user scripts that changes the links in the webpage containing the links instead of redirecting when the links are clicked.
And that is complementary to the /etc/hosts trick because, then, those malicious websites might still integrate spying stuffs in those page before the links are changed.