1
Good afternoon!
I’m trying to create an extension to automatically click a one-page button every X seconds. In my case is a working tool called Servicenow, where there are panels with reports in real time, but the menu where are the calls I have to answer does not update alone, only if you click a button with Refresh icon.
The problem is that it does not perform the function it should (I believe it is a problem in querySelector).
div do botão
<div class="header-tools" style="background-color: #1d7f00">
<button tabindex="0" class="btn header-icon icon-refresh" style="color: #FFFFFF" aria-label="Atualizar Widget Dashboard Fila Atendimento - Incidentes" title="" data-original-title="Atualizar"></button>
</div>
manifest.json
{
"manifest_version": 2,
"name": "Auto Refresh - ServiceNow",
"description": "Extensão para o Google Chrome que atualiza automaticamente o ServiceNow.",
"version": "1.1",
"icons": {
"128": "128.png"
},
"content_scripts": [{
"matches": ["https://renner.service-now.com/*"],
"js": ["autorefresh-servicenow.js"]
}]
}
autorefresh-servicenow.js
;(function( doc ) {
'use strict';
console.log( "Auto Refresh - ServiceNow" );
var $autorefreshsn;
window.setInterval(function() {
var $autorefreshsn = document.querySelector('button.btn.header-icon.icon-refresh::before');
if( ! $autorefreshsn ) {
return;
}
$autorefreshsn.click();
}, 3000);
})( document );
Obs: I’ve tried without the
::before
, I tried only with the class.header-tools
and even by the attribute[style="background-color: #1d7f00"]
but nothing helped.
Show! And how do I select with the attribute too? In case the same I put there. There are 5 buttons on this page, 4 of them in the panels that are real-time (wtf?) and the one that is left to update the Dashboard. I would have to select it in specific and the only distinction is the style="background-color: #1d7f00".
– Roger Windberg
@Rogerwindberg the
aria-label
anddata-original-title
are the same in all?– Renan Gomes
The
data-original-title
are equal in all but thearia-label
is unique to each.– Roger Windberg
@Rogerwindberg can make the query for him so I edited the answer.
– Renan Gomes
@Rogerwindberg a tip: if you need to interact with the page that doesn’t need to use any "low-level" API extensions use, it’s easier to create a userscript than an extension. Even as an example, I have a script to automatically rescue channel points on Twitch (which is basically the same thing your script does): example
– Renan Gomes
I tried everything here with the tips but it still didn’t work, it seems that he doesn’t recognize the selector at all. The goal of creating an extension is for me to be able to "fix" these page flaws and be able to share with the work team afterwards.
– Roger Windberg
A userscript can also be installed by multiple people and versioned. As for the selector question, the question you asked, what you can answer is this.
– Renan Gomes
I get it. I’m very uneducated in this subject of programming and this is my first attempt to build a code. How does this userscript work? I have no idea where to apply and what to do with it.
– Roger Windberg
@Rogerwindberg in the readme of this link I gave you, has an explanation of how to install a userscript.
– Renan Gomes