Skip to content

Instantly share code, notes, and snippets.

@pedrofracassi
Last active June 9, 2018 13:06
Show Gist options
  • Save pedrofracassi/b1bc452b871d71519e898e145c320aaa to your computer and use it in GitHub Desktop.
Save pedrofracassi/b1bc452b871d71519e898e145c320aaa to your computer and use it in GitHub Desktop.
Userscript que adiciona um botão para pesquisar a imagem da questão no DNA
// ==UserScript==
// @name DNA Helper
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Adiciona um botão para pesquisar a imagem da questão no DNA
// @author Pedro Fracassi (pedrofracassi.me)
// @match *://www.desafionacional.com.br/*
// @grant none
// ==/UserScript==
(function() {
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
if (document.getElementsByTagName('body')[0].getAttribute('class') == 'tag_body_game') {
var i = document.createElement('button');
i.setAttribute('onclick', 'buttonClicked();');
i.setAttribute('id', 'pesquisa-btn');
i.innerHTML = 'Pesquisar Imagem';
i.addEventListener ("click", () => {
var elemento = getElementByXpath('//*[@id="imagem_questao"]');
var style = elemento.currentStyle || window.getComputedStyle(elemento, false);
var bi = style.backgroundImage.slice(4, -1).replace(/"/g, "");
window.open('https://www.google.com/searchbyimage?&image_url=' + bi);
}, false);
document.getElementsByTagName('body')[0].appendChild(i);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment