Skip to content

Instantly share code, notes, and snippets.

@watert
Last active December 19, 2015 20:59
Show Gist options
  • Save watert/6017274 to your computer and use it in GitHub Desktop.
Save watert/6017274 to your computer and use it in GitHub Desktop.
Bookmarklet based on loading scripts
// Bookmarklet Example
// javascript:(function(){ })();
// load script For bookmarklet
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "helper.js";
head.appendChild(script);
var loadScripts = function(array,callback){
var array = array||["https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js",
"http://documentcloud.github.com/underscore/underscore-min.js",
"http://documentcloud.github.com/backbone/backbone-min.js"];
var loader = function(src,handler){
var script = document.createElement("script");
script.src = src;
script.onload = script.onreadystatechange = function(){
script.onreadystatechange = script.onload = null;
if(/MSIE ([6-9]+\.\d+);/.test(navigator.userAgent)){
window.setTimeout(function(){handler();},8,this);
} else {
handler();
};
}
var head = document.getElementsByTagName("head")[0];
(head || document.body).appendChild( script );
};
(function(){
if(array.length!=0){
loader(array.shift(),arguments.callee);
}else{
callback && callback();
}
})();
};
var lib_tests = {"https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js":typeof jQuery != "undefined" && jQuery.ajax,
"http://documentcloud.github.com/underscore/underscore-min.js":typeof _ != "undefined" && _.map,
"http://documentcloud.github.com/backbone/backbone-min.js":typeof Backbone != "undefined" && Backbone.View};
for(var i in lib_tests){
console.log(lib_tests[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment