简体   繁体   English

了解如何开发“ WhatsApp Web”前端页面

[英]Understanding how “WhatsApp Web” front-end page was developed

I'm trying to understand how the WhatsApp Web front-end page was created, especially the list of contacts on the left side ( <div id="pane-side"> ). 我试图了解WhatsApp Web前端页面是如何创建的,尤其是左侧的联系人列表( <div id="pane-side"> )。 The name of the contacts uses the class "emojitext ellipsify" and I am trying to get the name of all contacts by the code: 联系人的名称使用"emojitext ellipsify"类,我正在尝试通过代码获取所有联系人的名称:

var contatosTemp = document.getElementsByClassName('emojitext ellipsify');
var contatos = [];
for (var i = 0; i < contatosTemp.length; i = i + 2) { contatos.push(contatosTemp[i].innerText); }
contatos

If the scroll of the list of contacts is at top, the number of contatos are 19 . 如果联系人列表的滚动位于顶部,则contatos的数量为19 But if I scroll the list, the number of contatos is increased until the number of 29 . 但是,如果我滚动列表,则会增加contatos的数量,直到29为止。 If I minimize the window, the number of contatos is decreased to 15 . 如果我最小化窗口,则contatos的数量将减少到15

At resume, the number of the list of contacts caught by the JavaScript above changes when the user scrolls the list of contacts. 在恢复时,当用户滚动联系人列表时,上述JavaScript捕获的联系人列表数会更改。

If you want to understand what I am doing, open your WhatsApp Web , go to browser DevTools > Console and run the JavaScript above. 如果您想了解我在做什么,请打开WhatsApp Web ,转到浏览器DevTools> Console并运行上面的JavaScript。

You will see the size of the array contatos : 您将看到数组contatos的大小:

Then scroll the pane at left side of screen and execute the JavaScript again. 然后滚动屏幕左侧的窗格,然后再次执行JavaScript。 It will show that the array size changed. 它将显示数组大小已更改。

I would like to get all the contacts' names but JavaScript only gets part of it. 我想获取所有联系人的姓名,但是JavaScript仅包含其中一部分。 How can I do that? 我怎样才能做到这一点?

Use this script that will bring you all the contacts 使用此脚本将带给您所有联系人

function contactList(){
   var user = Store.Chat.models; 
   var destiny = [];

   user.forEach(function(obj){destiny.push(obj.__x_formattedTitle)});
   return destiny }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM