From 0b8d0ce4ca29f249ab9b906ab5a394fed0f190a6 Mon Sep 17 00:00:00 2001 From: Alexei Bezborodov Date: Sat, 28 Oct 2023 00:24:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=20=D0=BF=D0=B5=D1=80=D0=B2=D0=BE=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=B1=D0=BB=D0=B8=D0=B6=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B8=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=20rt.com=20#6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- news_parser.js | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/news_parser.js b/news_parser.js index 37ddbd8..9fb4d55 100644 --- a/news_parser.js +++ b/news_parser.js @@ -7,6 +7,7 @@ // @match https://tass.ru/* // @match https://ria.ru/* // @match https://rg.ru/* +// @match https://russian.rt.com/* // @match https://zakonvremeni.ru/* // @icon https://icons.duckduckgo.com/ip2/zakonvremeni.ru.ico // @grant none @@ -178,6 +179,15 @@ function GetClearHtml(a_Element, a_OutTag, a_TextAlign) { let clear_element = a_Element.cloneNode(true); + + let elements = clear_element.querySelectorAll('*'); + elements.forEach(function (element) { + RemoveAllAttributes(element); + if (element && element.parentNode && element.nodeName == 'DIV' && CheckRegExp(GetElementClassName, '.*(read-more|article__cover).*', element)) { + element.parentNode.removeChild(element); + } + }); + let tags_to_delete = ['div', 'span', 'em', 'svg', 'path']; tags_to_delete.forEach(function (del_tag_name) { @@ -187,19 +197,25 @@ }); }); - let elements = clear_element.querySelectorAll('*'); - elements.forEach(function (element) { - RemoveAllAttributes(element); - }); - elements = clear_element.querySelectorAll('a'); - //let re = new RegExp("(https?:\/\/.*)"); elements.forEach(function (element) { if (element.host == location.hostname) { RemoveCurrentElementSaveChild(element, clear_element); } }); + let tags_to_align = ['p', 'h2']; + + tags_to_align.forEach(function (align_tag_name) { + let elements = clear_element.querySelectorAll(align_tag_name); + elements.forEach(function (element) { + element.style.textAlign = a_TextAlign; + if (element.innerHTML == ' ' || element.innerHTML == '') { + element.parentNode.removeChild(element); + } + }); + }); + let result = clear_element.innerHTML; if (a_OutTag && a_TextAlign) { result = '<' + a_OutTag + ' style = "text-align:' + a_TextAlign + ';">' + result + ''; @@ -218,12 +234,12 @@ if (a_ClearTextFunc) { a_Content = a_ClearTextFunc(a_Content); } - if (a_Element && CheckRegExp(GetElementClassName, 'PageContentCommonStyling_text.*', a_Element)) { + if (a_Element && CheckRegExp(GetElementClassName, '(PageContentCommonStyling_text.*)', a_Element)) { let content = ''; - let childrens = FindElementsByRegExp(GetNodeName, 'P', a_Element); + let childrens = FindElementsByRegExp(GetNodeName, '(P)', a_Element); for (let i = 0; i < childrens.length; i++) { let c = childrens[i]; - content += FinishWorkFunc(GrubTextFuncTemplate()(c), c); + content += FinishWorkFunc(c); } return content; } @@ -312,6 +328,22 @@ [] ); } + else if (location.hostname == 'russian.rt.com') { + // test: https://russian.rt.com/business/article/1222163-centrobank-stavka-oktyabr-2023 + const base_element = document.getElementsByClassName('article article_article-page')[0]; + const base_element_text = document.getElementsByClassName('article__body')[0]; + + content = MakeContentByNews( + base_element, + base_element, + base_element_text, + 'article__heading', + 'article__cover article__cover_article-page', + 'article__text', + ElementCheckerRia, + [] + ); + } else if (location.hostname == 'zakonvremeni.ru') { const base_element = document.getElementsByClassName('item-page')[0]; const title = GetContentInContainers(FindElementsByRegExp(GetElementClassName, 'page-header', base_element), grub_text_func);