Skip to content

Instantly share code, notes, and snippets.

@yanivkalfa
Last active December 11, 2015 07:59
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 yanivkalfa/b443582b1ced537b7612 to your computer and use it in GitHub Desktop.
Save yanivkalfa/b443582b1ced537b7612 to your computer and use it in GitHub Desktop.
Just a part of my bookmarklet
/* creating loading and appending include files for the bookmarklet*/
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var jquery_load = document.createElement("script");
jquery_load.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
jquery_load.setAttribute('id', 'yk_bookmarklet_jquery');
jquery_load.onload = jquery_load.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
loaded_headers++;
console.log("Next1"); // <-- is being printed to console
if(loaded_headers >= total_headers){
done = true;
$.getJSON("xxxx",
function(data){
/* more variables*/
window.mbm = false;
initMyBookmarklet(); // function that has the bookmarklet info.
});
}
}
};
var CssScript = document.createElement("link");
CssScript.href = "http://www.shopsavr.com/css/yk_bookmarklet.css";
CssScript.setAttribute('type', 'text/css');
CssScript.setAttribute('rel', 'stylesheet');
CssScript.setAttribute('media', 'all');
CssScript.setAttribute('id', 'yk_bookmarklet_css');
CssScript.onload = CssScript.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
loaded_headers++;
console.log('Next2');// <-- DOES NOT print to console
if(loaded_headers >= total_headers){
done = true;
$.getJSON("xxxx",
function(data){
/* more variables*/
window.mbm = false;
initMyBookmarklet(); // function that has the bookmarklet info.
});
}
}
};
/*appending the created elements*/
document.getElementsByTagName("head")[0].appendChild(jquery_load);
document.getElementsByTagName("head")[0].appendChild(yk_bookmarklet);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment