Browse Source

Исправлена работа ЗВ и имя хоста в инотв #8

master
parent
commit
73036b2973
  1. 18
      news_parser.js

18
news_parser.js

@ -277,9 +277,13 @@
return FinishWorkFunc return FinishWorkFunc
} }
function FinishWorkFuncZV(a_Element, a_ElementIndex) {
return GrubTextFuncTemplate()(a_Element);
}
// Создание контента для стандартных новостей // Создание контента для стандартных новостей
const title_tag = 'h2'; const title_tag = 'h2';
const title_finish_text_func = FinishWorkFuncTemplate(title_tag, 'center') const title_finish_text_func = FinishWorkFuncTemplate(title_tag, 'center');
function MakeContentByNews(a_BaseElementTitle, a_BaseElementImage, a_BaseElementText, a_TitleRegExpElementPattern, a_ImageRegExpElementPattern, a_TextRegExpElementPattern, a_ElementChecker, a_SubElementCheckerToRemove, a_ClearTextPatterns) { function MakeContentByNews(a_BaseElementTitle, a_BaseElementImage, a_BaseElementText, a_TitleRegExpElementPattern, a_ImageRegExpElementPattern, a_TextRegExpElementPattern, a_ElementChecker, a_SubElementCheckerToRemove, a_ClearTextPatterns) {
const p_tag = 'p'; const p_tag = 'p';
@ -300,6 +304,7 @@
let source_add = true; let source_add = true;
const zero_tag_func = FinishWorkFuncTemplate() const zero_tag_func = FinishWorkFuncTemplate()
const grub_text_func = GrubTextFuncTemplate() const grub_text_func = GrubTextFuncTemplate()
let host_name = null;
if (location.hostname == 'tass.ru') { if (location.hostname == 'tass.ru') {
// test: https://tass.ru/proisshestviya/19117971 // test: https://tass.ru/proisshestviya/19117971
@ -399,6 +404,9 @@
), ),
[] []
); );
if (content.length > 0) {
host_name = 'inotv';
}
} }
} }
else if (location.hostname == 'www.cnews.ru') { else if (location.hostname == 'www.cnews.ru') {
@ -422,9 +430,9 @@
} }
else if (location.hostname == 'zakonvremeni.ru') { else if (location.hostname == 'zakonvremeni.ru') {
const base_element = document.getElementsByClassName('item-page')[0]; const base_element = document.getElementsByClassName('item-page')[0];
const title = GetContentInContainers(FindElementsByRegExp(GetElementClassName, 'page-header', base_element), grub_text_func); const title = GetContentInContainers(FindElementsByRegExp(GetElementClassName, 'page-header', base_element), grub_text_func, FinishWorkFuncZV);
const parent_category = GetContentInContainers(FindElementsByRegExp(GetElementClassName, 'parent-category-name', base_element), grub_text_func); const parent_category = GetContentInContainers(FindElementsByRegExp(GetElementClassName, 'parent-category-name', base_element), grub_text_func, FinishWorkFuncZV);
const category = GetContentInContainers(FindElementsByRegExp(GetElementClassName, 'category-name', base_element), grub_text_func); const category = GetContentInContainers(FindElementsByRegExp(GetElementClassName, 'category-name', base_element), grub_text_func, FinishWorkFuncZV);
const page = RemoveAfterSplitter(TrimString(document.getElementsByClassName('item-page')[0].querySelector('[itemprop=articleBody]').textContent), '.', true); const page = RemoveAfterSplitter(TrimString(document.getElementsByClassName('item-page')[0].querySelector('[itemprop=articleBody]').textContent), '.', true);
content = title + '\n' + parent_category + ' ' + category + '\n\n' + page + '\n' + document.URL; content = title + '\n' + parent_category + ' ' + category + '\n\n' + page + '\n' + document.URL;
source_add = false; source_add = false;
@ -434,7 +442,7 @@
if (content.length > 0) { if (content.length > 0) {
result = '<textarea id = "news_content" rows="10" cols="100">' + content; result = '<textarea id = "news_content" rows="10" cols="100">' + content;
if (source_add) { if (source_add) {
result += '<p style="text-align: justify;">Источник: <a href = "' + ClearUrl(document.URL) + '">' + location.hostname + '</a></p>'; result += '<p style="text-align: justify;">Источник: <a href = "' + ClearUrl(document.URL) + '">' + (host_name || location.hostname) + '</a></p>';
} }
result += '</textarea>'; result += '</textarea>';
} }

Loading…
Cancel
Save