Skip to content

Instantly share code, notes, and snippets.

@danielfilho
Last active August 29, 2015 13:56
Show Gist options
  • Save danielfilho/8957900 to your computer and use it in GitHub Desktop.
Save danielfilho/8957900 to your computer and use it in GitHub Desktop.
inject an external css

Como usar

  • Crie um servidor HTTP no diretório: css/
  • Rode na raiz do projeto: $ compass watch
  • Rode este snippet/bookmarklet no celular e aponte para o endereço do servidor de CSS da seguinte forma:

Caso seu IP na rede (a mesma que o celular está conectado) seja: 192.168.10.10 e seu servidor HTTP foi criado na porta 3333, o endereço que deverá entrar no celular é: http://192.168.10.10:3333/mediaqueries.css

Isso irá injetar a tag para o CSS mobile no final da tag <HEAD>, certificando que ele será a última regra de CSS carregada e irá sobrescrever as regras nativas.

Qualquer dúvida, orem pra pai oxalá ogum de pai-mei-san.

PS: parece que pra Iemanjá também funciona.

javascript:(function()%7B(function()%7Bvar%20theElement%20%3D%20document.getElementById('injectedcss')%2CtheHeader%20%3D%20document.querySelector('head')%3Bif%20(theElement)%20%7BtheElement.parentNode.removeChild(theElement)%3BtheElement.href%20%2B%3D%20'%3F'%20%2B%20new%20Date().getTime()%3BtheHeader.appendChild(theElement)%3Bconsole.log('CSS%20reloaded')%3B%7D%20else%20%7Bvar%20linkElement%20%3D%20document.createElement('link')%2CcssURL%20%3D%20prompt('Enter%20the%20remote%20CSS%20URL.%5CnDon%5C't%20type%20the%20.CSS%20extension.'%2C%20'http%3A%2F%2F')%3Bif%20(cssURL.indexOf%20%3C%200)%20%7BcssURL%20%2B%3D%20'.css'%20%2B%20'%3F'%20%2B%20new%20Date().getTime()%3B%7D%20else%20%7BcssURL%20%2B%3D%20'%3F'%20%2B%20new%20Date().getTime()%3B%7DlinkElement.id%20%3D%20'injectedcss'%3BlinkElement.rel%20%3D%20'stylesheet'%3BlinkElement.href%20%3D%20cssURL%3BtheHeader.appendChild(linkElement)%3B%7D%7D)()%7D)()
(function(){
var theElement = document.getElementById('injectedcss'),
theHeader = document.querySelector('head');
if (theElement) {
theElement.parentNode.removeChild(theElement);
theElement.href += '?' + new Date().getTime();
theHeader.appendChild(theElement);
console.log('CSS reloaded');
} else {
var linkElement = document.createElement('link'),
cssURL = prompt('Enter the remote CSS URL.\nDon\'t type the .CSS extension.', 'http://');
if (cssURL.indexOf < 0) {
cssURL += '.css' + '?' + new Date().getTime();
} else {
cssURL += '?' + new Date().getTime();
}
linkElement.id = 'injectedcss';
linkElement.rel = 'stylesheet';
linkElement.href = cssURL;
theHeader.appendChild(linkElement);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment