Skip to content

Instantly share code, notes, and snippets.

@bantic
Created February 3, 2019 16:08
Show Gist options
  • Save bantic/043bf9d9d09a2eb6c5cc8e456fdb1b5a to your computer and use it in GitHub Desktop.
Save bantic/043bf9d9d09a2eb6c5cc8e456fdb1b5a to your computer and use it in GitHub Desktop.
function injectJquery(callback) {
if (window.jQuery) {
return callback(window.jQuery);
}
let script = document.createElement('script');
script.setAttribute(
'src',
'//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js'
);
script.onload = () => callback(window.jQuery);
script.onerror = e => alert('The script failed to load: ' + e);
document.head.appendChild(script);
}
injectJquery(function($) {
let html = $('body').html();
html = html.replace(/Lorem/g, 'Bacon');
$('body').html(html);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment