innocoffee / Avito Phone replacer

// ==UserScript==
// @name         Avito Phone replacer
// @namespace    http://tampermonkey.net/
// @version      0.1
// @license      GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @copyright    2020, innocoffee (https://t.me/innocoffee)
// @description  Replaces 'Call' button link href to normal phone
// @author       t.me/innocoffee
// @include        https://m.avito.ru/*
// @grant        none
// ==/UserScript==

function init (e){
    document.querySelector('a[data-marker="item-contact-bar/call"]').click();
    var second_interval = setInterval(() => {
        if(document.querySelector('a[data-marker="phone-popup/call-button"]')) {
            var hr = document.querySelector('a[data-marker="phone-popup/call-button"]').href.split('%A0').join('').split('%C2').join('').split('-').join('');
            document.querySelector('a[data-marker="item-contact-bar/call"]').outerHTML = "<a href='" + hr + "'>Открыть ссылку в Задарме</a>";
            document.querySelector('#modal > div').click();
            clearInterval(second_interval);
        }
    }, 100);
}

var interval = setInterval(() => {
    if(document.querySelector('a[data-marker="item-contact-bar/call"]')) {
        init();
        clearInterval(interval);
    }

    if(document.querySelector('[data-marker="search/input"]')) {
        clearInterval(interval);
    }
}, 500);