Skip to content

Instantly share code, notes, and snippets.

@mvark
Last active January 6, 2022 16:54
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvark/a8c4745fdb879afd4c0db8e5e183911a to your computer and use it in GitHub Desktop.
Save mvark/a8c4745fdb879afd4c0db8e5e183911a to your computer and use it in GitHub Desktop.
Browser 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);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment