H
H
hibat705702020-05-24 14:19:45
JavaScript
hibat70570, 2020-05-24 14:19:45

How to track page changes?

Good afternoon!
I'm trying to remove links leading to Yandex turbo pages in Yandex search results

$('a[data-sc-host]').each(function() {
    var urlYaTurbo = $(this).attr('href');
    var dataCounter = JSON.parse($(this).attr('data-counter'));
    if ((urlYaTurbo.indexOf('https://yandex.ru/turbo/s/') != -1) || (urlYaTurbo.indexOf('https://yandex.ru/turbo?text=') != -1)) {
        $(this).attr('data-bem', '{"link":{}}');
        if (dataCounter[0] == 'b') {
            $(this).attr('href', dataCounter[1]);
        } else if (dataCounter[0] == 'w') {
            $(this).attr('href', dataCounter[3]);
        }
    }
});

On the first page, the code does its job. But when you click on the "Load more" button, the page is loaded using ajax and this script is no longer applied to it. How can this be fixed?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question