Last active
June 9, 2018 13:06
-
-
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
This file contains hidden or 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
// ==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