rsshub 1.0.0-master.fe69819 → 1.0.0-master.fee75c6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.js +4 -0
- package/lib/radar-rules.js +0 -162
- package/lib/router.js +82 -83
- package/lib/routes/dsndsht23/index.js +2 -1
- package/lib/routes/ehentai/ehapi.js +16 -6
- package/lib/routes/ehentai/favorites.js +14 -7
- package/lib/routes/ehentai/search.js +14 -5
- package/lib/routes/ehentai/tag.js +14 -5
- package/lib/routes/mofish/index.js +21 -9
- package/lib/routes/mofish/templates/description.art +4 -0
- package/lib/routes/or/index.js +1 -1
- package/lib/routes/prestige-av/series.js +3 -6
- package/lib/routes/tencent/wechat/tgchannel.js +84 -29
- package/lib/routes/weibo/timeline.js +18 -1
- package/lib/routes/weibo/user.js +19 -3
- package/lib/routes/weibo/utils.js +113 -5
- package/lib/routes/zhihu/hot.js +3 -2
- package/lib/v2/36kr/maintainer.js +7 -0
- package/lib/{routes → v2}/36kr/motif.js +2 -1
- package/lib/v2/36kr/news.js +56 -0
- package/lib/{routes → v2}/36kr/newsflashes.js +2 -1
- package/lib/v2/36kr/radar.js +37 -0
- package/lib/v2/36kr/router.js +7 -0
- package/lib/{routes → v2}/36kr/search/article.js +3 -2
- package/lib/{routes → v2}/36kr/user.js +2 -1
- package/lib/v2/52hrtt/index.js +57 -0
- package/lib/v2/52hrtt/maintainer.js +4 -0
- package/lib/v2/52hrtt/radar.js +19 -0
- package/lib/v2/52hrtt/router.js +4 -0
- package/lib/v2/52hrtt/symposium.js +57 -0
- package/lib/v2/8kcos/article.js +24 -0
- package/lib/v2/8kcos/cat.js +22 -0
- package/lib/{routes → v2}/8kcos/const.js +0 -0
- package/lib/v2/8kcos/latest.js +23 -0
- package/lib/v2/8kcos/maintainer.js +5 -0
- package/lib/v2/8kcos/radar.js +25 -0
- package/lib/v2/8kcos/router.js +5 -0
- package/lib/v2/8kcos/tag.js +23 -0
- package/lib/{routes → v2}/95mm/category.js +5 -3
- package/lib/v2/95mm/maintainer.js +5 -0
- package/lib/v2/95mm/radar.js +25 -0
- package/lib/v2/95mm/router.js +5 -0
- package/lib/v2/95mm/tab.js +9 -0
- package/lib/v2/95mm/tag.js +9 -0
- package/lib/v2/95mm/templates/description.art +3 -0
- package/lib/v2/95mm/utils.js +59 -0
- package/lib/v2/abskoop/index.js +52 -0
- package/lib/v2/abskoop/maintainer.js +3 -0
- package/lib/v2/abskoop/radar.js +13 -0
- package/lib/v2/abskoop/router.js +3 -0
- package/lib/v2/abskoop/templates/description.art +3 -0
- package/lib/v2/apple/exchange_repair.js +40 -0
- package/lib/v2/apple/maintainer.js +3 -0
- package/lib/v2/apple/radar.js +13 -0
- package/lib/v2/apple/router.js +3 -0
- package/lib/{routes/apple → v2}/appstore/gofans.js +3 -3
- package/lib/{routes/apple → v2}/appstore/in-app-purchase.js +0 -0
- package/lib/v2/appstore/maintainer.js +7 -0
- package/lib/{routes/apple → v2}/appstore/price.js +0 -0
- package/lib/v2/appstore/radar.js +41 -0
- package/lib/v2/appstore/router.js +7 -0
- package/lib/{routes/apple → v2}/appstore/update.js +0 -0
- package/lib/{routes/apple → v2}/appstore/xianmian.js +3 -2
- package/lib/{routes/universities → v2}/bjfu/grs.js +0 -0
- package/lib/v2/bjfu/it/index.js +49 -0
- package/lib/v2/bjfu/it/utils.js +64 -0
- package/lib/{routes/universities → v2}/bjfu/jwc/index.js +0 -0
- package/lib/{routes/universities → v2}/bjfu/jwc/utils.js +10 -9
- package/lib/{routes/universities → v2}/bjfu/kjc.js +0 -0
- package/lib/v2/bjfu/maintainer.js +7 -0
- package/lib/{routes/universities → v2}/bjfu/news/index.js +0 -0
- package/lib/{routes/universities → v2}/bjfu/news/utils.js +10 -9
- package/lib/v2/bjfu/radar.js +45 -0
- package/lib/v2/bjfu/router.js +7 -0
- package/lib/v2/dahecube/index.js +66 -0
- package/lib/v2/dahecube/maintainer.js +3 -0
- package/lib/v2/dahecube/radar.js +23 -0
- package/lib/v2/dahecube/router.js +3 -0
- package/lib/v2/dahecube/utils.js +47 -0
- package/lib/v2/dhu/jiaowu/news.js +37 -0
- package/lib/v2/dhu/maintainer.js +4 -0
- package/lib/v2/dhu/radar.js +17 -0
- package/lib/v2/dhu/router.js +4 -0
- package/lib/v2/dhu/xxgk/news.js +32 -0
- package/lib/v2/douban/people/wish.js +2 -1
- package/lib/{routes → v2}/dtcj/datahero.js +3 -2
- package/lib/v2/dtcj/datainsight.js +53 -0
- package/lib/v2/dtcj/maintainer.js +4 -0
- package/lib/v2/dtcj/radar.js +25 -0
- package/lib/v2/dtcj/router.js +4 -0
- package/lib/v2/eastday/24.js +90 -0
- package/lib/v2/eastday/maintainer.js +2 -0
- package/lib/v2/eastday/radar.js +16 -0
- package/lib/v2/eastday/router.js +2 -0
- package/lib/{routes → v2}/eastday/sh.js +6 -11
- package/lib/v2/eastmoney/radar.js +13 -0
- package/lib/v2/eastmoney/router.js +3 -0
- package/lib/v2/eastmoney/ttjj/user.js +65 -0
- package/lib/v2/ems/apple.js +42 -0
- package/lib/v2/ems/maintainer.js +4 -0
- package/lib/{routes → v2}/ems/news.js +0 -0
- package/lib/v2/ems/radar.js +19 -0
- package/lib/v2/ems/router.js +4 -0
- package/lib/v2/ems/templates/apple.art +6 -0
- package/lib/{routes → v2}/flyert/creditcard.js +0 -0
- package/lib/v2/flyert/maintainer.js +4 -0
- package/lib/{routes → v2}/flyert/preferential.js +0 -0
- package/lib/v2/flyert/radar.js +19 -0
- package/lib/v2/flyert/router.js +4 -0
- package/lib/{routes → v2}/flyert/utils.js +2 -1
- package/lib/v2/hdu/cs/index.js +57 -0
- package/lib/v2/hdu/maintainer.js +3 -0
- package/lib/v2/hdu/radar.js +13 -0
- package/lib/v2/hdu/router.js +4 -0
- package/lib/v2/hellobtc/information.js +51 -0
- package/lib/v2/hellobtc/kepu.js +64 -0
- package/lib/v2/hellobtc/maintainer.js +6 -0
- package/lib/v2/hellobtc/news.js +29 -0
- package/lib/v2/hellobtc/radar.js +85 -0
- package/lib/v2/hellobtc/router.js +6 -0
- package/lib/v2/hellobtc/topic.js +43 -0
- package/lib/v2/ielts/index.js +58 -0
- package/lib/v2/ielts/maintainer.js +3 -0
- package/lib/v2/ielts/radar.js +13 -0
- package/lib/v2/ielts/router.js +3 -0
- package/lib/{routes → v2}/javbus/genre.js +0 -0
- package/lib/{routes → v2}/javbus/home.js +0 -0
- package/lib/v2/javbus/label.js +7 -0
- package/lib/v2/javbus/maintainer.js +16 -0
- package/lib/v2/javbus/radar.js +99 -0
- package/lib/v2/javbus/router.js +16 -0
- package/lib/{routes → v2}/javbus/series.js +0 -0
- package/lib/{routes → v2}/javbus/star.js +0 -0
- package/lib/v2/javbus/studio.js +7 -0
- package/lib/{routes → v2}/javbus/uncensored/genre.js +0 -0
- package/lib/{routes → v2}/javbus/uncensored/home.js +0 -0
- package/lib/{routes → v2}/javbus/uncensored/series.js +0 -0
- package/lib/{routes → v2}/javbus/uncensored/star.js +0 -0
- package/lib/{routes → v2}/javbus/util.js +5 -9
- package/lib/{routes → v2}/javbus/western/genre.js +0 -0
- package/lib/{routes → v2}/javbus/western/home.js +0 -0
- package/lib/{routes → v2}/javbus/western/series.js +0 -0
- package/lib/{routes → v2}/javbus/western/star.js +0 -0
- package/lib/v2/javlibrary/utils.js +1 -1
- package/lib/v2/kbs/maintainer.js +4 -0
- package/lib/v2/kbs/news.js +67 -0
- package/lib/v2/kbs/radar.js +19 -0
- package/lib/v2/kbs/router.js +4 -0
- package/lib/{routes → v2}/kbs/today.js +1 -1
- package/lib/v2/lofter/maintainer.js +4 -0
- package/lib/v2/lofter/radar.js +17 -0
- package/lib/v2/lofter/router.js +4 -0
- package/lib/{routes → v2}/lofter/tag.js +4 -4
- package/lib/v2/lofter/user.js +52 -0
- package/lib/v2/lvv2/maintainer.js +4 -0
- package/lib/v2/lvv2/news.js +75 -0
- package/lib/v2/lvv2/radar.js +79 -0
- package/lib/v2/lvv2/router.js +4 -0
- package/lib/v2/lvv2/templates/outlink.art +1 -0
- package/lib/v2/lvv2/top.js +77 -0
- package/lib/v2/nbd/article.js +50 -0
- package/lib/{routes → v2}/nbd/index.js +8 -5
- package/lib/v2/nbd/maintainer.js +4 -0
- package/lib/v2/nbd/radar.js +19 -0
- package/lib/v2/nbd/router.js +4 -0
- package/lib/v2/njnu/ceai/ceai.js +44 -0
- package/lib/v2/njnu/ceai/utils.js +55 -0
- package/lib/v2/njnu/jwc/jwc.js +43 -0
- package/lib/v2/njnu/jwc/utils.js +59 -0
- package/lib/v2/njnu/maintainer.js +4 -0
- package/lib/v2/njnu/radar.js +21 -0
- package/lib/v2/njnu/router.js +4 -0
- package/lib/v2/nltimes/maintainer.js +3 -0
- package/lib/v2/nltimes/news.js +89 -0
- package/lib/v2/nltimes/radar.js +19 -0
- package/lib/v2/nltimes/router.js +3 -0
- package/lib/{routes → v2}/nowcoder/discuss.js +17 -22
- package/lib/v2/nowcoder/experience.js +48 -0
- package/lib/{routes → v2}/nowcoder/jobcenter.js +0 -0
- package/lib/v2/nowcoder/maintainer.js +7 -0
- package/lib/v2/nowcoder/radar.js +40 -0
- package/lib/{routes → v2}/nowcoder/recommend.js +1 -1
- package/lib/v2/nowcoder/router.js +7 -0
- package/lib/{routes → v2}/nowcoder/schedule.js +4 -3
- package/lib/v2/odaily/post.js +10 -8
- package/lib/v2/oilchem/index.js +67 -0
- package/lib/v2/oilchem/maintainer.js +3 -0
- package/lib/v2/oilchem/radar.js +11 -0
- package/lib/v2/oilchem/router.js +3 -0
- package/lib/v2/oilchem/routes.js +671 -0
- package/lib/v2/picuki/maintainer.js +3 -0
- package/lib/v2/picuki/profile.js +167 -0
- package/lib/v2/picuki/radar.js +13 -0
- package/lib/v2/picuki/router.js +3 -0
- package/lib/v2/picuki/templates/post.art +7 -0
- package/lib/v2/qq88/index.js +60 -0
- package/lib/v2/qq88/maintainer.js +3 -0
- package/lib/v2/qq88/radar.js +13 -0
- package/lib/v2/qq88/router.js +3 -0
- package/lib/v2/readhub/index.js +106 -0
- package/lib/v2/readhub/maintainer.js +3 -0
- package/lib/v2/readhub/radar.js +13 -0
- package/lib/v2/readhub/router.js +6 -0
- package/lib/v2/shmeea/maintainer.js +1 -0
- package/lib/v2/shmeea/radar.js +6 -0
- package/lib/v2/shmeea/router.js +2 -1
- package/lib/v2/shmeea/self-study.js +61 -0
- package/lib/{routes/universities/sysu/sdcs.js → v2/sysu/cse.js} +3 -3
- package/lib/v2/sysu/maintainer.js +3 -0
- package/lib/v2/sysu/radar.js +13 -0
- package/lib/v2/sysu/router.js +3 -0
- package/lib/v2/telegram/channel.js +446 -112
- package/lib/v2/telegram/maintainer.js +1 -1
- package/lib/v2/telegram/router.js +1 -1
- package/lib/v2/telegram/templates/video.art +3 -1
- package/lib/v2/tencent/maintainer.js +3 -0
- package/lib/v2/tencent/qq/sdk/changelog.js +56 -0
- package/lib/v2/tencent/radar.js +56 -0
- package/lib/v2/tencent/router.js +3 -0
- package/lib/v2/tokeninsight/blog.js +52 -0
- package/lib/v2/tokeninsight/bulletin.js +44 -0
- package/lib/v2/tokeninsight/maintainer.js +5 -0
- package/lib/v2/tokeninsight/radar.js +25 -0
- package/lib/v2/tokeninsight/report.js +52 -0
- package/lib/v2/tokeninsight/router.js +5 -0
- package/lib/v2/txrjy/fornumtopic.js +72 -0
- package/lib/v2/txrjy/maintainer.js +3 -0
- package/lib/v2/txrjy/radar.js +17 -0
- package/lib/v2/txrjy/router.js +3 -0
- package/lib/v2/txrjy/templates/fornumtopic.art +6 -0
- package/lib/v2/wfu/jwc.js +54 -0
- package/lib/v2/wfu/maintainer.js +4 -0
- package/lib/v2/wfu/news.js +96 -0
- package/lib/v2/wfu/radar.js +21 -0
- package/lib/v2/wfu/router.js +4 -0
- package/lib/v2/who/maintainer.js +5 -0
- package/lib/v2/who/news-room.js +76 -0
- package/lib/{routes → v2}/who/news.js +1 -1
- package/lib/v2/who/radar.js +25 -0
- package/lib/v2/who/router.js +5 -0
- package/lib/{routes → v2}/who/speeches.js +0 -0
- package/lib/v2/wikinews/index.js +43 -0
- package/lib/v2/wikinews/maintainer.js +3 -0
- package/lib/v2/wikinews/radar.js +13 -0
- package/lib/v2/wikinews/router.js +4 -0
- package/lib/{routes → v2}/wsj/index.js +6 -4
- package/lib/v2/wsj/maintainer.js +3 -0
- package/lib/v2/wsj/radar.js +21 -0
- package/lib/v2/wsj/router.js +3 -0
- package/lib/v2/xiaoyuzhou/maintainer.js +1 -1
- package/lib/v2/xiaoyuzhou/podcast.js +1 -1
- package/lib/v2/xmanhua/index.js +74 -0
- package/lib/v2/xmanhua/radar.js +13 -0
- package/lib/v2/xmanhua/router.js +3 -0
- package/lib/{routes → v2}/zhibo8/forum.js +8 -16
- package/lib/v2/zhibo8/maintainer.js +5 -0
- package/lib/v2/zhibo8/more.js +82 -0
- package/lib/{routes → v2}/zhibo8/post.js +1 -1
- package/lib/v2/zhibo8/radar.js +27 -0
- package/lib/v2/zhibo8/router.js +5 -0
- package/package.json +10 -9
- package/lib/routes/36kr/news.js +0 -94
- package/lib/routes/8kcos/article.js +0 -17
- package/lib/routes/8kcos/cat.js +0 -28
- package/lib/routes/8kcos/latest.js +0 -27
- package/lib/routes/95mm/tab.js +0 -9
- package/lib/routes/95mm/tag.js +0 -7
- package/lib/routes/95mm/utils.js +0 -51
- package/lib/routes/apple/exchange_repair.js +0 -47
- package/lib/routes/eastmoney/user.js +0 -30
- package/lib/routes/lofter/posts.js +0 -54
- package/lib/routes/nbd/article.js +0 -60
- package/lib/routes/picuki/profile.js +0 -90
- package/lib/routes/readhub/category.js +0 -102
- package/lib/routes/who/news-room.js +0 -56
- package/lib/routes/zhibo8/more.js +0 -45
|
@@ -1,23 +1,104 @@
|
|
|
1
|
+
const config = require('@/config').value;
|
|
1
2
|
const got = require('@/utils/got');
|
|
2
3
|
const cheerio = require('cheerio');
|
|
3
4
|
const { parseDate } = require('@/utils/parse-date');
|
|
4
5
|
const { art } = require('@/utils/render');
|
|
5
6
|
const path = require('path');
|
|
7
|
+
const querystring = require('querystring');
|
|
8
|
+
const { fallback, queryToBoolean } = require('@/utils/readable-social');
|
|
9
|
+
|
|
10
|
+
/* message types */
|
|
11
|
+
const REPLY = 'REPLY';
|
|
12
|
+
const FORWARDED = 'FORWARDED';
|
|
13
|
+
const SERVICE = 'SERVICE';
|
|
14
|
+
const VIA_BOT = 'VIA_BOT';
|
|
15
|
+
const VIDEO = 'VIDEO';
|
|
16
|
+
const GIF = 'GIF';
|
|
17
|
+
const PHOTO = 'PHOTO';
|
|
18
|
+
const POLL = 'POLL';
|
|
19
|
+
const VOICE = 'VOICE';
|
|
20
|
+
const MUSIC = 'MUSIC';
|
|
21
|
+
const DOCUMENT = 'DOCUMENT';
|
|
22
|
+
const LOCATION = 'LOCATION';
|
|
23
|
+
const CONTACT = 'CONTACT';
|
|
24
|
+
const STICKER = 'STICKER';
|
|
25
|
+
const ANIMATED_STICKER = 'ANIMATED_STICKER';
|
|
26
|
+
// const VIDEO_STICKER = 'VIDEO_STICKER'; // not supported yet by t.me
|
|
27
|
+
const UNSUPPORTED = 'UNSUPPORTED';
|
|
28
|
+
|
|
29
|
+
/* message media tag dict */
|
|
30
|
+
const mediaTagDict = {
|
|
31
|
+
REPLY: ['[Reply]', '↩️'],
|
|
32
|
+
FORWARDED: ['[Forwarded]', '🔁'],
|
|
33
|
+
SERVICE: ['[Service]', '🔧'],
|
|
34
|
+
VIA_BOT: ['[Via bot]', '🤖'],
|
|
35
|
+
VIDEO: ['[Video]', '🎬'],
|
|
36
|
+
GIF: ['[GIF]', '[GIF]'],
|
|
37
|
+
PHOTO: ['[Photo]', '🖼'],
|
|
38
|
+
POLL: ['[Poll]', '📊'],
|
|
39
|
+
VOICE: ['[Voice]', '🎙'],
|
|
40
|
+
MUSIC: ['[Music]', '🎵'],
|
|
41
|
+
DOCUMENT: ['[Document]', '📄'],
|
|
42
|
+
LOCATION: ['[Location]', '📍'],
|
|
43
|
+
CONTACT: ['[Contact]', '📱'],
|
|
44
|
+
STICKER: ['[Sticker]', '[Sticker]'],
|
|
45
|
+
ANIMATED_STICKER: ['[Animated Sticker]', '[Animated Sticker]'],
|
|
46
|
+
// VIDEO_STICKER: ['[Video Sticker]', '[Video Sticker]'], // not supported yet by t.me
|
|
47
|
+
UNSUPPORTED: ['[Unsupported]', '🚫'],
|
|
48
|
+
};
|
|
6
49
|
|
|
7
50
|
module.exports = async (ctx) => {
|
|
8
51
|
const username = ctx.params.username;
|
|
9
|
-
|
|
52
|
+
let routeParams = ctx.params.routeParams;
|
|
53
|
+
let showLinkPreview = true;
|
|
54
|
+
let showViaBot = true;
|
|
55
|
+
let showReplyTo = true;
|
|
56
|
+
let showFwdFrom = true;
|
|
57
|
+
let showFwdFromAuthor = true;
|
|
58
|
+
let showInlineButtons = false;
|
|
59
|
+
let showMediaTagInTitle = true;
|
|
60
|
+
let showMediaTagAsEmoji = true;
|
|
61
|
+
let includeFwd = true;
|
|
62
|
+
let includeReply = true;
|
|
63
|
+
let includeServiceMsg = true;
|
|
64
|
+
let includeUnsupportedMsg = false;
|
|
65
|
+
let searchQuery = routeParams; // for backward compatibility
|
|
66
|
+
if (routeParams && routeParams.search(/(^|&)(show(LinkPreview|ViaBot|ReplyTo|FwdFrom(Author)?|InlineButtons|MediaTag(InTitle|AsEmoji))|include(Fwd|Reply|(Service|Unsupported)Msg)|searchQuery)=/) !== -1) {
|
|
67
|
+
routeParams = querystring.parse(ctx.params.routeParams);
|
|
68
|
+
showLinkPreview = !!fallback(undefined, queryToBoolean(routeParams.showLinkPreview), showLinkPreview);
|
|
69
|
+
showViaBot = !!fallback(undefined, queryToBoolean(routeParams.showReplyTo), showViaBot);
|
|
70
|
+
showReplyTo = !!fallback(undefined, queryToBoolean(routeParams.showViaBot), showReplyTo);
|
|
71
|
+
showFwdFrom = !!fallback(undefined, queryToBoolean(routeParams.showFwdFrom), showFwdFrom);
|
|
72
|
+
showFwdFromAuthor = !!fallback(undefined, queryToBoolean(routeParams.showFwdFromAuthor), showFwdFromAuthor);
|
|
73
|
+
showInlineButtons = !!fallback(undefined, queryToBoolean(routeParams.showInlineButtons), showInlineButtons);
|
|
74
|
+
showMediaTagInTitle = !!fallback(undefined, queryToBoolean(routeParams.showMediaTagInTitle), showMediaTagInTitle);
|
|
75
|
+
showMediaTagAsEmoji = !!fallback(undefined, queryToBoolean(routeParams.showMediaTagAsEmoji), showMediaTagAsEmoji);
|
|
76
|
+
includeFwd = !!fallback(undefined, queryToBoolean(routeParams.includeFwd), includeFwd);
|
|
77
|
+
includeReply = !!fallback(undefined, queryToBoolean(routeParams.includeReply), includeReply);
|
|
78
|
+
includeServiceMsg = !!fallback(undefined, queryToBoolean(routeParams.includeServiceMsg), includeServiceMsg);
|
|
79
|
+
includeUnsupportedMsg = !!fallback(undefined, queryToBoolean(routeParams.includeUnsupportedMsg), includeUnsupportedMsg);
|
|
80
|
+
searchQuery = fallback(undefined, routeParams.searchQuery, null);
|
|
81
|
+
}
|
|
82
|
+
|
|
10
83
|
const resourceUrl = searchQuery ? `https://t.me/s/${username}?q=${encodeURIComponent(searchQuery)}` : `https://t.me/s/${username}`;
|
|
11
84
|
|
|
12
|
-
|
|
85
|
+
let data = await ctx.cache.get(resourceUrl, false);
|
|
86
|
+
if (!data) {
|
|
87
|
+
const response = await got.get(resourceUrl);
|
|
88
|
+
data = response.data;
|
|
89
|
+
ctx.cache.set(resourceUrl, data, config.cache.routeExpire);
|
|
90
|
+
}
|
|
13
91
|
const $ = cheerio.load(data);
|
|
14
|
-
const list =
|
|
92
|
+
const list = includeServiceMsg
|
|
93
|
+
? $('.tgme_widget_message_wrap:not(.tgme_widget_message_wrap:has(.tme_no_messages_found))') // exclude 'no posts found' messages
|
|
94
|
+
: $('.tgme_widget_message_wrap:not(.tgme_widget_message_wrap:has(.service_message,.tme_no_messages_found))'); // also exclude service messages
|
|
15
95
|
|
|
16
96
|
if (list.length === 0 && $('.tgme_channel_history').length === 0) {
|
|
17
|
-
throw `Unable to fetch message feed from this channel. Please check this URL to see if you can view the message preview:
|
|
97
|
+
throw `Unable to fetch message feed from this channel. Please check this URL to see if you can view the message preview: ${resourceUrl}`;
|
|
18
98
|
}
|
|
19
99
|
|
|
20
|
-
const
|
|
100
|
+
const channelName = $('.tgme_channel_info_header_title').text();
|
|
101
|
+
const feedTitle = (searchQuery ? `"${searchQuery}" - ` : '') + channelName + ' - Telegram Channel';
|
|
21
102
|
|
|
22
103
|
ctx.state.data = {
|
|
23
104
|
title: feedTitle,
|
|
@@ -25,7 +106,7 @@ module.exports = async (ctx) => {
|
|
|
25
106
|
link: resourceUrl,
|
|
26
107
|
allowEmpty: true,
|
|
27
108
|
|
|
28
|
-
itunes_author:
|
|
109
|
+
itunes_author: channelName,
|
|
29
110
|
image: $('.tgme_page_photo_image > img').attr('src'),
|
|
30
111
|
|
|
31
112
|
item:
|
|
@@ -34,69 +115,128 @@ module.exports = async (ctx) => {
|
|
|
34
115
|
.map((index, item) => {
|
|
35
116
|
item = $(item);
|
|
36
117
|
|
|
37
|
-
/*
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
118
|
+
/* message types */
|
|
119
|
+
const msgTypes = [];
|
|
120
|
+
if (item.find('.service_message').length) {
|
|
121
|
+
// service message can have an image (avatar changed)
|
|
122
|
+
msgTypes.push(SERVICE);
|
|
123
|
+
}
|
|
124
|
+
// if (item.find('.tgme_widget_message_video').length) { // fail if video too big
|
|
125
|
+
if (item.find('.tgme_widget_message_video_player').length) {
|
|
126
|
+
// video and gif cannot be mixed, it's safe to do that
|
|
127
|
+
msgTypes.push(item.find('.message_video_play').length ? VIDEO : GIF);
|
|
128
|
+
}
|
|
129
|
+
if (item.find('.tgme_widget_message_photo,.tgme_widget_message_service_photo').length) {
|
|
130
|
+
// video and photo can be mixed
|
|
131
|
+
msgTypes.push(PHOTO);
|
|
132
|
+
}
|
|
133
|
+
// all other types below cannot be mixed
|
|
134
|
+
if (item.find('.tgme_widget_message_poll').length) {
|
|
135
|
+
msgTypes.push(POLL);
|
|
136
|
+
}
|
|
137
|
+
if (item.find('.tgme_widget_message_voice').length) {
|
|
138
|
+
msgTypes.push(VOICE);
|
|
139
|
+
}
|
|
140
|
+
if (item.find('.tgme_widget_message_document').length) {
|
|
141
|
+
// music and document cannot be mixed, it's safe to do that
|
|
142
|
+
msgTypes.push(item.find('.audio').length ? MUSIC : DOCUMENT);
|
|
143
|
+
}
|
|
144
|
+
if (item.find('.tgme_widget_message_location').length) {
|
|
145
|
+
msgTypes.push(LOCATION);
|
|
146
|
+
}
|
|
147
|
+
if (item.find('.tgme_widget_message_contact').length) {
|
|
148
|
+
msgTypes.push(CONTACT);
|
|
149
|
+
}
|
|
150
|
+
if (item.find('.tgme_widget_message_sticker').length) {
|
|
151
|
+
msgTypes.push(STICKER);
|
|
152
|
+
}
|
|
153
|
+
if (item.find('.tgme_widget_message_tgsticker').length) {
|
|
154
|
+
msgTypes.push(ANIMATED_STICKER);
|
|
155
|
+
}
|
|
156
|
+
if (msgTypes.length === 0 && item.find('.message_media_not_supported').length) {
|
|
157
|
+
msgTypes.unshift(UNSUPPORTED);
|
|
158
|
+
if (!includeUnsupportedMsg) {
|
|
159
|
+
return null; // drop unsupported message
|
|
55
160
|
}
|
|
56
|
-
|
|
57
|
-
|
|
161
|
+
}
|
|
162
|
+
// all other types above cannot be mixed
|
|
163
|
+
if (item.find('.tgme_widget_message_author .tgme_widget_message_via_bot,.tgme_widget_message_forwarded_from .tgme_widget_message_via_bot').length) {
|
|
164
|
+
// can be mixed with other types, excluding service messages
|
|
165
|
+
msgTypes.unshift(VIA_BOT);
|
|
166
|
+
}
|
|
167
|
+
if (item.find('.tgme_widget_message_forwarded_from').length) {
|
|
168
|
+
// can be mixed with other types, excluding service messages and reply messages
|
|
169
|
+
msgTypes.unshift(FORWARDED);
|
|
170
|
+
if (!includeFwd) {
|
|
171
|
+
return null; // drop forwarded message
|
|
58
172
|
}
|
|
59
|
-
|
|
60
|
-
|
|
173
|
+
}
|
|
174
|
+
if (item.find('.tgme_widget_message_reply').length) {
|
|
175
|
+
// can be mixed with other types, excluding service messages and forwarded messages
|
|
176
|
+
msgTypes.unshift(REPLY);
|
|
177
|
+
if (!includeReply) {
|
|
178
|
+
return null; // drop reply message
|
|
61
179
|
}
|
|
62
|
-
|
|
63
|
-
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/* media tag */
|
|
183
|
+
let mediaTag = '';
|
|
184
|
+
if (showMediaTagInTitle) {
|
|
185
|
+
msgTypes.forEach((type) => {
|
|
186
|
+
if (type !== REPLY || type !== FORWARDED || type !== VIA_BOT || (type === REPLY && showReplyTo) || (type === FORWARDED && showFwdFrom) || (type === VIA_BOT && showViaBot)) {
|
|
187
|
+
mediaTag += showMediaTagAsEmoji ? mediaTagDict[type][1] : mediaTagDict[type][0];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/* fix emoji */
|
|
193
|
+
item.find('.emoji').each((_, emoji) => {
|
|
194
|
+
emoji = $(emoji);
|
|
195
|
+
emoji.replaceWith(`<span class="emoji">${emoji.text()}</span>`);
|
|
196
|
+
});
|
|
64
197
|
|
|
65
198
|
/* "Forwarded From" tag */
|
|
66
199
|
const fwdFrom = () => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
200
|
+
let fwdFrom = '';
|
|
201
|
+
const fwdFromNameObj = item.find('.tgme_widget_message_forwarded_from_name');
|
|
202
|
+
if (fwdFromNameObj.length) {
|
|
203
|
+
const userLink = fwdFromNameObj.attr('href');
|
|
204
|
+
const userHtml = userLink ? `<a href="${userLink}">${fwdFromNameObj.text()}</a>` : fwdFromNameObj.text();
|
|
205
|
+
fwdFrom += `<p>Forwarded From <b>${userHtml}</b>`;
|
|
206
|
+
const fwdFromAuthorObj = item.find('.tgme_widget_message_forwarded_from_author');
|
|
207
|
+
if (fwdFromAuthorObj.length && showFwdFromAuthor) {
|
|
208
|
+
fwdFrom += ` (${fwdFromAuthorObj.text()})`;
|
|
74
209
|
}
|
|
75
|
-
|
|
76
|
-
return '';
|
|
210
|
+
fwdFrom += '</p>';
|
|
77
211
|
}
|
|
212
|
+
return fwdFrom;
|
|
78
213
|
};
|
|
79
214
|
|
|
80
215
|
/* reply */
|
|
81
216
|
const replyContent = () => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const replyAuthor =
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const
|
|
217
|
+
const replyObj = item.find('.tgme_widget_message_reply');
|
|
218
|
+
if (replyObj.length !== 0) {
|
|
219
|
+
const replyAuthorObj = replyObj.find('.tgme_widget_message_author_name');
|
|
220
|
+
const replyAuthor = replyAuthorObj.length ? replyAuthorObj.text() : '';
|
|
221
|
+
const viaBotObj = replyObj.find('.tgme_widget_message_via_bot');
|
|
222
|
+
const viaBotText = viaBotObj.length ? ` via <b>${viaBotObj.text()}</b>` : '';
|
|
223
|
+
const replyLinkHref = replyObj.attr('href');
|
|
224
|
+
const replyLink = replyLinkHref.length ? replyLinkHref : '';
|
|
225
|
+
const replyMetaTextObj = replyObj.find('.tgme_widget_message_metatext');
|
|
226
|
+
const replyMetaText = replyMetaTextObj.length ? `<p><small>${replyMetaTextObj.html()}</small></p>` : '';
|
|
227
|
+
const replyTextObj = replyObj.find('.tgme_widget_message_text');
|
|
228
|
+
const replyText = replyTextObj.length ? `<p>${replyTextObj.html()}</p>` : '';
|
|
89
229
|
|
|
90
230
|
if (replyLink !== '') {
|
|
91
231
|
return `<blockquote>
|
|
92
|
-
<p><a href='${replyLink}'><
|
|
93
|
-
${
|
|
232
|
+
<p><a href='${replyLink}'><b>${replyAuthor}</b>${viaBotText}:</a></p>
|
|
233
|
+
${replyMetaText}
|
|
94
234
|
${replyText}
|
|
95
235
|
</blockquote>`;
|
|
96
236
|
} else {
|
|
97
237
|
return `<blockquote>
|
|
98
|
-
<p><
|
|
99
|
-
${
|
|
238
|
+
<p><b>${replyAuthor}</b>${viaBotText}:</p>
|
|
239
|
+
${replyMetaText}
|
|
100
240
|
${replyText}
|
|
101
241
|
</blockquote>`;
|
|
102
242
|
}
|
|
@@ -105,54 +245,118 @@ module.exports = async (ctx) => {
|
|
|
105
245
|
}
|
|
106
246
|
};
|
|
107
247
|
|
|
108
|
-
/*
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
$(this)
|
|
116
|
-
.css('background-image')
|
|
117
|
-
.match(/url\('(.*)'\)/)[1]
|
|
118
|
-
}">`;
|
|
119
|
-
});
|
|
120
|
-
return tag_images;
|
|
248
|
+
/* via bot */
|
|
249
|
+
const viaBot = () => {
|
|
250
|
+
const viaBotObj = item.find('.tgme_widget_message_author .tgme_widget_message_via_bot,.tgme_widget_message_forwarded_from .tgme_widget_message_via_bot');
|
|
251
|
+
if (viaBotObj.length) {
|
|
252
|
+
const userLink = viaBotObj.attr('href');
|
|
253
|
+
const userHtml = userLink ? `<a href="${userLink}">${viaBotObj.text()}</a>` : viaBotObj.text();
|
|
254
|
+
return `<p>via <b>${userHtml}</b></p>`;
|
|
121
255
|
} else {
|
|
122
256
|
return '';
|
|
123
257
|
}
|
|
124
258
|
};
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
item.find('.tgme_widget_message_video_player').each(function () {
|
|
132
|
-
const source = $(this).find('.tgme_widget_message_video').attr('src');
|
|
133
|
-
if (source) {
|
|
134
|
-
const poster = $(this)
|
|
135
|
-
.find('.tgme_widget_message_video_thumb')
|
|
136
|
-
.css('background-image')
|
|
137
|
-
.match(/url\('(.*)'\)/)[1];
|
|
138
|
-
messageVideos += art(path.join(__dirname, 'templates/video.art'), {
|
|
139
|
-
source,
|
|
140
|
-
poster,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
});
|
|
259
|
+
|
|
260
|
+
/* images and videos */
|
|
261
|
+
const generateMedia = (selector) => {
|
|
262
|
+
const nodes = item.find(selector);
|
|
263
|
+
if (!nodes.length) {
|
|
264
|
+
return '';
|
|
144
265
|
}
|
|
145
|
-
|
|
266
|
+
let tag_media = '';
|
|
267
|
+
const pictureNodes = nodes.find('picture');
|
|
268
|
+
const imgNodes = nodes.find('img');
|
|
269
|
+
nodes.each((_, node) => {
|
|
270
|
+
const $node = $(node);
|
|
271
|
+
if (node.attribs && node.attribs.class && node.attribs.class.search(/(^|\s)tgme_widget_message_video_player(\s|$)/) !== -1) {
|
|
272
|
+
// video
|
|
273
|
+
const videoLink = $node.find('.tgme_widget_message_video').attr('src');
|
|
274
|
+
const thumbBackground = $node.find('.tgme_widget_message_video_thumb').css('background-image');
|
|
275
|
+
const thumbBackgroundUrl = thumbBackground && thumbBackground.match(/url\('(.*)'\)/);
|
|
276
|
+
const thumbBackgroundUrlSrc = thumbBackgroundUrl && thumbBackgroundUrl[1];
|
|
277
|
+
tag_media += art(path.join(__dirname, 'templates/video.art'), {
|
|
278
|
+
source: videoLink,
|
|
279
|
+
poster: thumbBackgroundUrlSrc,
|
|
280
|
+
});
|
|
281
|
+
} else if ($node.attr('data-webp')) {
|
|
282
|
+
// sticker
|
|
283
|
+
tag_media += `<img src="${$node.attr('data-webp')}">`;
|
|
284
|
+
} else if (node.name === 'picture') {
|
|
285
|
+
// animated sticker
|
|
286
|
+
tag_media += '<picture>';
|
|
287
|
+
$node.find('source,img').each((_, source) => {
|
|
288
|
+
tag_media += $(source).toString();
|
|
289
|
+
});
|
|
290
|
+
tag_media += '</picture>';
|
|
291
|
+
} else if (node.name === 'img') {
|
|
292
|
+
// unknown
|
|
293
|
+
tag_media += $node.toString();
|
|
294
|
+
} else if (pictureNodes.length) {
|
|
295
|
+
// unknown
|
|
296
|
+
pictureNodes.each((_, picture) => {
|
|
297
|
+
tag_media += '<picture>';
|
|
298
|
+
$(picture)
|
|
299
|
+
.find('source,img')
|
|
300
|
+
.each((_, source) => {
|
|
301
|
+
tag_media += $(source).toString();
|
|
302
|
+
});
|
|
303
|
+
tag_media += '</picture>';
|
|
304
|
+
});
|
|
305
|
+
return tag_media;
|
|
306
|
+
} else if (imgNodes.length) {
|
|
307
|
+
// service message
|
|
308
|
+
imgNodes.each((_, img) => {
|
|
309
|
+
tag_media += $(img).toString();
|
|
310
|
+
});
|
|
311
|
+
return tag_media;
|
|
312
|
+
} else {
|
|
313
|
+
// image message, location
|
|
314
|
+
const background = $node.css('background-image');
|
|
315
|
+
const backgroundUrl = background && background.match(/url\('(.*)'\)/);
|
|
316
|
+
const backgroundUrlSrc = backgroundUrl && backgroundUrl[1];
|
|
317
|
+
tag_media += backgroundUrlSrc ? `<img src="${backgroundUrlSrc}">` : '';
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
return tag_media;
|
|
146
321
|
};
|
|
322
|
+
// ordinary message photos, service message photos, stickers, animated stickers, video
|
|
323
|
+
const messageMedia = generateMedia('.tgme_widget_message_photo_wrap,.tgme_widget_message_service_photo,.tgme_widget_message_sticker,.tgme_widget_message_tgsticker,.tgme_widget_message_video_player');
|
|
147
324
|
|
|
148
|
-
/*
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
const
|
|
325
|
+
/* location */
|
|
326
|
+
const location = () => {
|
|
327
|
+
const locationObj = item.find('.tgme_widget_message_location_wrap');
|
|
328
|
+
if (locationObj.length) {
|
|
329
|
+
const locationLink = locationObj.attr('href');
|
|
330
|
+
const mapBackground = locationObj.find('.tgme_widget_message_location').css('background-image');
|
|
331
|
+
const mapBackgroundUrl = mapBackground && mapBackground.match(/url\('(.*)'\)/);
|
|
332
|
+
const mapBackgroundUrlSrc = mapBackgroundUrl && mapBackgroundUrl[1];
|
|
333
|
+
const mapImgHtml = mapBackgroundUrlSrc ? `<img src="${mapBackgroundUrlSrc}">` : showMediaTagAsEmoji ? mediaTagDict[LOCATION][1] : mediaTagDict[LOCATION][0];
|
|
334
|
+
return locationLink ? `<a href="${locationLink}">${mapImgHtml}</a>` : mapImgHtml;
|
|
335
|
+
} else {
|
|
336
|
+
return '';
|
|
337
|
+
}
|
|
338
|
+
};
|
|
155
339
|
|
|
340
|
+
/* voice */
|
|
341
|
+
const voiceObj = item.find('audio.tgme_widget_message_voice');
|
|
342
|
+
const durationObj = item.find('.tgme_widget_message_voice_duration');
|
|
343
|
+
const durationInMmss = durationObj.text();
|
|
344
|
+
const voiceUrl = voiceObj.length ? voiceObj.attr('src') : '';
|
|
345
|
+
let voiceTitle = '';
|
|
346
|
+
let voiceHtml = '';
|
|
347
|
+
if (voiceUrl) {
|
|
348
|
+
if (showMediaTagInTitle) {
|
|
349
|
+
voiceTitle = durationInMmss ? `(${durationInMmss})` : '';
|
|
350
|
+
}
|
|
351
|
+
voiceHtml += '<p><b>';
|
|
352
|
+
voiceHtml += showMediaTagAsEmoji ? mediaTagDict[VOICE][1] : mediaTagDict[VOICE][0];
|
|
353
|
+
voiceHtml += durationInMmss ? ` (${durationInMmss})` : '';
|
|
354
|
+
voiceHtml += '</b></p>';
|
|
355
|
+
voiceHtml += `<audio src="${voiceUrl}"></audio>`;
|
|
356
|
+
}
|
|
357
|
+
const voiceDuration = () => {
|
|
358
|
+
if (durationObj.length) {
|
|
359
|
+
const p = durationInMmss.split(':');
|
|
156
360
|
let second = 0,
|
|
157
361
|
minute = 1;
|
|
158
362
|
while (p.length > 0) {
|
|
@@ -165,18 +369,38 @@ module.exports = async (ctx) => {
|
|
|
165
369
|
}
|
|
166
370
|
};
|
|
167
371
|
|
|
372
|
+
/* unsupported */
|
|
373
|
+
let unsupportedHtml = '';
|
|
374
|
+
let unsupportedTitle = '';
|
|
375
|
+
const unsupportedNodes = item.find('.message_media_not_supported');
|
|
376
|
+
if (msgTypes.indexOf(UNSUPPORTED) !== -1 && unsupportedNodes.length) {
|
|
377
|
+
unsupportedHtml += '<blockquote>';
|
|
378
|
+
unsupportedNodes.find('.message_media_not_supported_label').each(function () {
|
|
379
|
+
const $this = $(this);
|
|
380
|
+
unsupportedTitle += $this.text();
|
|
381
|
+
unsupportedHtml += `<p>${$this.text()}</p>`;
|
|
382
|
+
});
|
|
383
|
+
unsupportedNodes.find('.message_media_view_in_telegram').each(function () {
|
|
384
|
+
const $this = $(this);
|
|
385
|
+
unsupportedHtml += $this.attr('href') ? `<p><a href="${$this.attr('href')}">${$this.text()}</a></p>` : `<p>${$this.text()}</p>`;
|
|
386
|
+
});
|
|
387
|
+
unsupportedHtml += '</blockquote>';
|
|
388
|
+
}
|
|
389
|
+
|
|
168
390
|
/* link preview */
|
|
169
391
|
const linkPreview = () => {
|
|
170
|
-
const
|
|
392
|
+
const linkPreviewSiteObj = item.find('.link_preview_site_name');
|
|
393
|
+
const linkPreviewSite = linkPreviewSiteObj.length ? `<b>${linkPreviewSiteObj.text()}</b><br>` : '';
|
|
394
|
+
const linkPreviewTitleObj = item.find('.link_preview_title');
|
|
171
395
|
let linkPreviewTitle;
|
|
172
|
-
if (
|
|
173
|
-
linkPreviewTitle = `<b><a href="${item.find('.tgme_widget_message_link_preview').attr('href')}"
|
|
174
|
-
${item.find('.link_preview_title').text()}</a></b><br>`;
|
|
396
|
+
if (linkPreviewTitleObj.length) {
|
|
397
|
+
linkPreviewTitle = `<b><a href="${item.find('.tgme_widget_message_link_preview').attr('href')}">${linkPreviewTitleObj.text()}</a></b><br>`;
|
|
175
398
|
} else {
|
|
176
399
|
linkPreviewTitle = '';
|
|
177
400
|
}
|
|
178
|
-
const
|
|
179
|
-
const
|
|
401
|
+
const linkPreviewDescriptionObj = item.find('.link_preview_description');
|
|
402
|
+
const linkPreviewDescription = linkPreviewDescriptionObj.length ? `<p>${linkPreviewDescriptionObj.html()}</p>` : '';
|
|
403
|
+
const linkPreviewImage = generateMedia('.link_preview_image') + generateMedia('.link_preview_right_image');
|
|
180
404
|
|
|
181
405
|
if (linkPreviewSite.length > 0 || linkPreviewTitle.length > 0 || linkPreviewDescription.length > 0 || linkPreviewImage.length > 0) {
|
|
182
406
|
return `<blockquote>${linkPreviewSite}${linkPreviewTitle}${linkPreviewDescription}${linkPreviewImage}</blockquote>`;
|
|
@@ -186,46 +410,156 @@ module.exports = async (ctx) => {
|
|
|
186
410
|
};
|
|
187
411
|
|
|
188
412
|
/* poll */
|
|
189
|
-
const
|
|
413
|
+
const pollQuestionObj = item.find('.tgme_widget_message_poll_question');
|
|
414
|
+
const pollQuestion = pollQuestionObj.length ? pollQuestionObj.text() : '';
|
|
415
|
+
const poll = () => {
|
|
416
|
+
let pollHtml = '';
|
|
417
|
+
const pollTypeObj = item.find('.tgme_widget_message_poll_type');
|
|
418
|
+
const pollType = pollTypeObj.length ? pollTypeObj.text() : '';
|
|
419
|
+
const pollOptions = item.find('.tgme_widget_message_poll_option');
|
|
420
|
+
if (pollQuestion && pollType.length > 0 && pollOptions.length > 0) {
|
|
421
|
+
pollHtml += `<p><b>${pollQuestion}</b></p>`;
|
|
422
|
+
pollHtml += `<p><small>${pollType}</small></p>`;
|
|
423
|
+
pollOptions.each((_, option) => {
|
|
424
|
+
const $option = $(option);
|
|
425
|
+
const percentObj = $option.find('.tgme_widget_message_poll_option_percent');
|
|
426
|
+
const percent = percentObj.length ? percentObj.text() : '';
|
|
427
|
+
const textObj = $option.find('.tgme_widget_message_poll_option_text');
|
|
428
|
+
const text = textObj.length ? textObj.text() : '';
|
|
429
|
+
if (percent && text) {
|
|
430
|
+
pollHtml += `<p><b>${percent}</b> - ${text}</p>`;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
return pollHtml ? `<blockquote>${pollHtml}</blockquote>` : '';
|
|
435
|
+
};
|
|
190
436
|
|
|
191
|
-
/* attachment */
|
|
192
|
-
const
|
|
437
|
+
/* attachment (document or music) */
|
|
438
|
+
const documentWrapObj = item.find('.tgme_widget_message_document_wrap');
|
|
439
|
+
let attachmentTitle = '';
|
|
440
|
+
let attachmentHtml = '';
|
|
441
|
+
if (documentWrapObj.length) {
|
|
442
|
+
documentWrapObj.each((_, wrap) => {
|
|
443
|
+
// a message may have multiple attachments
|
|
444
|
+
const $wrap = $(wrap);
|
|
445
|
+
const documentTitleObj = $wrap.find('.tgme_widget_message_document_title');
|
|
446
|
+
const documentExtraObj = $wrap.find('.tgme_widget_message_document_extra');
|
|
447
|
+
const documentTitle = documentTitleObj.length ? documentTitleObj.text() : '';
|
|
448
|
+
const documentExtra = documentExtraObj.length ? documentExtraObj.text() : '';
|
|
449
|
+
const _attachmentTitle = `${documentTitle}${documentTitle && documentExtra ? ' - ' : ''}${documentExtra}`;
|
|
450
|
+
const _attachmentHtml = (documentTitle ? `<p><b>${documentTitle}</b></p>` : '') + (documentExtra ? `<p><small>${documentExtra}</small></p>` : '');
|
|
451
|
+
attachmentTitle += attachmentTitle && _attachmentTitle ? ' | ' : '';
|
|
452
|
+
attachmentTitle += _attachmentTitle;
|
|
453
|
+
attachmentHtml += _attachmentHtml ? `<blockquote>${_attachmentHtml}</blockquote>` : '';
|
|
454
|
+
const wrapNext = $wrap.next('.tgme_widget_message_text');
|
|
455
|
+
if (wrapNext.length) {
|
|
456
|
+
const captionHtml = wrapNext.html();
|
|
457
|
+
if (captionHtml.length) {
|
|
458
|
+
attachmentHtml += `<p>${captionHtml}</p>`;
|
|
459
|
+
}
|
|
460
|
+
// remove them, avoid being duplicated
|
|
461
|
+
wrapNext.each((_, caption) => {
|
|
462
|
+
$(caption).remove();
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/* contact */
|
|
469
|
+
const contactNameObj = item.find('.tgme_widget_message_contact_name');
|
|
470
|
+
const contactName = contactNameObj.length ? contactNameObj.text() : '';
|
|
471
|
+
const contactNameHtml = contactName ? `<b>${contactName}</b>` : '';
|
|
472
|
+
const contactPhoneObj = item.find('.tgme_widget_message_contact_phone');
|
|
473
|
+
const contactPhone = contactPhoneObj.length ? contactPhoneObj.text() : '';
|
|
474
|
+
const contactPhoneHtml = contactPhone ? `<a href="tel:${contactPhone.replace(' ', '')}">${contactPhone}</a>` : '';
|
|
475
|
+
const contactTitle = contactName + (contactName && contactPhone ? ': ' : '') + contactPhone;
|
|
476
|
+
const contactHtml = contactNameHtml || contactPhoneHtml ? `<p>${contactNameHtml}${contactName && contactPhone ? ': ' : ''}${contactPhoneHtml}</p>` : '';
|
|
477
|
+
|
|
478
|
+
/* inline buttons */
|
|
479
|
+
let inlineButtons = '';
|
|
480
|
+
const inlineButtonNodes = item.find('.tgme_widget_message_inline_button_text');
|
|
481
|
+
if (showInlineButtons && inlineButtonNodes.length) {
|
|
482
|
+
inlineButtons += '<table style="width: 100%"><tbody><tr>';
|
|
483
|
+
inlineButtonNodes.each((_, button) => {
|
|
484
|
+
const $button = $(button);
|
|
485
|
+
const buttonText = $button.text();
|
|
486
|
+
inlineButtons += `<td style="border: 2px solid;text-align: center"><b>${buttonText}</b></td>`;
|
|
487
|
+
});
|
|
488
|
+
inlineButtons += '</tr></tbody></table>';
|
|
489
|
+
}
|
|
193
490
|
|
|
194
491
|
/* pubDate */
|
|
195
492
|
const pubDate = parseDate(item.find('.tgme_widget_message_date time').attr('datetime'));
|
|
196
493
|
|
|
197
494
|
/* message text & title */
|
|
198
|
-
const
|
|
199
|
-
let
|
|
495
|
+
const messageTextObj = item.find('.tgme_widget_message_bubble > .tgme_widget_message_text');
|
|
496
|
+
let messageHtml = '',
|
|
200
497
|
messageTitle = '';
|
|
201
498
|
|
|
202
|
-
if (
|
|
203
|
-
|
|
499
|
+
if (messageTextObj.length > 0) {
|
|
500
|
+
messageHtml = `<p>${messageTextObj.html()}</p>`;
|
|
204
501
|
}
|
|
205
502
|
|
|
206
|
-
|
|
503
|
+
let titleCompleteFlag = false;
|
|
504
|
+
if (pollQuestion) {
|
|
207
505
|
messageTitle = pollQuestion;
|
|
208
|
-
|
|
506
|
+
titleCompleteFlag = true;
|
|
507
|
+
} else if (attachmentTitle) {
|
|
209
508
|
messageTitle = attachmentTitle;
|
|
210
|
-
|
|
211
|
-
|
|
509
|
+
titleCompleteFlag = true;
|
|
510
|
+
} else if (contactTitle) {
|
|
511
|
+
messageTitle = contactTitle;
|
|
512
|
+
titleCompleteFlag = true;
|
|
513
|
+
} else if (voiceTitle) {
|
|
514
|
+
messageTitle = voiceTitle;
|
|
515
|
+
} else if (unsupportedTitle) {
|
|
516
|
+
messageTitle = unsupportedTitle;
|
|
517
|
+
titleCompleteFlag = true;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (messageTextObj.length > 0 && !titleCompleteFlag) {
|
|
521
|
+
const _messageTextObj = $(messageTextObj.toString());
|
|
522
|
+
_messageTextObj.find('br').replaceWith('\n');
|
|
523
|
+
const trimmedTitleText = _messageTextObj.text().replace(/\n/g, ' ').trim();
|
|
524
|
+
messageTitle += (messageTitle && trimmedTitleText ? ': ' : '') + trimmedTitleText;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
if (messageTitle === '') {
|
|
528
|
+
messageTitle = mediaTag || pubDate.toUTCString();
|
|
212
529
|
} else {
|
|
213
|
-
messageTitle =
|
|
530
|
+
messageTitle = `${mediaTag}${mediaTag ? ' ' : ''}${messageTitle}`;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
let description = '';
|
|
534
|
+
if (showFwdFrom) {
|
|
535
|
+
description += fwdFrom();
|
|
536
|
+
}
|
|
537
|
+
if (showReplyTo) {
|
|
538
|
+
description += replyContent();
|
|
539
|
+
}
|
|
540
|
+
if (showViaBot) {
|
|
541
|
+
description += viaBot();
|
|
542
|
+
}
|
|
543
|
+
description += location() + poll() + contactHtml + voiceHtml + attachmentHtml + messageHtml + unsupportedHtml;
|
|
544
|
+
if (showLinkPreview) {
|
|
545
|
+
description += linkPreview();
|
|
214
546
|
}
|
|
547
|
+
description += inlineButtons + messageMedia;
|
|
215
548
|
|
|
216
549
|
return {
|
|
217
|
-
title:
|
|
218
|
-
description
|
|
550
|
+
title: messageTitle,
|
|
551
|
+
description,
|
|
219
552
|
pubDate,
|
|
220
553
|
link: item.find('.tgme_widget_message_date').attr('href'),
|
|
221
554
|
author: item.find('.tgme_widget_message_from_author').text(),
|
|
222
555
|
|
|
223
|
-
enclosure_url:
|
|
224
|
-
enclosure_length:
|
|
556
|
+
enclosure_url: voiceUrl,
|
|
557
|
+
enclosure_length: voiceDuration(),
|
|
225
558
|
enclosure_type: 'audio/ogg',
|
|
226
559
|
};
|
|
227
560
|
})
|
|
228
561
|
.get()
|
|
562
|
+
.filter((item) => item)
|
|
229
563
|
.reverse(),
|
|
230
564
|
};
|
|
231
565
|
};
|