--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/109bd8d4-bb37-4c08-a341-75c677702c3bn%40chromium.org.
I can do this defining a callback function on the page load event. You can do it this way :
var loadfunction = window.onload;Or this way :
window.addEventListener("load", function load(event){
waitForElm('[name=filter]').then((elm) => {
var list = document.getElementsByName("filter");
for (var i = 0; i < list.length; i++) list[i].click();
waitForElm('.ui-icon.ui-icon-pencil.tiptip').then((elm) => {
var list = document.getElementsByClassName("ui-icon ui-icon-pencil tiptip");
for (var i=0; i<list.length; i++) list[i].click();
waitForElmByTextContent('Configuration').then((elm) => {
for(var i = 0, len = document.links.length; i < len; i += 1) {
if(document.links[i].textContent === "Configuration ") {
document.links[i].click();
}
}
waitForElm('[name=configurations]').then((elm) => {
var x = document.getElementsByName("configurations[]");
var i;
for (i = 0; i < x.length; i++) {
if (x[i].type == "checkbox") {
x[i].checked = true;
}
}
});
});
});
});
function waitForElm(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer1 = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer1.disconnect();
}
});
observer1.observe(document.body, {
childList: true,
subtree: true
});
});
}
function waitForElmByTextContent(searchText) {
return new Promise(resolve => {
let foundEl = foundElement(text);
if (foundEl) {
return resolve(foundEl);
}
const observer1 = new MutationObserver(mutations => {
let foundEl = foundElement(text);
if (foundEl) {
resolve(foundEl);
observer1.disconnect();
}
});
observer1.observe(document.body, {
childList: true,
subtree: true
});
});
}
function foundElement(text) {
for (var i = 0, len = document.links.length; i < len; i += 1) {
if (document.links[i].textContent === "Configuration ") {
return document.links[i];
}
}
return null;
}
For more details about this subject, here is the source code with screenshots of the 4 buttons
Button 1 “Rechercher”
Button 2 “Editer”
Button 3 “Configuration”
Button 4 “checkbox M and D”
I manage to click the buttons with the following code but I can’t manage to configure a setTimeout to wait for the buttons are displayed before the clicks.
//Button 1 "Rechercher"
var list = document.getElementsByName("filter");
for (var i=0; i<list.length; i++) list[i].click();
//Button 2 "Editer"
var list = document.getElementsByClassName("ui-icon ui-icon-pencil tiptip");
for (var i=0; i<list.length; i++) list[i].click();
//Button 3 "Configuration"
for(var i = 0, len = document.links.length; i < len; i += 1) {
if(document.links[i].textContent === "Configuration ") {
document.links[i].click();
}
}
//Button 4 "checkbox M and D"
var x = document.getElementsByName("configurations[]");
var i;
for (i = 0; i < x.length; i++) {
if (x[i].type == "checkbox") {
x[i].checked = true;
}
}
Here is the content of my Chrome extension:
manifest.json
{popup.html
<!doctype html>popup.js
extension.js
chrome.runtime.onMessage.addListener(as you can see on the extension.js file I have the number 1 function which is executed for example on the website: https://www.gsmarena.com/
I have to write in the search field the word google then press the go button and I have to wait for the result then press the model google_pixel_7_pro.
I used the setTimeout method but without success the code stops after the second click here is a demonstration video in gif format
A demonstration video in gif format
I hope I have explained my need well and thank you for your help.