Skip to content

Instantly share code, notes, and snippets.

@dsingleton
Created December 14, 2011 12:22
Show Gist options
  • Save dsingleton/1476378 to your computer and use it in GitHub Desktop.
Save dsingleton/1476378 to your computer and use it in GitHub Desktop.
Bookmarklet to insert a JS file, with config query params added to the script call
(function (url, params) {
var body = document.body,
script = document.createElement('script');
try {
pairs = [];
for(var key in params) pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
script.setAttribute('src', url + '?' + pairs.join('&'));
script.setAttribute('id', params.id || 'bookmarklet');
} catch (c) {
alert('Please wait until the page has loaded');
}
body.appendChild(script);
void(0);
})('http://example.com/bookmarklet.js', {id: 'my-bookmarklet', cachebust: new Date()*1, user: 'alice');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment