Skip to content

Commit

Permalink
优化 telegram 图片获取
Browse files Browse the repository at this point in the history
  • Loading branch information
yllhwa committed Dec 28, 2023
1 parent 464d9e9 commit 53997e6
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/lib/telegram/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ let deal = async (ctx) => {
tgme_widget_message_texts[tgme_widget_message_texts.length - 1] += text.text;
},
})
.on('.tgme_widget_message_bubble > .tgme_widget_message_photo_wrap', {
.on('.tgme_widget_message_bubble .tgme_widget_message_photo_wrap', {
element(element) {
let style = element.getAttribute('style');
let url = style.match(/background-image:url\('(.+)'\)/)[1];
tgme_widget_message_texts[tgme_widget_message_texts.length - 1] += '<img src="' + url + '" />';
tgme_widget_message_texts[tgme_widget_message_texts.length - 1] += '<br>';
},
})
.on('.tgme_widget_message_bubble > .tgme_widget_message_text > b', {
Expand Down Expand Up @@ -76,9 +77,12 @@ let deal = async (ctx) => {
if (tgme_widget_message_texts[i] === '') {
continue;
}
let title = tgme_widget_message_texts[i].replace(/<br>|<b>|<\/b>|<img.*>/g, ' ');
let title = tgme_widget_message_texts[i].replace(/<br>/g, ' ');
title = title.replace(/<b>|<\/b>|<img.*>/g, '');
if (title.length > 100) {
title = title.slice(0, 100) + '...';
} else if (title.trim().length === 0) {
title = '无标题';
}
let item = {
title: title,
Expand Down

0 comments on commit 53997e6

Please sign in to comment.