From 85c1ec5e7139acdc99e905b8375f9ef76fa51a9a Mon Sep 17 00:00:00 2001 From: Alexei Date: Wed, 25 Oct 2023 15:00:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A6=D0=B8=D1=82=D0=B0=D1=82=D1=8B=20=D0=B8?= =?UTF-8?q?=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B8=20=D0=B2=20=D0=A0=D0=98?= =?UTF-8?q?=D0=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- news_parser.js | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/news_parser.js b/news_parser.js index 49f8fff..e49f5bb 100644 --- a/news_parser.js +++ b/news_parser.js @@ -60,21 +60,6 @@ return a_String; } - function FinishWorkFuncTemplate(a_OutTag, a_TextAlign, a_ClearTextFunc) { - function FinishWorkFunc(a_Content, a_Element) { - if (a_ClearTextFunc) { - a_Content = a_ClearTextFunc(a_Content); - } - if (a_OutTag && a_TextAlign) { - return '<' + a_OutTag + ' style = "text-align:' + a_TextAlign + ';">' + a_Content + ''; - } - else { - return a_Content; - } - } - return FinishWorkFunc - } - function ClearUrl(a_Url) { var separator = '?'; return RemoveAfterSplitter(a_Url, separator, false); @@ -162,11 +147,11 @@ } function ElementCheckerRia(a_Element) { - if (a_Element.dataset.type == 'text' || a_Element.dataset.type == 'quote' || a_Element.dataset.type == 'list') { - return true; + if (a_Element.dataset.type == 'article' || a_Element.dataset.type == 'banner') { + return false; } - return false; + return true; } function ElementCheckerZV(a_Element) { @@ -176,6 +161,8 @@ return false; } + // Обработка элементов + function GrubTextFuncTemplate() { function GrubTextFunc(a_Element) { var content = ''; @@ -187,19 +174,46 @@ return GrubTextFunc } + function FinishWorkFuncTemplate(a_OutTag, a_TextAlign, a_ClearTextFunc) { + function FinishWorkFunc(a_Content, a_Element) { + if (a_ClearTextFunc) { + a_Content = a_ClearTextFunc(a_Content); + } + if (a_Element && a_Element.dataset && a_Element.dataset.type == 'list') { + var childrens = FindElementsByRegExp(GetElementClassName, 'article__list-item', a_Element); + let content = ''; + for (let i = 0; i < childrens.length; i++) { + var c = childrens[i]; + content += '
  • ' + GrubTextFuncTemplate()(c) + '
  • '; + } + a_Content = ''; + } + + if (a_OutTag && a_TextAlign) { + a_Content = '<' + a_OutTag + ' style = "text-align:' + a_TextAlign + ';">' + a_Content + ''; + } + if (a_Element && a_Element.dataset && a_Element.dataset.type == 'quote') { + a_Content = '
    ' + a_Content + '
    '; + } + + return a_Content; + } + return FinishWorkFunc + } + // Создание контента для стандартных новостей function MakeContentByNews(a_BaseElementTitle, a_BaseElementImage, a_BaseElementText, a_TitleRegExpElementPattern, a_ImageRegExpElementPattern, a_TextRegExpElementPattern, a_ElementChecker, a_ClearTextPatterns) { var title_tag = 'h2'; var p_tag = 'p'; var title_finish_text_func = FinishWorkFuncTemplate(title_tag, 'center') - var grub_text_func = GrubTextFuncTemplate() + var grub_func = GrubTextFuncTemplate(); var content = ''; var paragraph_finish_text_func = FinishWorkFuncTemplate(p_tag, 'justify', ClearTextFuncTemplate(a_ClearTextPatterns)); - content += GetContentInContainers(FindElementsByRegExp(GetElementClassName, a_TitleRegExpElementPattern, a_BaseElementTitle), grub_text_func, title_finish_text_func); + content += GetContentInContainers(FindElementsByRegExp(GetElementClassName, a_TitleRegExpElementPattern, a_BaseElementTitle), grub_func, title_finish_text_func); content += GetImageInContainers(FindElementsByRegExp(GetElementClassName, a_ImageRegExpElementPattern, a_BaseElementImage), 'center'); - content += GetContentInContainers(FIlterElements(FindElementsByRegExp(GetElementClassName, a_TextRegExpElementPattern, a_BaseElementText), a_ElementChecker), grub_text_func, paragraph_finish_text_func); + content += GetContentInContainers(FIlterElements(FindElementsByRegExp(GetElementClassName, a_TextRegExpElementPattern, a_BaseElementText), a_ElementChecker), grub_func, paragraph_finish_text_func); return content; }