Skip to content

Instantly share code, notes, and snippets.

@spiralx
Created March 11, 2014 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiralx/9489034 to your computer and use it in GitHub Desktop.
Save spiralx/9489034 to your computer and use it in GitHub Desktop.
Bookmarklets I've written or found useful
/*
* Prompts for the URL of a script, then creates a bookmarklet to load and run the script.
*
* javascript:(function(u) {u=prompt('Script URL');u&&prompt('Bookmarklet', 'javascript:(function(d,s){s=d.createElement("script");s.src="'+u.replace(/^https?:/,'')+'?cb="+Math.random();d.body.appendChild(s)})(document)') })()
*/
(function(u) {
u = prompt('Script URL');
u && prompt('Bookmarklet',
'javascript:(function(d,s){s=d.createElement("script");s.src="' +
u.replace(/^https?:/,'') +
'?cb="+Math.random();d.body.appendChild(s)})(document)')
})()
/*
* Same, but shows a element at the top of the page with a link you can drag to your bookmarks.
*
* javascript:(function(d, u, b, a){u=prompt('Script URL');if(u){b='javascript:(function(d,s){s=d.createElement("script");s.src="'+u.replace(/^https?:/,'')+'?cb="+Math.random();d.body.appendChild(s)})(document)';a = d.createElement('a');a.setAttribute('style','display:block;position:fixed;top:10px;width:640px;left:50%;margin-left:-320px;border:solid 2px black;padding:6px;font-weight:bold;background:#fff');a.href = a.textContent = b;d.body.appendChild(a)}})(document)
*/
(function(d, u, b, a) {
u = prompt('Script URL');
if (u) {
b = 'javascript:(function(d,s){s=d.createElement("script");s.src="' +
u.replace(/^https?:/,'') +
'?cb="+Math.random();d.body.appendChild(s)})(document)';
a = d.createElement('a');
a.setAttribute('style', 'display:block;position:fixed;top:10px;width:640px;left:50%;margin-left:-320px;border:solid 2px black;padding:6px;font-weight:bold;background:#fff');
a.href = a.textContent = b;
d.body.appendChild(a)
}
})(document)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment