snipt

Ctrl+h for KB shortcuts

JavaScript

jQuerfiy Bookmarklet

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%25",el.style.padding="5px 10px",el.style.zIndex=1001,el.style.fontSize="12px",el.style.color="#222",el.style.backgroundColor="#f99";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.$=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("http://code.jquery.com/jquery-latest.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()})})();
https://snipt.net/embed/77069b54f508601283d6684b6b50bf1f/
/raw/77069b54f508601283d6684b6b50bf1f/
77069b54f508601283d6684b6b50bf1f
js
JavaScript
1
2019-06-24T06:47:34
True
False
False
Oct 25, 2012 at 01:21 PM
/api/public/snipt/49051/
jquerfiy-bookmarklet
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="nx">javascript</span><span class="o">:</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span><span class="kd">var</span> <span class="nx">el</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s2">&quot;div&quot;</span><span class="p">),</span><span class="nx">b</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">&quot;body&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span><span class="nx">otherlib</span><span class="o">=!</span><span class="mi">1</span><span class="p">,</span><span class="nx">msg</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">;</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">position</span><span class="o">=</span><span class="s2">&quot;fixed&quot;</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">height</span><span class="o">=</span><span class="s2">&quot;32px&quot;</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">width</span><span class="o">=</span><span class="s2">&quot;220px&quot;</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">marginLeft</span><span class="o">=</span><span class="s2">&quot;-110px&quot;</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">top</span><span class="o">=</span><span class="s2">&quot;0&quot;</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">left</span><span class="o">=</span><span class="s2">&quot;50%25&quot;</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">padding</span><span class="o">=</span><span class="s2">&quot;5px 10px&quot;</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">zIndex</span><span class="o">=</span><span class="mi">1001</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">fontSize</span><span class="o">=</span><span class="s2">&quot;12px&quot;</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">color</span><span class="o">=</span><span class="s2">&quot;#222&quot;</span><span class="p">,</span><span class="nx">el</span><span class="p">.</span><span class="nx">style</span><span class="p">.</span><span class="nx">backgroundColor</span><span class="o">=</span><span class="s2">&quot;#f99&quot;</span><span class="p">;</span><span class="kd">function</span> <span class="nx">showMsg</span><span class="p">(){</span><span class="kd">var</span> <span class="nx">txt</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">createTextNode</span><span class="p">(</span><span class="nx">msg</span><span class="p">);</span><span class="nx">el</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">txt</span><span class="p">),</span><span class="nx">b</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">el</span><span class="p">),</span><span class="nb">window</span><span class="p">.</span><span class="nx">setTimeout</span><span class="p">(</span><span class="kd">function</span><span class="p">(){</span><span class="nx">txt</span><span class="o">=</span><span class="kc">null</span><span class="p">,</span><span class="k">typeof</span> <span class="nx">jQuery</span><span class="o">==</span><span class="s2">&quot;undefined&quot;</span><span class="o">?</span><span class="nx">b</span><span class="p">.</span><span class="nx">removeChild</span><span class="p">(</span><span class="nx">el</span><span class="p">)</span><span class="o">:</span><span class="p">(</span><span class="nx">jQuery</span><span class="p">(</span><span class="nx">el</span><span class="p">).</span><span class="nx">fadeOut</span><span class="p">(</span><span class="s2">&quot;slow&quot;</span><span class="p">,</span><span class="kd">function</span><span class="p">(){</span><span class="nx">jQuery</span><span class="p">(</span><span class="k">this</span><span class="p">).</span><span class="nx">remove</span><span class="p">()}),</span><span class="nx">otherlib</span><span class="o">&amp;&amp;</span><span class="p">(</span><span class="nb">window</span><span class="p">.</span><span class="nx">$</span><span class="o">=</span><span class="nx">jQuery</span><span class="p">.</span><span class="nx">noConflict</span><span class="p">()))},</span><span class="mi">2500</span><span class="p">)}</span><span class="k">if</span><span class="p">(</span><span class="k">typeof</span> <span class="nx">jQuery</span><span class="o">!=</span><span class="s2">&quot;undefined&quot;</span><span class="p">)</span><span class="k">return</span> <span class="nx">msg</span><span class="o">=</span><span class="s2">&quot;This page already using jQuery v&quot;</span><span class="o">+</span><span class="nx">jQuery</span><span class="p">.</span><span class="nx">fn</span><span class="p">.</span><span class="nx">jquery</span><span class="p">,</span><span class="nx">showMsg</span><span class="p">();</span><span class="k">typeof</span> <span class="nx">$</span><span class="o">==</span><span class="s2">&quot;function&quot;</span><span class="o">&amp;&amp;</span><span class="p">(</span><span class="nx">otherlib</span><span class="o">=!</span><span class="mi">0</span><span class="p">);</span><span class="kd">function</span> <span class="nx">getScript</span><span class="p">(</span><span class="nx">url</span><span class="p">,</span><span class="nx">success</span><span class="p">){</span><span class="kd">var</span> <span class="nx">script</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s2">&quot;script&quot;</span><span class="p">);</span><span class="nx">script</span><span class="p">.</span><span class="nx">src</span><span class="o">=</span><span class="nx">url</span><span class="p">;</span><span class="kd">var</span> <span class="nx">head</span><span class="o">=</span><span class="nb">document</span><span class="p">.</span><span class="nx">getElementsByTagName</span><span class="p">(</span><span class="s2">&quot;head&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">],</span><span class="nx">done</span><span class="o">=!</span><span class="mi">1</span><span class="p">;</span><span class="nx">script</span><span class="p">.</span><span class="nx">onload</span><span class="o">=</span><span class="nx">script</span><span class="p">.</span><span class="nx">onreadystatechange</span><span class="o">=</span><span class="kd">function</span><span class="p">(){</span><span class="o">!</span><span class="nx">done</span><span class="o">&amp;&amp;</span><span class="p">(</span><span class="o">!</span><span class="k">this</span><span class="p">.</span><span class="nx">readyState</span><span class="o">||</span><span class="k">this</span><span class="p">.</span><span class="nx">readyState</span><span class="o">==</span><span class="s2">&quot;loaded&quot;</span><span class="o">||</span><span class="k">this</span><span class="p">.</span><span class="nx">readyState</span><span class="o">==</span><span class="s2">&quot;complete&quot;</span><span class="p">)</span><span class="o">&amp;&amp;</span><span class="p">(</span><span class="nx">done</span><span class="o">=!</span><span class="mi">0</span><span class="p">,</span><span class="nx">success</span><span class="p">(),</span><span class="nx">script</span><span class="p">.</span><span class="nx">onload</span><span class="o">=</span><span class="nx">script</span><span class="p">.</span><span class="nx">onreadystatechange</span><span class="o">=</span><span class="kc">null</span><span class="p">,</span><span class="nx">head</span><span class="p">.</span><span class="nx">removeChild</span><span class="p">(</span><span class="nx">script</span><span class="p">))},</span><span class="nx">head</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">script</span><span class="p">)}</span><span class="nx">getScript</span><span class="p">(</span><span class="s2">&quot;http://code.jquery.com/jquery-latest.min.js&quot;</span><span class="p">,</span><span class="kd">function</span><span class="p">(){</span><span class="k">return</span> <span class="k">typeof</span> <span class="nx">jQuery</span><span class="o">==</span><span class="s2">&quot;undefined&quot;</span><span class="o">?</span><span class="nx">msg</span><span class="o">=</span><span class="s2">&quot;Sorry, but jQuery was not able to load&quot;</span><span class="o">:</span><span class="p">(</span><span class="nx">msg</span><span class="o">=</span><span class="s2">&quot;This page is now jQuerified with v&quot;</span><span class="o">+</span><span class="nx">jQuery</span><span class="p">.</span><span class="nx">fn</span><span class="p">.</span><span class="nx">jquery</span><span class="p">,</span><span class="nx">otherlib</span><span class="o">&amp;&amp;</span><span class="p">(</span><span class="nx">msg</span><span class="o">+=</span><span class="s2">&quot; and noConflict(). Use $jq(), not $().&quot;</span><span class="p">)),</span><span class="nx">showMsg</span><span class="p">()})})();</span> </span></pre></div> </td></tr></table>
bookmarklet, javascript, jquery