Saturday, 3 October 2020

Magic of Browser Bookmarks - Automate Simple Tasks using JavaScript

 As I promised in #LearnedToday, I'm going to show you how much you can achieve with this little bookmark feature in the browsers.

Ever wondered how to easily remove citations from a Wikipedia page? 

What are bookmarks?

The bookmarks in the browsers are to save the links to the pages you wish visiting again, or you just find them useful and save for later. 

Instead of creating a text file "Imp Links"and saving all the links there (I've done it a lot), you could use browser's bookmark feature.

The shortcut to bookmark a webpage in most of the broswsers is ctrl+b.

What more can they do?

To sum up, they can run JavaScript on a page. So instead of opening broswer console to do run a couple lines of code, you could create a bookmark and click that instead.


Whenever I needed to copy something from Wikipedia, I usually had to deal with the references/citations they have. You must've seen those, with squared brackets around numbers, something like this [1] or with a disclaimer like [citation needed] etc. I needed to remove all those. 

Initially, I used to do it in MS Word manually, by Find and Replace. I don't remember that now, doesn't matter anyway. 

Finally, I came to know about this browser bookmarklets, and then a simple regex was enough to do the work for me.

Now I have a simple bookmark. I go to any Wikipedia page, select the text I need, and click the bookmark. Viola! Citations are removed.

How to create a bookmarklet?

Got to Bookmarks Manager

1. Click three vertical dots in the upper right corner > Bookmark > Bookmark Manager

Or chrome shortcut: ctrl+shift+o

Or type in the address bar: chrome://bookmarks/

2. Click three vertical dots in the upper right corner of Bookmark manager (Shows tooltip: Organize) 

3. Add new bookmark

4. It will show a popup with two fields: Name and URL. 

5. Give any appropriate name, and in the URL bar, paste the JavaScript code you want to execute.

6. Click Save. 

You have your bookmarklet ready. 

Show/Hide Bookmarks bar with ctrl+shift+b. Clicking on the name of your bookmark will run the underlying code. 

Which bookmarklets am I using?

1. Citation Remover discussed above. 

2. A tiny calculator which returns results of simple arithmetic operations.

3. StyleStripper which strips all CSS styles from a webpage. Helpful if I don't want to load an entire page I want to copy something from.Also works on the sites which disable copying using JavaScript. Click StyleStripper and you can copy the text.

To those who requested, don't complain now. I have shared it finally. More such tips will follow. Keep visiting! Or not. But I know you will. :wink:

Rab Raakha!

Shakeeb Ahmad Maharashtra, India

Shakeeb Ahmad is a blogger, poet, enthusiast programmer, student of comparative religion and psychology, public speaker, singer and Vedic Maths expert. He loves playing with the numbers and invented a shortcut method to square the numbers at the age of 16. In sports, football is root to his happiness. He lives it.

No comments:

Post a comment