JSFiddle - React, Tailwind, and code Playground

by Константин Дралюк

HTML

Вот таким нехитрым образом я буду проверять все публикации с сайта mystical-stories.ru с webarchieve на уникальность

JavaScript

// Example usage with google and webarchieve
// Stages
// - go to sitemap cache page in webarchieve
// - run first two scripts
// - when it is done run console.log(JSON.stringify(quotes)); , copy
// - open new tab
// - paste last script, replace quotes with stringified json


// TODO
// Ignore empty strings or return
// cut off \n , \r from strings



var urls = [];
$('#d3_container a').each(function(i){
    var h = $(this).attr('href');
    if (h.match(/.html+$/) || h.match(/.html +$/)) {
        urls.push('https://web.archive.org' + h);
    }
});

var quotes = [];
$(urls).each(function(index, item) {
    $('#nav-tophat').load(item + ' #content p:nth-child(2)', function(data){
        var text = $(data).find('p:nth-child(2)').text().slice(0, 80);
        if (!text.trim()) { return false; }
        quotes.push({
          item: item,
          text: text.replace(/[\w\u0430-\u044f]+$/ig, '')
        });
    });
});

/////
quotes.forEach(function(item){
    var search = item;

    var xhr = new XMLHttpRequest();
    xhr.open('GET', 'https://www.googleapis.com/customsearch/v1?key=AIzaSyCR1jIgacjOd6OLfLb9Nt3KYZ8nQ6EWkc4&cx=009731065677694099867:_ux5fw7ltic&q='+search, false);
    xhr.send();

    if (JSON.parse(xhr.responseText).searchInformation.totalResults === "0") {
      console.log(item)
    }
});