Normally, I write about C# here. However, I want to share this little utility I wrote to fix an annoying problem I encounter almost every day.
Some websites won’t let you view their pages if you have an ad-blocker installed for your browser. When I visit sites like Hacker News, there are usually a few links to articles on these sites. So, when I visit them, I can’t view them.
So, I wrote this Greasemonkey script to remove the links to these articles, and highlight them in yellow – so I know I can’t click on that text.
I use Firefox, and installed the Greasemonkey plug-in from here: https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/
After you install Greasemonkey, you should see a monkey icon in your browser’s toolbar.
To create this script, click on the arrow (next to the monkey) and select “New User Script…” from the menu.
I named this script “RemoveBadHyperlinks”.
For the namespace, select something that is unique, in case you ever import a script with the same name. I used my website name “https://www.scottlilly.com”.
I used “Removes hyperlinks to websites with annoying policies” for the description.
The Includes and Excludes boxes are empty.
Clicking on the “OK” will open a script editor, with the script’s information in it:
// ==UserScript== // @name RemoveBadHyperlinks // @namespace https://www.scottlilly.com // @description Removes hyperlinks to websites with annoying policies // @version 1 // @grant none // ==/UserScript==
If you want to copy-paste this code into the script editor, you need to type “allow pasting” first. I typed this after the last line of the script header information. Or, you could manually type the code below into your editor window.
If you paste the code, remove the “allow pasting” line and your code should look like this:
You can remove, or add, websites to your version of this script. Just delete, or add, the “link.hostname.includes” lines.
Now, browsing is a little less frustrating.
What if you want to click on one of the links?
You can disable the script by clicking on the arrow next to the monkey, to show the Greasemonkey menu, and un-checking the script(s) you want to turn off. Check them, to turn the script on again.
Do you have suggestions to improve this script?