Whatsapp contact search

try to take over the world!

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Whatsapp contact search
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @include      https://web.whatsapp.com/?*
// @author       Jop van Dijk
// @grant        none
// @run-at       document-idle
// ==/UserScript==

function waitasec(ms){
    return new Promise(resolve => setTimeout(resolve, ms))
}

async function findContacts() {
    'use strict'
    await waitasec()
    var check = findHim()
    while (check == 0) {
        await waitasec(1000)
        check = findHim()
    }
    if (check == 1) {
        return
    }
    document.getElementById("pane-side").onscroll = function() {findHim()}
    while (check == 2){
        await waitasec(0)
        document.getElementById("pane-side").scrollBy(0,1440);
        check = findHim()
    }
}

function findHim() {
    var name = window.location.href.substr(26,1000).toLowerCase().replace(/\+/g," ")
    console.log(name)
    var found = 0
//     var aantal = document.querySelectorAll("._3H4MS").length
    for (var i=0;document.querySelectorAll("._3H4MS")[i];i=i){
        if (found==0) {found = 2;}
        if (document.querySelectorAll("._3H4MS")[i].innerHTML.toLowerCase().includes(name)) {
            document.querySelectorAll("._3H4MS")[i].parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "block"
            document.querySelectorAll("._3H4MS")[i].parentNode.parentNode.parentNode.parentNode.parentNode.scrollIntoView()
//             await waitasec(300)
            document.querySelectorAll("._3H4MS")[i].parentNode.parentNode.parentNode.parentNode.parentNode.click()
            console.log('found him: ',i)
            found = 1
            i++
            continue
        }else{
            document.querySelectorAll("._3H4MS")[i].parentNode.parentNode.parentNode.parentNode.parentNode.style.display = "none"
            i++
//             document.querySelectorAll("._3H4MS")[i].parentNode.parentNode.parentNode.parentNode.parentNode.remove()
            continue
        }
    }
    return found
}

findContacts()