Created
December 22, 2010 00:09
-
-
Save laander/750857 to your computer and use it in GitHub Desktop.
A nifty tool for creating hosted javascript browser bookmarklets supporting jQuery
This file contains 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
/** | |
* Hosted jQuery Bookmarklet | |
* @description A nifty tool for creating hosted javascript browser bookmarklets supporting jQuery | |
* @author Laander (http://laander.com) at Konscript (http://konscript.com) | |
* @gist https://gist.github.com/gists/750857 | |
*/ | |
/** | |
* Usage: | |
* The following snippet should be the link saved as a bookmarklet by the user. | |
* Instead of a regular website adress, this will execute the remotely located javascript on | |
* the page where the user is currently located. Replace the test address with you own. | |
* | |
* <a alt="My Bookmarklet" href="javascript:(function(){document.body.appendChild(document.createElement('script')).src='http://mysite.com/hosted-bookmarlet.jquery.js');})();">Drag to Bookmarks Bar to save this Bookmarklet</a> | |
*/ | |
function run() { | |
// Your script here. | |
// Remember that you have full access to the DOM on which page the bookmarklet is loaded, | |
// which means that you can manipulate the content of other sites on-the-fly | |
} | |
function loadJQ() { | |
// Load newest jQuery if it isn't already | |
if (typeof jQuery == 'undefined') { | |
var jQuery = document.createElement('script'); | |
jQuery.type = 'text/javascript'; | |
jQuery.onload = run; | |
jQuery.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'; | |
document.body.appendChild(jQuery); | |
} | |
// Activate no-conflict mode, remember to call jQuery().function instead of $().function | |
jQuery.noConflict(); | |
} | |
loadJQ(); | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment