Skip to content

Instantly share code, notes, and snippets.

@ricealexander
Last active June 24, 2025 07:18
Show Gist options
  • Save ricealexander/4e96b08869f515a3515ca25084f4cb1b to your computer and use it in GitHub Desktop.
Save ricealexander/4e96b08869f515a3515ca25084f4cb1b to your computer and use it in GitHub Desktop.
Refactoring Grove's Inline Bookmarklet
// Original bookmarklet
javascript: void function () {
var bspUrl = 'https://' + window.location.hostname + '/cms/content/edit.jsp'
var metaName = 'brightspot.contentId'
var metas = document.getElementsByTagName('meta')
var found = false
console.log(bspUrl)
for(var i = 0; i < metas.length; i++) {
console.log(metas[i])
if(metas[i].getAttribute('name') === metaName) {
found = true
open(bspUrl + '?id=' + metas[i].getAttribute('content'), '_blank')
}
}
if(!found) {
alert('Error Finding In Brightspot')
}
}()
// Refactored bookmarklet
javascript: void function () {
var contentId = document.querySelector('meta[name="brightspot.contentId"]')
if (contentId && contentId.content) {
open('https://app.grovecms.org/cms/content/edit.jsp?id=' + contentId.content, '_blank')
}
else {
alert('Error Finding In Brightspot')
}
}
// Changes
// 1. Query 'meta[name="brightspot.contentId"]' instead of querying all meta tags and filtering to find 'brightspot.contentId'
// 2. The edit URL at window.location.hostname will always redirect to https://app.grovecms.org, so hardcode this value
// 3. Check whether contentId.content exists before referencing it. An empty content attribute is valid HTML and would cause unexpected behavior
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment