如何使用内容脚本过滤 Whatsapp Web 上的聊天?

问题描述 投票:0回答:1

我实际上正在创建一个 chrome 扩展,它会在 Whatsapp Web 中创建一些选项卡,例如“所有”、“未读”、“组”等。当我们选择这些选项卡中的任何一个时,它会过滤掉选项卡左侧底座上的联系人列表。

问题在于 Whatsapp 聊天的 html 结构非常不寻常。它对列表的所有元素使用

position:absolute
并使用
translateY
并将其更改为垂直创建列表。

还有一件事。列表中 html 元素的实际数量最大为 18,最小为 0。我无法理解他们是如何处理这个问题的。

这是我的过滤聊天功能。现在我只有两个标签未读。但它不起作用。当我转到“未读”并返回“全部”时,它显示的结果较少......

const filterChatList = () => {
   //Selects the active tab
   const activeTab = document.querySelector(".ext-tab.active");
   if (activeTab) {
      const chatListWrapper = document.querySelector("._3uIPm"); //The element in which all list items are.
      const name = activeTab.name; //Get the name of tab like "all" | "unread"
      let chatsToShow = [...document.querySelectorAll("._3m_Xw")]; //List of all the items of list

      //Hide all the items first.
      chatsToShow.forEach((x) => {
         x.style.display = "none";
      });
      //Checking if selected tab is "unread"
      if (name === "unread") {
         //Filter out the only chats which have that green unread circle with them
         chatsToShow = chatsToShow.filter((x) => x.querySelector(".aumms1qt"));
      }
      //Change the total height of wrapper
      chatListWrapper.style.height = 72 * chatsToShow.length + "px";
      //Then only display the required items and change their translateY sequentially.
      //Note height of each item is 72.
      chatsToShow.forEach((x, i) => {
         x.style.display = "block";
         x.style.transform = `translateY(${72 * i})`;
      });
   }
};

我不知道如何过滤掉元素的聊天内容。我知道上面的方法是不正确的,因为如果我们选择所有元素,我们只会得到 18 个元素,并且聊天列表可能会更长。

有没有任何库或任何 api 之类的东西,以便我们可以过滤我们想要的结果。许多扩展程序都有此选项卡功能,但代码是捆绑的,所以我无法从中获取任何内容。

如果您知道实现此目标的任何好方法,请告诉我。我会很感激的。如果有任何问题请随时提问。

这是whatsappweb

的链接
javascript html css google-chrome-extension
1个回答
0
投票

嗨先生,您可以使用whatsapp过滤工具

window.WAPI.isValidNumber = async function (phoneId) {
isValid = window.Store.WapQuery.queryExist(phoneId).then(result => {
    return result.jid !== undefined;
}).catch((e) => {
    return false;**strong text**
});

return isValid;

};

我们还找到了一些相关工具供大家参考 whatsapp 过滤器应用程序

© www.soinside.com 2019 - 2024. All rights reserved.