[Скрипты]Скрипт считающий реакции на всех комментариях

[Скрипты]Скрипт считающий реакции на всех комментариях
const reactions_lib = [ 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //0 'https://leonardo.osnova.io/5c63be49-162a-5e4e-adca-9b9c3f76314c/-/preview/700x/', //1 - сердце 'https://leonardo.osnova.io/b9e9a5d6-cfbc-5d11-9b31-edad6bb6fbf0/-/preview/700x/', //2 - огонь 'https://leonardo.osnova.io/133c8232-843b-5f6b-80bd-f1f31d633892/-/preview/700x/', //3 - смайл плач 'https://leonardo.osnova.io/15ad35e5-1708-58a5-a25a-d419cdd2d46a/-/preview/700x/', //4 - смайл смех 'https://leonardo.osnova.io/0f3a998f-1441-5f0f-8a5b-549bbf170c65/-/preview/700x/', //5 - смайл злость 'https://leonardo.osnova.io/2d62d1ab-8ec6-5f17-81f8-6f6f3312d283/-/preview/700x/', //6 - пикачу 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', // 7 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //8 'https://leonardo.osnova.io/080e8489-f354-52f3-b495-d3901aa329b3/-/preview/700x/', //9 - попкорн 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', // 10 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //11 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //12 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //13 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //14 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //15 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //16 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //17 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //18 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //19 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //20 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //21 'https://leonardo.osnova.io/7f766c9a-3720-5eaf-9a1a-3d0038876af7/-/preview/700x/', //22 - смайл в очках 'https://leonardo.osnova.io/88faa3a8-281d-5f0d-8e9f-bd23d541d33b/-/preview/700x/', //23 - смайл в покерфейс 'https://leonardo.osnova.io/36cfdc28-ced9-5e6f-8195-e75975bc9f31/-/preview/700x/', //24 - глаза 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', // 25 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //26 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //27 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //28 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //29 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //30 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //31 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //32 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //33 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //34 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //35 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //36 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //37 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //38 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //39 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //40 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //41 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //42 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //43 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //44 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //45 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //46 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //47 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //48 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //49 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //50 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //51 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //52 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //53 'https://leonardo.osnova.io/abbcfa35-9c72-5cfb-9f6b-eff11b904d9c/-/preview/1300x/-/format/raw/', //54 ]; async function main() { let ls_user = localStorage.getItem('user'); if (!ls_user) {alert('Войдите на сайт'); return;} let user = JSON.parse(ls_user); if (!user || !user.id) {alert('Войдите на сайт'); return;} const user_id = user.id; const delay_time_ms = 1000; let status = 'Загружаем...'; let reactions = []; for (let k = 0; k < 54; k++) {reactions[k]={id:k, counter:0, icon:reactions_lib[k] };} let reactions_count = 0; //let max_reactions = 50; let must_break = false; let last_sorting_value = 0; let last_id = 0; create_form(); let results_form__table = document.getElementById('results_form__table'); let results_form__status = document.getElementById('results_form__status'); while (true) { let link = 'https://api.dtf.ru/v2.5/comments?sorting=new&subsiteId=' + user_id; if (last_sorting_value !== 0) { link = 'https://api.dtf.ru/v2.5/comments?sorting=new&subsiteId=' + user_id + '&lastSortingValue=' + last_sorting_value + '&lastId=' + last_id; } await delay(delay_time_ms); const response = await fetch(link); const response_json = await response.json(); //console.log(response_json); if (response_json.result === undefined || response_json.result.items === undefined || response_json.result.items.length === undefined || response_json.result.items.length === 0 || response_json.result.items[response_json.result.items.length-1].id === last_id) { must_break = true; } else { last_sorting_value = response_json.result.lastSortingValue; last_id = response_json.result.lastId; for (let k = 0; k < response_json.result.items.length; k++) { //если коммент до 2024 - заканчиваем if (response_json.result.items[k].date < 1704031200) { //01.01.2024 must_break = true; break; } const counters = response_json.result.items[k].reactions.counters; for (let c = 0; c < counters.length; c++) { if (c === counters.length-1) { status = `Считаем реакции. Последний коммент дата - ${format_ts(response_json.result.items[k].date)}`; } if (!counters[c].count) continue; //0 реакций if (counters[c].id === 1) continue; //простые сердечки пропускаем reactions[counters[c].id].counter += counters[c].count; reactions_count += counters[c].count; /* if (reactions_count>max_reactions) { reactions[counters[c].id].counter += counters[c].count - (reactions_count - max_reactions); must_break = true; break; } else { reactions[counters[c].id].counter += counters[c].count; } */ } if (must_break) break; } } update_form(); if (must_break) break; } status = 'Готово!'; update_form(); //console.log(reactions); function create_form() { let body = document.querySelector("body"); let results = document.createElement("div"); results.className = "results_form__wrapper"; body.innerHTML = ''; body.appendChild(results) let $innerHTML = ` <div class="results_form"> <div class="results_form_colomns__wrapper">`; $innerHTML += ` <div class="results_form_colomn"> <div id="results_form__status" ></div> <h1>Реакции</h1> <div class="table"> <div class="table__row table__row--header"> <div class="table__cell"> </div> <div class="table__cell"> <strong>Реакция</strong> </div> <div class="table__cell"> <strong>Кол-во</strong> </div> <div class="table__cell"> <strong>%</strong> </div> </div> <div class="table__content__wrapper"> <div id="results_form__table" ></div> </div> </div> </div>`; $innerHTML += ` </div> </div> `; results.innerHTML = $innerHTML; const style = document.createElement('style'); style.innerHTML = ` .results_form { width: 1200px; margin: 0 auto; padding: 30px; } .results_form_colomns__wrapper { display: flex; } .results_form_colomn{ display: flex; flex-direction: column; margin: 0 auto; } .results_form h1 { text-align:center; font-size:30px; margin: 20px 0; } .results_form .table { display: flex; flex-direction: column; font-size: 15px; line-height: 1.5em; width: 300px; height: 750px; margin: auto; } .table__content { display: flex; flex-direction: column; } .table__row { display: -ms-flexbox; display: flex; align-items: center; padding: 5px 0; } .table__cell { -ms-flex-preferred-size: 0%; flex-basis: 0%; -ms-flex-positive: 1; flex-grow: 1; -ms-flex-negative: 0; flex-shrink: 0; display: -ms-flexbox; display: flex; min-width: 0; } .table__cell img { width:40px; } `; document.head.appendChild(style); } function update_form() { results_form__status.innerHTML= `<p>${status}<p>`; //сортируем массив const sorted_reactions = [...reactions]; sorted_reactions.sort((a,b)=> (a.counter < b.counter ? 1 : -1)); let $innerHTML=''; for (let j=0; j<sorted_reactions.length; j++) { if (sorted_reactions[j].counter === 0 ) break; $innerHTML +=` <div class="table__row"> <div class="table__cell"> <span>${j+1}</span> </div> <div class="table__cell"> <img src="${sorted_reactions[j].icon}" > </div> <div class="table__cell"> <span>${sorted_reactions[j].counter}</span> </div> <div class="table__cell"> <span>${(sorted_reactions[j].counter/reactions_count*100).toFixed(2)}%</span> </div> </div>`; } results_form__table.innerHTML = $innerHTML; } } main(); //функция для паузы function delay(milliseconds){ return new Promise(resolve => { setTimeout(resolve, milliseconds); }); } function format_ts($ts) { const date = new Date($ts * 1000); const months = ['Янв','Фев','Мар','Апр','Май','Июн','Июл','Авг','Сен','Окт','Ноя','Дек']; const year = date.getFullYear(); const month = date.getMonth(); const day = date.getDate(); return (`${day}/${months[month]}/${year}`); }

Как запустить:

Скопировать и вставить в консоль браузера. Запустить.

Проверено работает в Firefox и Chrome.

  • Считает только реакции на комментариях(можно доработать).
  • Не считает простые лайки(сердечки)(можно раскомментировать).
  • Все "платные" реакции отображаются реакцией "звёздочка"(можно доработать.).
99
66
55
22
11
11
11
15 комментариев

Ээээ... Зачем?

2
1

А это, детектив, правильный вопрос.

2

Ето для умных кто сам холодильник починить может

2