Skip to content

Instantly share code, notes, and snippets.

@solsend2l
Forked from mattosborn/gist:6eb44db53789b485ab4a
Last active August 29, 2015 14:23
Show Gist options
  • Save solsend2l/2a71ffad3e06f19d8666 to your computer and use it in GitHub Desktop.
Save solsend2l/2a71ffad3e06f19d8666 to your computer and use it in GitHub Desktop.
Embed jQuery and Lodash on the webpage
javascript:(function() {
var el = document.createElement('pre'),
b = document.getElementsByTagName('body')[0],
otherjQuery = false,
msg = '',
libs = [
function loadjQuery() {
if (typeof jQuery != 'undefined') {
showMsg('This page already using jQuery v' + jQuery.fn.jquery);
} else {
if (typeof $ == 'function') {
otherjQuery = true;
}
var jqv = prompt('jQuery version:', '2.0.3');
getScript('//cdnjs.cloudflare.com/ajax/libs/jquery/'+jqv+'/jquery.js', function() {
if (typeof jQuery == 'undefined') {
showMsg('Sorry, but jQuery wasn\'t able to load')
} else {
showMsg('This page is now jQuerified with v' + jQuery.fn.jquery + otherjQuery ? ' and noConflict(). Use $jq(), not $().' : '');
}
});
}
},
function loadLodash() {
if (typeof _ != 'undefined') {
showMsg('This page already using lodash v' + _.VERSION);
}
var ldv = prompt('lodash version:', '3.9.3');
getScript('//cdnjs.cloudflare.com/ajax/libs/lodash.js/'+ldv+'/lodash.min.js', function() {
showMsg('This page is now has lodash');
});
}
];
el.style.position = 'fixed';
el.style.top = '0';
el.style.padding = '5px 10px';
el.style.zIndex = 9001;
el.style.fontSize = '12px';
el.style.color = '#222';
el.style.backgroundColor = '#f99';
function getScript(url, success) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0],
done = false;
script.onload = script.onreadystatechange = function() {
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
success();
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
function showMsg(msg) {
if (!document.body.contains(el)) {
b.appendChild(el);
}
el.appendChild(document.createTextNode(msg + '\n'));
window.setTimeout(function() {
if (typeof jQuery == 'undefined') {
b.removeChild(el);
} else {
jQuery(el).fadeOut('slow', function() {
jQuery(this).remove();
});
if (otherjQuery) {
$jq = jQuery.noConflict();
}
}
}, 2500);
}
libs.forEach(function(init) {
init();
});
})();
@solsend2l
Copy link
Author

javascript:(function(){window.s140=document.createElement('script');window.s140.setAttribute('type','text/javascript');window.s140.setAttribute('src','https://bookmarkify.it/bookmarklets/4364/raw');document.getElementsByTagName('body')[0].appendChild(window.s140);})();

@solsend2l
Copy link
Author

javascript:(function()%7Bjavascript%3A(function()%20%7Bvar%20el%20%3D%20document.createElement('pre')%2Cb%20%3D%20document.getElementsByTagName('body')%5B0%5D%2CotherjQuery%20%3D%20false%2Cmsg%20%3D%20''%2Clibs%20%3D%20%5Bfunction%20loadjQuery()%20%7Bif%20(typeof%20jQuery%20!%3D%20'undefined')%20%7BshowMsg('This%20page%20already%20using%20jQuery%20v'%20%2B%20jQuery.fn.jquery)%3B%7D%20else%20%7Bif%20(typeof%20%24%20%3D%3D%20'function')%20%7BotherjQuery%20%3D%20true%3B%7Dvar%20jqv%20%3D%20prompt('jQuery%20version%3A'%2C%20'2.0.3')%3BgetScript('%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Fjquery%2F'%2Bjqv%2B'%2Fjquery.js'%2C%20function()%20%7Bif%20(typeof%20jQuery%20%3D%3D%20'undefined')%20%7BshowMsg('Sorry%2C%20but%20jQuery%20wasn%5C't%20able%20to%20load')%7D%20else%20%7BshowMsg('This%20page%20is%20now%20jQuerified%20with%20v'%20%2B%20jQuery.fn.jquery%20%2B%20otherjQuery%20%3F%20'%20and%20noConflict().%20Use%20%24jq()%2C%20not%20%24().'%20%3A%20'')%3B%7D%7D)%3B%7D%7D%2Cfunction%20loadLodash()%20%7Bif%20(typeof%20_%20!%3D%20'undefined')%20%7BshowMsg('This%20page%20already%20using%20lodash%20v'%20%2B%20_.VERSION)%3B%7Dvar%20ldv%20%3D%20prompt('lodash%20version%3A'%2C%20'3.9.3')%3BgetScript('%2F%2Fcdnjs.cloudflare.com%2Fajax%2Flibs%2Flodash.js%2F'%2Bldv%2B'%2Flodash.min.js'%2C%20function()%20%7BshowMsg('This%20page%20is%20now%20has%20lodash')%3B%7D)%3B%7D%5D%3Bel.style.position%20%3D%20'fixed'%3Bel.style.top%20%3D%20'0'%3Bel.style.padding%20%3D%20'5px%2010px'%3Bel.style.zIndex%20%3D%209001%3Bel.style.fontSize%20%3D%20'12px'%3Bel.style.color%20%3D%20'%23222'%3Bel.style.backgroundColor%20%3D%20'%23f99'%3Bfunction%20getScript(url%2C%20success)%20%7Bvar%20script%20%3D%20document.createElement('script')%3Bscript.src%20%3D%20url%3Bvar%20head%20%3D%20document.getElementsByTagName('head')%5B0%5D%2Cdone%20%3D%20false%3Bscript.onload%20%3D%20script.onreadystatechange%20%3D%20function()%20%7Bif%20(!done%20%26%26%20(!this.readyState%20%7C%7C%20this.readyState%20%3D%3D%20'loaded'%20%7C%7C%20this.readyState%20%3D%3D%20'complete'))%20%7Bdone%20%3D%20true%3Bsuccess()%3Bscript.onload%20%3D%20script.onreadystatechange%20%3D%20null%3Bhead.removeChild(script)%3B%7D%7D%3Bhead.appendChild(script)%3B%7Dfunction%20showMsg(msg)%20%7Bif%20(!document.body.contains(el))%20%7Bb.appendChild(el)%3B%7Del.appendChild(document.createTextNode(msg%20%2B%20'%5Cn'))%3Bwindow.setTimeout(function()%20%7Bif%20(typeof%20jQuery%20%3D%3D%20'undefined')%20%7Bb.removeChild(el)%3B%7D%20else%20%7BjQuery(el).fadeOut('slow'%2C%20function()%20%7BjQuery(this).remove()%3B%7D)%3Bif%20(otherjQuery)%20%7B%24jq%20%3D%20jQuery.noConflict()%3B%7D%7D%7D%2C%202500)%3B%7Dlibs.forEach(function(init)%20%7Binit()%3B%7D)%3B%7D)()%7D)()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment