Skip to content

Instantly share code, notes, and snippets.

@akshatmittal
Created November 23, 2014 11:57
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 akshatmittal/2de3c3b7907cc96e5097 to your computer and use it in GitHub Desktop.
Save akshatmittal/2de3c3b7907cc96e5097 to your computer and use it in GitHub Desktop.
Inject jQuery to any page
javascript:(function () { var el = document.createElement("div"), b = document.getElementsByTagName("body")[0], otherlib = !1, msg = ""; el.style.position = "fixed", el.style.height = "32px", el.style.width = "220px", el.style.marginLeft = "-110px", el.style.top = "0", el.style.left = "50%", el.style.padding = "5px 10px", el.style.zIndex = 1001, el.style.fontSize = "12px", el.style.color = "#222", el.style.backgroundColor = "#f99", el.style.zIndex = "99999999999999999999999999999999999"; function showMsg() { var txt = document.createTextNode(msg); el.appendChild(txt), b.appendChild(el), window.setTimeout(function () { txt = null, typeof jQuery == "undefined" ? b.removeChild(el) : (jQuery(el).fadeOut("slow", function () { jQuery(this).remove() }), otherlib && (window.$jq = jQuery.noConflict())) }, 2500) } if (typeof jQuery != "undefined") return msg = "This page already using jQuery v" + jQuery.fn.jquery, showMsg(); typeof $ == "function" && (otherlib = !0); function getScript(url, success) { var script = document.createElement("script"); script.src = url; var head = document.getElementsByTagName("head")[0], done = !1; script.onload = script.onreadystatechange = function () { !done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") && (done = !0, success(), script.onload = script.onreadystatechange = null, head.removeChild(script)) }, head.appendChild(script) } getScript("//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js", function () { return typeof jQuery == "undefined" ? msg = "Sorry, but jQuery was not able to load" : (msg = "This page is now jQuerified with v" + jQuery.fn.jquery, otherlib && (msg += " and noConflict(). Use $jq(), not $().")), showMsg() }) })();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment