Estoy aprendiendo a crear una extensión de Chrome. Quiero crear una extensión para encontrar un botón y mostrar alertas que lo encontraron
el boton es
<button class="bt bt-sm text-white btn-flashing" style="background-color: #fd7e14; margin:3px" disabled="">ABC - 01</button>Entonces, ¿cómo puedo escribir un script para encontrar eso?
Tengo un script para mostrar la alerta.
chrome.browserAction.onClicked.addListener(function() { alert("found it"); })Gracias.
chrome.browserAction.onClicked.addListener(function() { //Checking if there are any results of the button with that class if(document.querySelectorAll('.bt bt-sm text-white btn-flashing').length >= 1){ //Found results of the button }else{ //Found no results of the button });Todo este código dice que si hay más de 0 ocurrencias de ".bt bt-sm text white btn-flashing", entonces encontró resultados.
Puede utilizar un script de contenido para comprobar la presencia del botón.
Por ejemplo:
chrome.browserAction.onClicked.addListener(function(){ chrome.tabs.executeScript({ code: 'document.querySelector("button.bt.bt-sm.text-white.btn-flashing")' }, function(result) { if (result[0]) { alert('found it'); } else { alert('not found'); } }); });