This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweet.js
155 lines (123 loc) · 3.21 KB
/
tweet.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
var Tweet = function(streamItem) {
var INVISIBLE = 'ln-invisible';
var HIGHLIGHTED = 'ln-highlighted';
var cache = {};
function hide() {
$(streamItem).addClass(INVISIBLE);
}
function unhide() {
$(streamItem).removeClass(INVISIBLE);
}
function isHidden() {
return $(streamItem).hasClass(INVISIBLE);
}
function highlight() {
$(streamItem).addClass(HIGHLIGHTED);
}
function isHighlighted() {
return $(streamItem).hasClass(HIGHLIGHTED);
}
function id() {
if (!cache.id) {
cache.id = $(streamItem).data('item-id');
}
return cache.id;
}
// Returns either the author of a tweet, or the name of the retweeter if it is a retweet
function author() {
if (!cache.author) {
if (isRetweet()) {
cache.author = $(streamItem).find('div.context a.js-user-profile-link').attr('href').substring(1);
} else {
cache.author = $(streamItem).find('div.js-stream-tweet').data('screen-name');
}
}
return cache.author;
}
function isRetweet() {
return $(streamItem).find('div.tweet').data('retweet-id') !== undefined;
}
function characterSet() {
var txt = text();
var characterRanges = {
'arabic': '[\u0600-\u06FF]+', // http://en.wikipedia.org/wiki/Arabic_script_in_Unicode
'japanese': '[\u3040-\u309F]+', // Hiragana
'chinese': '[\u4E00-\u9FCC\u3400-\u4DB5]+' // http://stackoverflow.com/questions/1366068/whats-the-complete-range-for-chinese-characters-in-unicode
}
for (var key in characterRanges) {
if ((new RegExp(characterRanges[key])).test(txt)) {
return key;
}
}
return undefined;
}
function hashtags() {
if (!cache.hashtags) {
cache.hashtags = getHashtags();
}
return cache.hashtags;
}
function getHashtags() {
var result = [];
$(streamItem).find('.twitter-hashtag b').each(function() {
result.push($(this).text());
});
return result;
}
function mentions() {
if (!cache.mentions) {
cache.mentions = getMentions();
}
return cache.mentions;
}
function getMentions() {
var mentionsString = $(streamItem).find('.tweet').data('mentions');
if (mentionsString !== undefined) {
return mentionsString.toString().split(' ');
}
return [];
}
function links() {
if (cache.links) {
return cache.links;
}
var links = getLinks();
if (links.length === 0) {
cache.links = links;
}
return links;
}
function getLinks() {
var result = [];
$(streamItem).find('.twitter-timeline-link').each(function() {
var url = $(this).data('expanded-url');
if (url === undefined) {
url = $(this).attr('href');
}
result.push(url);
});
return result;
}
function hasLinks() {
return (links().length > 0);
}
function text() {
return $.trim($(streamItem).find('.js-tweet-text').text());
}
return {
id: id,
author: author,
characterSet: characterSet,
hashtags: hashtags,
mentions: mentions,
links: links,
hasLinks: hasLinks,
isRetweet: isRetweet,
text: text,
hide: hide,
unhide: unhide,
isHidden: isHidden,
highlight: highlight,
isHighlighted: isHighlighted
}
}