Last active
January 6, 2022 16:54
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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