Get name and message from whatsapp via DOM JS
unknown
javascript
a year ago
1.8 kB
7
Indexable
const objects = document.getElementsByClassName('_amk6')
const childrenObject = []
for (let i = 0; i < objects.length; i++) {
childrenObject[i] = objects[i].children
}
const dataArray = [];
for (let i = 0; i < childrenObject.length; i++) {
if (childrenObject[i][0].nodeName == "DIV") {
console.log("kena")
if (childrenObject[i][0].children[0].children[0].children.length == 2) {
const newObject = {
name: childrenObject[i - 1][0].ariaLabel, // Ngambil ariaLabel yang berisi username
message: childrenObject[i][0].children[0].children[0].children[1].innerText // Ngambil isi text dalam div
};
dataArray.push(newObject);
} else {
const newObject = {
name: childrenObject[i - 1][0].ariaLabel, // Ngambil ariaLabel yang berisi username
message: childrenObject[i][0].children[0].children[0].innerText // Ngambil isi text dalam div
};
dataArray.push(newObject);
}
} else {
if (childrenObject[i][1].children[0].children[0].children.length == 2) {
const newObject = {
name: childrenObject[i][0].ariaLabel, // Ngambil ariaLabel yang berisi username
message: childrenObject[i][1].children[0].children[0].children[1].innerText // Ngambil isi text dalam div
};
dataArray.push(newObject);
} else {
const newObject = {
name: childrenObject[i][0].ariaLabel, // Ngambil ariaLabel yang berisi username
message: childrenObject[i][1].children[0].children[0].innerText // Ngambil isi text dalam div
};
dataArray.push(newObject);
}
}
}
console.log(dataArray);Editor is loading...
Leave a Comment