Skip to content

Instantly share code, notes, and snippets.

@SebastianGrans
Last active June 22, 2023 11:12
Show Gist options
  • Save SebastianGrans/26e41b6e050de385775d5eaffbb83049 to your computer and use it in GitHub Desktop.
Save SebastianGrans/26e41b6e050de385775d5eaffbb83049 to your computer and use it in GitHub Desktop.
Emulate the behaviour of the Wikiwand extension in Safari 13 using an AdGuard JavaScript filter
# Since Safari 13 the Wikiwand plugin is no longer available and they
# don't even list Safari as a supported browser anymore.
#
# Most people use some kind of ad blocker, and personally I'm using "AdGuard for Safari" which allows you
# to define filters that inject javascript code on certain domains.
#
# Simply add this to AdGuards "User filter", and any wikipedia article will be redirected to Wikiwand.
#
@@||wikipedia.org^$generichide,badfilter
wikipedia.org#%#if (window.location.search === "") { var lang = window.location.hostname.split('.')[0]; var article = window.location.pathname.split('/')[2]; window.location.href = "http://www.wikiwand.com/" + lang + "/" + article; }
@nikolamilekic
Copy link

Hi, does this still work for you? I can only get it to work with the AdGuard Base filter disabled. Do you know of a way to keep the filter enabled and have the redirect work? Thanks!

@SebastianGrans
Copy link
Author

Yes and no.
It works flawlessly on the Mac I'm currently using, but on my work laptop, it suddenly stopped working some time ago.
I tried debugging it, but I can't seem to figure out what's wrong.

@SebastianGrans
Copy link
Author

After disabling and enabling all the AdGuard filters it seems to be working again.

@nikolamilekic
Copy link

nikolamilekic commented Aug 31, 2020 via email

@SebastianGrans
Copy link
Author

Hm... Strange.

What you can try to do is to add the following user rule:

#%#console.log("Hello world!");

This should run on ALL websites and print "Hello world" in the javascript console.

You can access the javascript console through the Safari menu: DevelopShow JavaScript Console or by pressing ⌥-⌘-c (option-command-c). (You might have to enable web inspector for this to work, see instructions here.)

I noticed that this rule ran on every website, except for Wikipedia. So I simply tried enabling/disabling extensions and the various rules in AdGuard. All of a sudden it just started to work.

Note: After changing the user rules, you need to open a new window for the rule to be active.

@nikolamilekic
Copy link

No luck. ☹️
With the 'hello world' trick I see the same results as you – that rule runs on every website except for Wikipedia. The only way I can get it to run on Wikipedia is if I disable (and keep disabled) the AdGuard Base filter, but I want to keep that enabled for the sake of my sanity. I guess it's an AdGuard bug... Nevertheless, thanks for your help!

@SebastianGrans
Copy link
Author

Somehow the AdGuard Base filter was disabled for me as well...
I'll try to file an issue with AdGuard and see how to resolve this.

@SebastianGrans
Copy link
Author

I am now using AdGuard for Safari version 1.8.2 with the base filter activated and it seems to be working! fingers crossed

@nikolamilekic
Copy link

nikolamilekic commented Oct 1, 2020 via email

@adamJLev
Copy link

Thanks for the tip, this is great 👍
I also had some issues enabling it, but after enabling/disabling the adguard base list it seems to now work

@SebastianGrans
Copy link
Author

SebastianGrans commented Apr 8, 2021

I just discovered that they have a specific repo for their lists, so I added an issue there: AdguardTeam/AdguardFilters#79855

EDIT:
Well that was fast. Someone replied immediately and solved it!

The first line removes the basefilter from Wikipedia and allows the second rule to run. And hence, redirect any wikipedia article to wikiwand.

@@||wikipedia.org^$generichide,badfilter
wikipedia.org#%#if (window.location.search === "") { var lang = window.location.hostname.split('.')[0]; var article = window.location.pathname.split('/')[2]; window.location.href = "http://www.wikiwand.com/" + lang + "/" + article; } 

@nikolamilekic
Copy link

It works, it works! Thanks a bunch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment