| changeset 1571 | 4a1e6952afe5 |
| parent 1558 | 761ba7426984 |
| child 1575 | ce1d5b0d1479 |
| 1570:c175d505e40d | 1571:4a1e6952afe5 |
|---|---|
52 |
52 |
53 function getGlobal(varkey, defaultValue) { |
53 function getGlobal(varkey, defaultValue) { |
54 return typeof(global[varkey]) == "undefined" ? defaultValue : global[varkey]; |
54 return typeof(global[varkey]) == "undefined" ? defaultValue : global[varkey]; |
55 } |
55 } |
56 |
56 |
57 function getSocialGroupUri(social_group) { |
|
58 const groupParts = social_group.replace(/^\@+/,"").split('@'); |
|
59 return `https://${groupParts[1]}/u/${groupParts[0]}` |
|
60 } |
|
61 |
|
62 |
|
57 //var i10n = getGlobal('i10n', { "rechercher" : "Rechercher" }); |
63 //var i10n = getGlobal('i10n', { "rechercher" : "Rechercher" }); |
58 |
64 |
59 var suggested_keywords = getGlobal('suggested_keywords',[]); |
65 const suggested_keywords = getGlobal('suggested_keywords',[]); |
60 |
66 |
61 var max_pages = getGlobal('max_pages', 5); |
67 const max_pages = getGlobal('max_pages', 5); |
62 |
68 |
63 var social_network = getGlobal('social_network', 'Twitter'); |
69 const social_network = getGlobal('social_network', 'Twitter'); |
70 const social_login_domain = getGlobal('social_login_domain'); |
|
71 const social_access_token = getGlobal('social_access_token'); |
|
72 const social_group = getGlobal('social_group'); |
|
64 |
73 |
65 tracking_keywords = _(getGlobal('tracking_keywords', [])).map(function(_w) { |
74 tracking_keywords = _(getGlobal('tracking_keywords', [])).map(function(_w) { |
66 return _w.toLowerCase(); |
75 return _w.toLowerCase(); |
67 }); |
76 }); |
68 |
77 |
109 'non', 'nos', 'nous', 'ont', 'oui', 'par', 'pas', 'peu', 'peut', 'plus', 'pour', 'que', 'qui', 'ses' ,'son', 'sont', 'sur', |
118 'non', 'nos', 'nous', 'ont', 'oui', 'par', 'pas', 'peu', 'peut', 'plus', 'pour', 'que', 'qui', 'ses' ,'son', 'sont', 'sur', |
110 'tes', 'très', 'the', 'ton', 'tous', 'tout', 'une', 'votre', 'vos', 'vous' |
119 'tes', 'très', 'the', 'ton', 'tous', 'tout', 'une', 'votre', 'vos', 'vous' |
111 ] |
120 ] |
112 } |
121 } |
113 |
122 |
123 function getSocialData() { |
|
124 return $.ajax({ |
|
125 beforeSend: function(request) { |
|
126 request.setRequestHeader('Authorization', `Bearer ${social_access_token}`); |
|
127 }, |
|
128 type: "GET", |
|
129 dataType: "json", |
|
130 url: `https://${social_login_domain}/api/v1/accounts/verify_credentials`, |
|
131 }); |
|
132 } |
|
133 |
|
134 function getFollowing(user_id) { |
|
135 return $.ajax({ |
|
136 beforeSend: function(request) { |
|
137 request.setRequestHeader('Authorization', `Bearer ${social_access_token}`); |
|
138 }, |
|
139 type: "GET", |
|
140 dataType: "json", |
|
141 url: `https://${social_login_domain}/api/v1/accounts/${user_id}/following`, |
|
142 }); |
|
143 } |
|
144 |
|
145 |
|
114 function getTweets(options) { |
146 function getTweets(options) { |
115 |
147 |
116 function getTweetUrl(url) { |
148 function getTweetUrl(url) { |
117 $.getJSON(url, function(data) { |
149 $.getJSON(url, function(data) { |
118 options.tweets = options.tweets.concat(data.statuses); |
150 options.tweets = options.tweets.concat(data.statuses); |
281 |
313 |
282 if (tweet.retweeted_status && tweet.retweeted_status.id_str) { |
314 if (tweet.retweeted_status && tweet.retweeted_status.id_str) { |
283 tweet.retweeted_status_id = tweet.retweeted_status.id_str; |
315 tweet.retweeted_status_id = tweet.retweeted_status.id_str; |
284 backRef( tweet.id, tweet.retweeted_status_id, "retweet" ); |
316 backRef( tweet.id, tweet.retweeted_status_id, "retweet" ); |
285 } |
317 } |
286 |
318 |
287 |
319 // clean full text from html |
288 var tab = tweet.full_text.replace(twCx.urlRegExp,'').match(twCx.wordRegExp); |
320 const temp_div_element = document.createElement("div"); |
321 temp_div_element.innerHTML = tweet.full_text; |
|
322 const full_text = temp_div_element.textContent || temp_div_element.innerText || tweet.full_text; |
|
323 |
|
324 var tab = full_text.replace(twCx.urlRegExp,'').match(twCx.wordRegExp); |
|
289 _(tab).each(function(w) { |
325 _(tab).each(function(w) { |
290 var word = w.toLowerCase(); |
326 var word = w.toLowerCase(); |
291 if (_(twCx.stopWords).indexOf(word) == -1 && _(tracking_keywords).indexOf(word) == -1 && word[0] != '@') { |
327 if (_(twCx.stopWords).indexOf(word) == -1 && _(tracking_keywords).indexOf(word) == -1 && word[0] != '@') { |
292 if (twCx.globalWords[word]) { |
328 if (twCx.globalWords[word]) { |
293 twCx.globalWords[word].freq++; |
329 twCx.globalWords[word].freq++; |
605 }); |
641 }); |
606 //lastend = Math.max(120, lastend); |
642 //lastend = Math.max(120, lastend); |
607 txt += highlight( full_text.substring(lastend) ); |
643 txt += highlight( full_text.substring(lastend) ); |
608 html += '<p class="tweet_text"><b>' + a_user + '<span title="'+tweet.user.screen_name+ '">' +highlight('@' + tweet.user.name) + '</span></a>' + ( className == 'full' ? ' (' + tweet.user.name + ')</b><br />' : '</b> : ') + txt + '</p>'; |
644 html += '<p class="tweet_text"><b>' + a_user + '<span title="'+tweet.user.screen_name+ '">' +highlight('@' + tweet.user.name) + '</span></a>' + ( className == 'full' ? ' (' + tweet.user.name + ')</b><br />' : '</b> : ') + txt + '</p>'; |
609 if (className == 'full' && el == 'li') { |
645 if (className == 'full' && el == 'li') { |
610 html += '<div class="tweet_actions"><a href="' + htmlAdapter.getMsgUrl() + '" onclick="tweetPopup(this.href); return false;" target="_blank">afficher tweet</a>'; |
646 html += '<div class="tweet_actions"><a href="' + htmlAdapter.getMsgUrl() + '" onclick="tweetPopup(this.href); return false;" target="_blank">afficher message</a>'; |
611 const replyUrl = htmlAdapter.getMsgReplyUrl(); |
647 const replyUrl = htmlAdapter.getMsgReplyUrl(); |
612 if (replyUrl) { html += '<a href="' + replyUrl + '" onclick="tweetPopup(this.href); return false;" target="_blank">répondre</a> · '; } |
648 if (replyUrl) { html += '<a href="' + replyUrl + '" onclick="tweetPopup(this.href); return false;" target="_blank">répondre</a> · '; } |
613 const retweetUrl = htmlAdapter.getMsgRetweetUrl(); |
649 const retweetUrl = htmlAdapter.getMsgRetweetUrl(); |
614 if (retweetUrl) { html += '<a href="' + retweetUrl + '" onclick="tweetPopup(this.href); return false;" target="_blank">retweeter</a> · '; } |
650 if (retweetUrl) { html += '<a href="' + retweetUrl + '" onclick="tweetPopup(this.href); return false;" target="_blank">retransmettre</a> · '; } |
615 const favoriteUrl = htmlAdapter.getMsgFavoriteUrl(); |
651 const favoriteUrl = htmlAdapter.getMsgFavoriteUrl(); |
616 if (favoriteUrl) { html += '<a href="' + favoriteUrl + '" onclick="tweetPopup(this.href); return false;" target="_blank">favori</a>'; } |
652 if (favoriteUrl) { html += '<a href="' + favoriteUrl + '" onclick="tweetPopup(this.href); return false;" target="_blank">favori</a>'; } |
617 html += '</div>'; |
653 html += '</div>'; |
618 } |
654 } |
619 } |
655 } |
1159 } |
1195 } |
1160 } |
1196 } |
1161 document.location.href = "data:text/json;base64," + btoa(_buf); |
1197 document.location.href = "data:text/json;base64," + btoa(_buf); |
1162 } |
1198 } |
1163 |
1199 |
1164 $(document).ready(function() { |
1200 function followSocialGroup() { |
1201 $.ajax({ |
|
1202 beforeSend: function(request) { |
|
1203 request.setRequestHeader('Authorization', `Bearer ${social_access_token}`); |
|
1204 }, |
|
1205 type: "POST", |
|
1206 dataType: "json", |
|
1207 url: `https://${social_login_domain}/api/v1/accounts/`, |
|
1208 }); |
|
1209 } |
|
1210 |
|
1211 function buildFollowLink() { |
|
1212 const sgroup = social_group.replace(/^\@+/,"") |
|
1213 $("#twwWrap").prepend(`<div id="socialGroupFollow" ><a target=”_blank” href="https://${social_login_domain}/authorize_interaction?uri=${sgroup}">Suivez le groupe ${social_group}</a> et recharger cette page</div>`) |
|
1214 } |
|
1215 |
|
1216 function checkSocialGroup() { |
|
1217 getSocialData().then( (data) => { |
|
1218 getFollowing(data.id).then((following_data) => { |
|
1219 let is_following_group = false; |
|
1220 for(const user_def of following_data) { |
|
1221 const group_uri = getSocialGroupUri(social_group) |
|
1222 if (user_def.uri == group_uri) { |
|
1223 is_following_group = true; |
|
1224 } |
|
1225 } |
|
1226 |
|
1227 $("#socialGroupFollow").remove(); |
|
1228 if(!is_following_group) { |
|
1229 buildFollowLink(); |
|
1230 setTimeout(function() { |
|
1231 checkSocialGroup(); |
|
1232 }, 5000); |
|
1233 } |
|
1234 }); |
|
1235 }); |
|
1236 } |
|
1237 |
|
1238 $(function() { |
|
1239 //twwWrap |
|
1240 if(social_network == "Mastodon") { |
|
1241 checkSocialGroup(); |
|
1242 } |
|
1243 |
|
1165 twCx.tlWidth = $("#timeline").width(); |
1244 twCx.tlWidth = $("#timeline").width(); |
1166 twCx.tlHeight = $("#timeline").height(); |
1245 twCx.tlHeight = $("#timeline").height(); |
1167 twCx.tlPaper = Raphael("timeline", twCx.tlWidth, twCx.tlHeight); |
1246 twCx.tlPaper = Raphael("timeline", twCx.tlWidth, twCx.tlHeight); |
1168 |
1247 |
1169 connectTweets(); |
1248 connectTweets(); |
1336 "y" : twCx.tlHeight - _h, |
1415 "y" : twCx.tlHeight - _h, |
1337 "height" : _h |
1416 "height" : _h |
1338 }) |
1417 }) |
1339 }, |
1418 }, |
1340 "cbEnd" : function() { |
1419 "cbEnd" : function() { |
1341 console.log(this.tweets); |
|
1342 loadTweets(this.tweets); |
1420 loadTweets(this.tweets); |
1343 setInterval(function() { |
1421 setInterval(function() { |
1344 getTweets({ |
1422 getTweets({ |
1345 "social_network" : social_network, |
1423 "social_network" : social_network, |
1346 "keyword" : tracking_keywords.join(" OR "), |
1424 "keyword" : tracking_keywords.join(" OR "), |
1358 |
1436 |
1359 export { |
1437 export { |
1360 rolloverTweet, |
1438 rolloverTweet, |
1361 selectTweet, |
1439 selectTweet, |
1362 filtrerTexte, |
1440 filtrerTexte, |
1363 tweetPopup |
1441 tweetPopup, |
1364 } |
1442 getSocialData, |
1443 getFollowing |
|
1444 } |