More short click version

 avatar
user_0634698
javascript
20 days ago
1.1 kB
0
Indexable
Never
const elements = document.querySelectorAll('[role="listitem"]');
for (let i = 0; i < elements.length; i++) {
    elements[i].addEventListener("click", function() {
        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++) {
            // Jika pesan tidak memiliki span ariaLabel maka nama nya ambil dari username sebelumnya
            const newObject = {
                name: childrenObject[childrenObject[i][0].nodeName == "DIV" ? i - 1 : i][0].ariaLabel, // Ngambil ariaLabel yang berisi username,
                message: childrenObject[i][childrenObject[i][0].nodeName == "DIV" ? 0 : 1].children[0].children[0].children.length == 2 ? childrenObject[i][1].children[0].children[0].children[1].innerText : childrenObject[i][1].children[0].children[0].innerText
            }
            dataArray.push(newObject);
        }
        
        console.log(dataArray);
    });
}
Leave a Comment