Bookmarker Bookmarklet

I've used the Google Bookmarks bookmarklet in the past to save interesting articles for future reference. I like adding some notes so that I know in the future why it was bookmarked. If it was a social media contact, I would like to record some interaction or personal details for future reference.

I found a code sample in a StackOverflow post that showed how to save a URL to Google Sheets. As I like spreadsheets, I liked the idea of saving bookmarks there along with my notes. 

I tweaked the original sample a bit (Github Gist link^) to create what I call the "L8r" Bookmarklet to record an open web page's URL & its title as a row in Google Sheets -


//Following code can be used within Google App Script editor & deployed
//Original code - https://stackoverflow.com/q/15592094/325251
function doGet(request) {
var ss = SpreadsheetApp.openByUrl( "https://docs.google.com/spreadsheet/ccc?key=<YOUR-SPREADSHEET-ID>");
var sheet = ss.getSheets()[0];
//just this line was tweaked to include the web page's title
var headers = ["Timestamp", "url","title"];
var nextRow = sheet.getLastRow();
var cell = sheet.getRange('a1');
var col = 0;
for (i in headers){
if (headers[i] == "Timestamp"){
val = new Date();
} else {
val = request.parameter[headers[i]];
}
cell.offset(nextRow, col).setValue(val);
col++;
}
return ContentService.createTextOutput(request.parameter.url)
.setMimeType(ContentService.MimeType.TEXT);
}
///////////////////////////////////////////////////////////////////
Link to use to add Bookmarklet to bookmark bar -
<a href="javascript:(function(){var w=window.open('https://script.google.com/macros/s/<YOUR-WEB-APP>/exec?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title),'bookmarker');setTimeout(function(){w.close()},3000);})();">L8r</a>
//Added the following line of code to original sample to close the window after the entry is made to Google Sheets
setTimeout(function(){w.close()},3000);}
view raw Bookmarker hosted with ❤ by GitHub

If you wish to use this bookmarklet, you'll be saving it to Google Sheets that's connected to your account. So to customize you have to replace the Spreadsheet ID in the URL of a newly pre-created sheet in the code sample and some familiarity with Google App Script is required.

The first part of the code should be copied to Apps Script editor and deployed so that an endpoint like this is created -

Related Article

https://script.google.com/macros/s/<YOUR-WEB-APP>/exec

Next drag & drop the bookmarklet link to your browser after replacing the unique placeholder identifiers. When you wish to bookmark a page, click on this "L8r" bookmarklet. It will trigger the above-mentioned Google Apps Script which will grab the URL & Title of the page you're on and add a row along with the timestamp within the pre-created sheet.

You're free add your notes in the corresponding columns of each row.

While this takes a little effort to configure, you can adapt this script for various other scenarios. Using it as a Social Media Contact Tracker, you can jot down notes about a virtual friend's birthday or some minor detail that can be beneficial later. If you shop across multiple e-commerce sites, you can create a single wish-list where you can note the URL and possibly why this caught your interest.

0 Comments