Bookmarklets

Err… what’s a Bookmarklet?

A bookmarklet is a bit of JavaScript disguised as a bookmark that, when run, can perform a specific bit of work via your browser.  These below are generally built to satisfy some search need, to make these searches easier, more seamless, and less annoying.  Try one; try them all!

I have tested these and they all work as-is in the latest (2023-01-19) versions of Opera, Chrome, and Firefox.

If you run into trouble, try updating your browser or disabling all extensions before altering the JavaScript.

(If clicking the bookmarklet dialog does not spawn a new tab with your target, I have seen Firefox act a fool and need changed to %27.  But probably check your updates and extensions.)

HowTo:  Install and Use a Bookmarklet

The short version:

  • Triple-click the line of JavaScript code to highlight it.
  • Drag and drop that line of code to your browser’s Bookmarks Bar to create a bookmark.
    • If drag-and-drop doesn’t work, created any bookmark and edit to substitute the js as the destination and name it accordingly.
  • Right-click that newly created bookmark to edit the name.
    • Suggested names are provided above each JS line.  I like to keep the names short so more fit on the bar.
  • Rinse and repeat for all you’d like below.  Or create your own.

Usage

Once you have a bookmarklet installed, there are two ways to use it.  You can either highlight any text on the page and click the bookmarklet, or (if no text is highlighted on the page) a search dialog appears when the bookmarklet is clicked.

Of note, iframe contents cannot be seen, only the wrapping page.  In these circumstances a dialog will always spawn.

These are all built to open a new tab, which should open next to (to the right of) your current working tab.

These can be leveraged for many searches one does throughout the day, thus greatly increasing the efficiency of said searches.  I’ve been building and using them since 1999 and will continue to do so.

Bookmarklets

GitHub

// 
// GitHub https://github.com/search?q=searchthis 
// gitH 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search GitHub for… ").replace(/\s\+/g,"%252B");if(q!=null)window.open("https://github.com/search?q="+q);void(0); 
// 

Amazon

// 
// Amazon https://www.amazon.com/s?k=searchthis&crid=2SHRP43MFNSJ8&sprefix=searchthis%2Caps%2C386&ref=nb_sb_noss 
// Amazon+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search Amazon for… ").replace(/\s\+/g,"%252B");if(q!=null)window.open("https://www.amazon.com/s?k="+q);void(0); 
// 

LinkedIn

// 
// LinkedIn https://www.linkedin.com/search/results/all/?keywords=searchthis&origin=GLOBAL_SEARCH_HEADER&sid=cVD  
// LI+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search Amazon for… ").replace(/\s\+/g,"%252B");if(q!=null)window.open("https://www.linkedin.com/search/results/all/?keywords="+q);void(0); 
// 

Confluence

Adjust URL for your instance.

// 
// Confluence 
// https://esentire.atlassian.net/wiki/search?text=narf 
// C+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Confluence [try words]…").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://esentire.atlassian.net/wiki/search?text='+q);void(0); 
// 

SolarWinds

Adjust URL for your instance.

// 
// SolarWinds https://YOURINSTANCE/ui/search?q=%s 
// SW+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("SolarWinds [try a sensor number]…").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://YOURINSTANCE/ui/search?q='+q);void(0); 
// 

ServiceNow

Adjust URL for your instance.

// 
// ServiceNow ticket search https://YOURINSTANCE.service-now.com/nav_to.do?uri=%2F$sn_global_search_results.do%3Fsysparm_search%3D%s 
// SN+s 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Service-Now [try a sensor number]…").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://YOURINSTANCE.service-now.com/nav_to.do?uri=%2F$sn_global_search_results.do%3Fsysparm_search%3D'+q);void(0); 

// ServiceNow direct ticket search (no iframe) 
// this takes you to a ticket directly if search results are unique 
// SN+cs 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("ServiceNow Case Number: ").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://YOURINSTANCE.service-now.com/text_search_exact_match.do?sysparm_search='+q);void(0); 

// ServiceNow knowledge base article search 
// SN+KB 
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Search for a KB").replace(/\s\+/g,"%252B");if(q!=null)window.open('https://esentire.service-now.com/selfservice?id=search&spa=1&q='+q);void(0); 
// 

Under the Hood

As you will note from the JavaScript, each of these bookmarklets performs a variable substitution (here named q) into the URL sent back to the server performing the search.  As such, one would perform any URL substitution.

For example, at one job I was able to create several bookmarklets for accessing various config pages on devices by substituting the device names.

// 
// so if you begin with a URL like  
// https://devicename.company.internal:5555/path/to/configX 
// you can massage that into a bookmarklet something like  
javascript:q=""+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text);if(!q)q=prompt("Config X for device…").replace(/\s\+/g,"%252B");if(q!=null)window.open("https://"+q+".company.internal:8834/path/to/configX");void(0); 
// 

The possibilities are pretty limitless.

Share

Leave a Reply

Your email address will not be published. Required fields are marked *