2
Well, I’m setting up a chat system in Delphi in which I use the Chromium component to load an HTML that I use as the chat history due to lack of visual components in it.
Anyway, in the messages balloons it is possible to notice that old confirmation "V" that is nothing more than the following code:
<i class="material-icons readStatus">done</i>
That is, when the sender visualizes the message, I need to change all "done" to "done_all". I researched a lot and found nothing related to change several texts already printed in HTML, I even found a function that I believed would solve my problem, but for some reason it is not working.
function replaceText(selector, text, newText, flags) {
var matcher = new RegExp(text, flags);
var elems = document.querySelectorAll(selector), i;
for (i = 0; i < elems.length; i++)
if (!elems[i].childNodes.length)
elems[i].innerHTML = elems[i].innerHTML.replace(matcher, newText);
}
function readStatusIcon(oldStatus, newStatus) {
replaceText('*', oldStatus, newStatus, 'g');
}
## Nessa função "readStatusIcon" eu passo ">done<" e ">done_all<" pelo ##
## Delphi para ele não se confundir com outra parte do código ##
<section class="mainApp">
<div class="rightPanel">
<div class="convHistory userBg">
<!-- CONVERSATION GOES HERE! -->
<msg></msg>
<div class="msg messageSent">
EAE
<i class="material-icons readStatus">done</i>
<span class="timestamp">10:20 AM</span>
</div>
<div class="msg messageSent">
EAE
<i class="material-icons readStatus">done</i>
<span class="timestamp">10:20 AM</span>
</div>
<div class="msg messageSent">
EAE
<i class="material-icons readStatus">done</i>
<span class="timestamp">10:20 AM</span>
</div>
</div>
</div>
</section>
The code
@EDIT: Guys, it worked, it’s how our colleague Felipe responded, removing only the !
of that line if (!elems[i].childNodes.length)
, the problem has been solved. Thank you very much!!!
That one
if (!elems[i].childNodes.length)
is correct? Because he will perform the replace, rightly, in us who have no children, maybe!
solve your problem...– Felipe Avelar
It wouldn’t just be a simple substitution? ->
elems[i].textContent = "done_all";
.– Sam
toggleClass does not work?
– flourigh