Created
August 3, 2012 20:29
-
-
Save vndmtrx/3251272 to your computer and use it in GitHub Desktop.
Bookmarklet para inserção e verificação de jQuery na página.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var outralib = false; | |
var msg = ''; | |
var criapainel = function() { | |
var div = document.createElement("div"); | |
div.style.zIndex = 1001; | |
div.style.backgroundColor='#c90'; | |
div.style.color='#fff'; | |
div.style.fontFamily = 'sans-serif'; | |
div.style.height='64px'; | |
div.style.width='500px'; | |
div.style.padding='5px 10px'; | |
div.style.position='absolute'; | |
div.style.top = '10px'; | |
div.style.left = '0px'; | |
div.style.right = '0px'; | |
div.style.margin = '0 auto'; | |
return div; | |
}; | |
var baixascript = function(url, sucesso) { | |
var head = document.getElementsByTagName('head')[0]; | |
var pronto = false; | |
var script = document.createElement("script"); | |
script.src = url; | |
script.onload = script.onreadystatechange = function() { | |
// Removendo o script de carregamento de dentro da página depois de | |
//carregar o jQuery | |
if (!pronto && (!this.readyState | |
|| this.readyState == 'loaded' | |
|| this.readyState == 'complete')) { | |
pronto = true; | |
sucesso(); // Funcao externa | |
script.onload = script.onreadystatechange = null; | |
head.removeChild(script); | |
} | |
}; | |
head.appendChild(script); | |
}; | |
mostramensagem = function(mensagem) { | |
var body = document.getElementsByTagName('body')[0]; | |
var quadro = criapainel(); | |
quadro.innerHTML = '<span style="color:#fff;">' + mensagem + '</span>'; | |
quadro.innerHTML += '<br><div style="text-align:center;">'; | |
quadro.innerHTML += '<a href="http://www.tocadoelfo.com.br">#tocadoelfo</a></div>'; | |
body.appendChild(quadro); | |
window.setTimeout(function() { | |
if (typeof jQuery == 'undefined') { | |
body.removeChild(quadro); | |
} else { | |
jQuery(quadro).fadeOut('slow', function() { | |
jQuery(this).remove(); | |
}); | |
if (outralib) { | |
$jq=jQuery.noConflict(); | |
} | |
} | |
}, 10000); | |
}; | |
//---------------------------------------------------------------------------- | |
if(typeof jQuery != 'undefined') { | |
msg = 'Essa pagina atualmente usa jQuery v' + jQuery.fn.jquery; | |
return mostramensagem(msg); | |
} else if (typeof $ == 'function') { | |
outralib = true; | |
} | |
baixascript('//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', function() { | |
msg = ''; | |
if (typeof jQuery == 'undefined') { | |
msg = 'Nao foi possivel carregar o jQuery'; | |
} else { | |
msg = 'jQuery carregado na versao v' + jQuery.fn.jquery; | |
if (outralib) { | |
msg += ' usando noConflict(). Use $jq() no lugar de $().'; | |
} | |
} | |
return mostramensagem(msg); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment