-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.js
2258 lines (1918 loc) · 70.1 KB
/
twitter.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Main kickoff function
$( document ).ready(function() {
showIntro();
}); // End Doc ready
function showIntro(){
$("html").addClass("intro");
var modal = `<div class="modal">
<div class="modal-body">
<p>Welcome to Fake Twitter,<br />where nothing is real.</p>
<p>Or is it? 😏</p>
<p>
<a href="#" class="button">
Enter Fake Twitter
<svg viewBox="0 0 24 24" class="r-13gxpu9 r-4qtqp9 r-yyyyoo r-16y2uox r-1q142lx r-8kz0gk r-dnmrzs r-bnwqim r-1plcrui r-lrvibr"><g><path d="M23.643 4.937c-.835.37-1.732.62-2.675.733.962-.576 1.7-1.49 2.048-2.578-.9.534-1.897.922-2.958 1.13-.85-.904-2.06-1.47-3.4-1.47-2.572 0-4.658 2.086-4.658 4.66 0 .364.042.718.12 1.06-3.873-.195-7.304-2.05-9.602-4.868-.4.69-.63 1.49-.63 2.342 0 1.616.823 3.043 2.072 3.878-.764-.025-1.482-.234-2.11-.583v.06c0 2.257 1.605 4.14 3.737 4.568-.392.106-.803.162-1.227.162-.3 0-.593-.028-.877-.082.593 1.85 2.313 3.198 4.352 3.234-1.595 1.25-3.604 1.995-5.786 1.995-.376 0-.747-.022-1.112-.065 2.062 1.323 4.51 2.093 7.14 2.093 8.57 0 13.255-7.098 13.255-13.254 0-.2-.005-.402-.014-.602.91-.658 1.7-1.477 2.323-2.41z"></path></g></svg>
</a>
</p>
</div>
<div class="modal-footer">
<p>
Made with ❤️ by <a href="https://twitter.com/solomania" target="_blank">@solomania</a>
| <a href="https://thecleverest.com/about-fake-twitter/" target="_blank">About Fake Twitter</a>
</p>
</div>
</div>`;
$(".main").append(modal);
// Click the button, load the thing
$( ".button" ).click(function(e) {
e.preventDefault();
$(this).addClass("clicked")
var screenWidth = screen.width;
var screenHeight = screen.height;
var targetHeight = screenHeight * 5; // Make the bird a little wider than screen
var targetTop = targetHeight / 2; // make the bird a little toward the top half
var svg = $(this).find("svg")
svg.height(targetHeight+"px")
svg.css({"top":"-"+targetTop+"px"})
setTimeout(function(){
$(".modal").fadeOut();
}, 800);
setTimeout(function(){
$("html").removeClass("intro");
begin();
}, 800);
});
} // end showIntro
function begin() {
// Start the timer
var startTime = moment();
/* Generate a few tweets to kick things off */
for (i = 0; i < 30; i++) {
addTweetToPage();
}
activatTweetTracking() // Do this after rendering tweets to track when they're in/out of view
// Add a footer
$(".main").append('<div id="footer"><img src="ajax-loader.gif" />Faking More Tweets...</div>');
// Add the nav
var nav = `
<div id="nav">
<span class="icon icon-home">
<svg viewBox="0 0 24 24" class="r-13gxpu9 r-4qtqp9 r-yyyyoo r-lwhw9o r-dnmrzs r-bnwqim r-1plcrui r-lrvibr"><g><path d="M22.58 7.35L12.475 1.897c-.297-.16-.654-.16-.95 0L1.425 7.35c-.486.264-.667.87-.405 1.356.18.335.525.525.88.525.16 0 .324-.038.475-.12l.734-.396 1.59 11.25c.216 1.214 1.31 2.062 2.66 2.062h9.282c1.35 0 2.444-.848 2.662-2.088l1.588-11.225.737.398c.485.263 1.092.082 1.354-.404.263-.486.08-1.093-.404-1.355zM12 15.435c-1.795 0-3.25-1.455-3.25-3.25s1.455-3.25 3.25-3.25 3.25 1.455 3.25 3.25-1.455 3.25-3.25 3.25z"></path></g></svg>
</span>
<span class="icon icon-search">
<svg viewBox="0 0 24 24" class="r-1re7ezh r-4qtqp9 r-yyyyoo r-lwhw9o r-dnmrzs r-bnwqim r-1plcrui r-lrvibr"><g><path d="M21.53 20.47l-3.66-3.66C19.195 15.24 20 13.214 20 11c0-4.97-4.03-9-9-9s-9 4.03-9 9 4.03 9 9 9c2.215 0 4.24-.804 5.808-2.13l3.66 3.66c.147.146.34.22.53.22s.385-.073.53-.22c.295-.293.295-.767.002-1.06zM3.5 11c0-4.135 3.365-7.5 7.5-7.5s7.5 3.365 7.5 7.5-3.365 7.5-7.5 7.5-7.5-3.365-7.5-7.5z"></path></g></svg>
</span>
<span class="icon icon-alerts">
<span class="badge-holder">
<!-- badges go here -->
</span>
<svg viewBox="0 0 24 24" class="r-1re7ezh r-4qtqp9 r-yyyyoo r-lwhw9o r-dnmrzs r-bnwqim r-1plcrui r-lrvibr"><g><path d="M21.697 16.468c-.02-.016-2.14-1.64-2.103-6.03.02-2.532-.812-4.782-2.347-6.335C15.872 2.71 14.01 1.94 12.005 1.93h-.013c-2.004.01-3.866.78-5.242 2.174-1.534 1.553-2.368 3.802-2.346 6.334.037 4.33-2.02 5.967-2.102 6.03-.26.193-.366.53-.265.838.102.308.39.515.712.515h4.92c.102 2.31 1.997 4.16 4.33 4.16s4.226-1.85 4.327-4.16h4.922c.322 0 .61-.206.71-.514.103-.307-.003-.645-.263-.838zM12 20.478c-1.505 0-2.73-1.177-2.828-2.658h5.656c-.1 1.48-1.323 2.66-2.828 2.66zM4.38 16.32c.74-1.132 1.548-3.028 1.524-5.896-.018-2.16.644-3.982 1.913-5.267C8.91 4.05 10.397 3.437 12 3.43c1.603.008 3.087.62 4.18 1.728 1.27 1.285 1.933 3.106 1.915 5.267-.024 2.868.785 4.765 1.525 5.896H4.38z"></path></g></svg>
</span>
<span class="icon icon-messages">
<span class="badge-holder">
<!-- badges go here -->
</span>
<svg viewBox="0 0 24 24" class="r-1re7ezh r-4qtqp9 r-yyyyoo r-lwhw9o r-dnmrzs r-bnwqim r-1plcrui r-lrvibr"><g><path d="M19.25 3.018H4.75C3.233 3.018 2 4.252 2 5.77v12.495c0 1.518 1.233 2.753 2.75 2.753h14.5c1.517 0 2.75-1.235 2.75-2.753V5.77c0-1.518-1.233-2.752-2.75-2.752zm-14.5 1.5h14.5c.69 0 1.25.56 1.25 1.25v.714l-8.05 5.367c-.273.18-.626.182-.9-.002L3.5 6.482v-.714c0-.69.56-1.25 1.25-1.25zm14.5 14.998H4.75c-.69 0-1.25-.56-1.25-1.25V8.24l7.24 4.83c.383.256.822.384 1.26.384.44 0 .877-.128 1.26-.383l7.24-4.83v10.022c0 .69-.56 1.25-1.25 1.25z"></path></g></svg>
</span>
</div>`;
$(".main").append(nav);
// Check when the footer's in viewm then generate some more tweets. That's it!
$('#footer').on('inview', function(event, isInView) {
if (isInView) {
// element is now visible in the viewport
// Small delay, then load more!
setTimeout(function(){
/* Generate more tweets */
for (i = 0; i < 30; i++) {
addTweetToPage();
}
activatTweetTracking() // Do this after rendering tweets to track when they're in/out of view
}, 1000);
} else {
// element has gone out of viewport
// Not used here
}
});
// Make nav elements clickable
$( "#nav .icon-alerts" ).click(function(e) {
e.preventDefault();
var now = moment();
var start = startTime;
var alertText = ``;
var seconds = now.diff(start, "seconds")
var status = pickARandom("statuses")
status = status.replace("_",seconds+" seconds")+" "+pickARandom("kudos")
status = status.replace("*",tweetsViewed)
alertText += status
alert(alertText)
notifications = 0;
updateNotificationsAndDMs();
});
// Generate useless alerts every so often
var t;
t = setInterval(newNotification, returnRandom(5000, 30000));
function newNotification(){
notifications++;
// Increase the value, show
console.log("new notification: current count is "+notifications)
updateNotificationsAndDMs();
// Clear old internal
clearInterval(t)
// Make a new random interval
t = setInterval(newNotification, returnRandom(5000, 30000));
}
}/* End function */
function addTweetToPage() {
// First make an object for the tweet
var tweetObj = generateTweet();
// Now feed that object into the function to render it, and get HTML
var tweetHTML = renderTweet(tweetObj)
// Now pop that HTML onto the page
$("#container").append(tweetHTML);
// Fade it in. We're done here
$(".item").fadeIn(300);
}
function generateTweet() {
// Here's the object that will tumble through this big function and
// pick up data along the way (like a katamari!), until it's returned at the end
// only to be rendered by a different function
var status = {};
// Let's roll a dice and decide what kind of tweet to make...
if (percentChance(60)) {
var tweetType = "news";
} else {
var tweetType = "person";
}
if (tweetType == "person"){
if (percentChance(1)) {
// Just amram for now
var tweetSubType = "personalTweets"
} else if (percentChance(25)) {
var tweetSubType = "mansplaining"
//debugger;
} else if (percentChance(25)) {
var tweetSubType = "magareply"
//debugger;
} else if (percentChance(25)) {
var tweetSubType = "trumpretweet"
//debugger;
} else {
var tweetSubType = "weirdtwitter"
}
}
// If it's personalTweets, filter the people that have tweets
// Anyone from "people" who you add a "tweets" array to, should work
if (tweetSubType == "personalTweets"){
// Filter just people who have tweets
var peopleWithTweets = people.filter( x => x["tweets"] != undefined );
status["user"] = pickARandom(peopleWithTweets)
var text = pickARandom(status["user"]["tweets"])
status["text"] = text;
status["retweet_count"] = returnRandom(100, 1000);
status["favorite_count"] = returnRandom(1000, 80000);
status["reply_count"] = returnRandom(10, 100);
status["timestamp"] = pickARandom(timestamps)
//debugger;
}
// If it's weirdtwitter, piece together some bullshit nonsense and give it tons of likes
if (tweetSubType == "weirdtwitter"){
status["type"] = "weirdtwitter";
var text = ``;
if (percentChance(50)){ // should be 50 in prod
text += pickARandom("weirdTwitterIntros") // "hey buddy ""
}
text += pickARandom("weirdTwitterNounPrefixes") // "this is my"
text += " " // space
text += pickARandom("weirdTwitterNouns") // "bidet"
if (percentChance(50)){ // should be 50 in prod
text += " " // space
text += pickARandom("weirdTwitterSuffixes") // "friendo"
}
//console.log("weirdtwitter: "+text) // hey buddy this is my bidet friendo
status["text"] = text;
// put username
status["user"] = pickARandom("weirdTwitterPeople")
var person = pickARandom("people")
//var reason = pickARandom("reasonsForShowingTweet")
//var reasonFull = reasonPerson["name"]+" "+reason
//status["reason"] = reason
status["person"] = person["name"];
status["retweet_count"] = returnRandom(100, 1000);
status["favorite_count"] = returnRandom(1000, 80000);
status["reply_count"] = returnRandom(10, 100);
status["timestamp"] = pickARandom(timestamps)
//debugger;
}
// If it's mansplaining, make a man replying to a women with unsolicited assholey stuff
if (tweetSubType == "mansplaining"){
// Pick a random topic that the women's tweeting about
var randomTopic = pickARandom("topics")
// Pick a subtopic the mansplainer will reply about
var subTopic = pickARandom(randomTopic["subTopics"])
// Start crafting the woman's original tweet...
var womanTweetWithPlaceholder = pickARandom("womanTweets")
// Replace the placeholder _ with the topic name
var womanTweet = womanTweetWithPlaceholder.replace("_TOPIC",randomTopic["name"])
// Here comes the asshole... "Let's take her down a peg!" he thinks...
var manTweetWithPlaceholders = pickARandom("mansplaining");
// Replace the placeholder _TOPIC and _SUBTOPIC with the right topic and subtopics
var manTweet = manTweetWithPlaceholders.replace("_TOPIC",randomTopic["name"])
manTweet = manTweet.replace("_SUBTOPIC",subTopic)
// Attach the man's tweet to the main status object
status["text"] = manTweet
// Make a new sub object for the original tweet (the woman's tweet), to which this is a reply
status["in_reply_to_status"] = {};
status["in_reply_to_status"]["text"] = womanTweet;
// Add stats for woman's tweet
status["in_reply_to_status"]["retweet_count"] = returnRandom(0, 5);
status["in_reply_to_status"]["favorite_count"] = returnRandom(0, 10);
status["in_reply_to_status"]["reply_count"] = returnRandom(0, 10);
status["in_reply_to_status"]["user"] = pickARandom("women");
// Add stats for man's tweet
status["retweet_count"] = returnRandom(0, 1);
status["favorite_count"] = returnRandom(0, 1);
status["reply_count"] = returnRandom(0, 10);
status["user"] = pickARandom("men");
status["timestamp"] = pickARandom(timestamps)
}
// If it's a maga reply, make a rangom semi-rambling but thoughtful tweet by a man or woman, and make a maga reply, similar to mansplaining
if (tweetSubType == "magareply"){
// Pick a man or woman
if (percentChance(50)){
var op = "women"
} else {
var op = "men"
}
// Make a new sub object for the original tweet, to which this is a reply
status["in_reply_to_status"] = {};
status["in_reply_to_status"]["user"] = pickARandom(op);
// Craft the OPs tweet
var tweet = ``;
tweet += pickARandom("randomTweetIntros")
tweet += " "
tweet += pickARandom("randomTweetTopics")
tweet += " "
tweet += pickARandom("randomTweetRealized")
tweet += " "
tweet += pickARandom("randomTweetNeed")
tweet += " "
tweet += pickARandom("randomTweetMoreOf")
tweet += " "
tweet += pickARandom("randomTweetLessOf")
status["in_reply_to_status"]["text"] = tweet;
// Add stats for OPs tweet
status["in_reply_to_status"]["retweet_count"] = returnRandom(0, 5);
status["in_reply_to_status"]["favorite_count"] = returnRandom(0, 10);
status["in_reply_to_status"]["reply_count"] = returnRandom(0, 10);
// Add stats for maga tweet
status["retweet_count"] = returnRandom(0, 1);
status["favorite_count"] = returnRandom(0, 1);
status["reply_count"] = returnRandom(0, 10);
status["user"] = pickARandom("magaReplyPeople");
// Attach the maga tweet to the main status object
status["text"] = pickARandom("magaReplies")
status["timestamp"] = pickARandom(timestamps)
}
if (tweetSubType == "trumpretweet"){
// Someone's retweeting without a comment
status["user"] = pickARandom("trump")
// Make their retweet
status["retweeted_status"] = {}
status["retweeted_status"]["user"] = pickARandom("trumpRetweets")
status["retweeted_status"]["text"] = pickARandom(status["retweeted_status"]["user"].tweets)
// Add stats
status["retweeted_status"]["retweet_count"] = returnRandom(100, 1000);
status["retweeted_status"]["favorite_count"] = returnRandom(1000, 10000);
status["retweeted_status"]["reply_count"] = returnRandom(10, 100);
status["timestamp"] = pickARandom(timestamps)
}
// If it's news, generate some "news" consisting of a mishmash from the trump news cycle
if (tweetType == "news"){
/*
News formats:
- as a card: text/image/domain
- retweeted: as text/link/image with news source user
The types of ways news can appear
- in regular tweet (as card)
- as retweet
*/
// Generate some stuff then decide how/where to use it
var fakeNews = generateFakeNews();
//debugger;
if (percentChance(33)) {
// Someone's sharing an actual link in their tweet
status["user"] = pickARandom("people")
status["text"] = pickARandom("readyMadeTweets")
status["card"] = {}
status["card"]["image"] = fakeNews["image"]
status["card"]["headline"] = fakeNews["headline"]
// Pick a source for the attribution
var source = pickARandom("sources")
status["card"]["domain"] = source["domain"]
// Add stats
status["retweet_count"] = returnRandom(100, 1000);
status["favorite_count"] = returnRandom(1000, 10000);
status["reply_count"] = returnRandom(10, 100);
status["timestamp"] = pickARandom(timestamps)
} else if (percentChance(33)) {
// Someone's retweeting WITH a comment
status["user"] = pickARandom("people")
status["text"] = pickARandom("readyMadeTweets")
// Make their retweet
var source = pickARandom("sources")
status["retweeted_status"] = {}
status["retweeted_status"]["text"] = `${fakeNews["headline"]} <span class="url">${source.url}/${makeid()}</span>`
status["retweeted_status"]["image"] = fakeNews["image"]
status["retweeted_status"]["user"] = source
// Add stats
status["retweet_count"] = returnRandom(100, 1000);
status["favorite_count"] = returnRandom(1000, 10000);
status["reply_count"] = returnRandom(10, 100);
status["timestamp"] = pickARandom(timestamps)
} else {
// Someone's retweeting without a comment
status["user"] = pickARandom("people")
// Make their retweet
var source = pickARandom("sources")
status["retweeted_status"] = {}
status["retweeted_status"]["text"] = `${fakeNews["headline"]} <span class="url">${source.url}/${makeid()}</span>`
status["retweeted_status"]["image"] = fakeNews["image"]
status["retweeted_status"]["user"] = source
// Add stats
status["retweeted_status"]["retweet_count"] = returnRandom(100, 1000);
status["retweeted_status"]["favorite_count"] = returnRandom(1000, 10000);
status["retweeted_status"]["reply_count"] = returnRandom(10, 100);
status["timestamp"] = pickARandom(timestamps)
}
function generateFakeNews() {
var h = ``;
//debugger;
/* Quoted Headline, ie "According to Trump: Blah blah blah..." */
if (percentChance(20)) { // should be 20
var quotedHeadline = true;
}
if (quotedHeadline) {
//console.log("quoted headline, show the quoted person's photo");
//var randomNounIndex = returnRandom(0, nounsClone.length-1);
var randomNoun = pickARandom("nouns")
var quotedName = randomNoun["name"];
if (percentChance(50)) {
h += "According to "+quotedName+", ";
} else if (percentChance(50)) {
h += "BREAKING: "+quotedName+", ";
} else {
var quotedHeadlineTypeBrief = true;
h += quotedName+": \""; // Don't forget to end the quote at the end...
}
var headlineImage = pickARandom(randomNoun["images"])
//debugger;
}
if (percentChance(50)) {
var usePrefixes = true;
} else {
var usePrefixes = false;
}
// should be 50 or less?
if (usePrefixes) {
h += pickARandom("nounPrefixes");
}
// Pick the main subject of the headline
var mainPersonObj = pickARandom("nouns")
var mainPerson = mainPersonObj["name"];
var mainPersonSide = mainPersonObj["side"];
h += mainPerson;
//console.log("main person is: "+mainPerson);
if (!quotedHeadline) {
var headlineImage = pickARandom(mainPersonObj["images"]); // get the image of the person who's the main subject of the headline
}
if (usePrefixes) {
h += " "+pickARandom("nounSuffixes");
}
// Main Verb
var randomVerb = pickARandom("verbs");
h += randomVerb["text"]; // "Paul Manafort Moves On"
// Don't show the last details if it's a short quoted headline; doesn't seem believable
if (percentChance(50) && !quotedHeadlineTypeBrief) { // should be around 50?
//debugger;
var detailsWithPlaceholder = pickARandom("details");
var nounForDetails = pickARandom("nouns")
var details = detailsWithPlaceholder.replace("_",nounForDetails["name"])
h += details;
}
if (quotedHeadlineTypeBrief) {
h += '"';
}
var objectToReturn = {
"headline":h,
"image":headlineImage
};
//console.table("headline: "+h)
//debugger;
return objectToReturn
} // end generateFakeNews
} // end if tweet type is news
//console.table(status)
//debugger;
return status;
} /* End generateTweet */
function renderTweet(tweetObj){
//debugger;
var output = ''; // This is the main string we'll append to. React Shmreact!
// Create the shell item
output += '<div class="item" style="display:none;">'; // Set to display none, then fadeIn once built and added to dom
// If there's no tweet text and a retweeted status, say why it's on your timeline
if (!tweetObj.text && tweetObj.retweeted_status) {
output += `<span class="reason reason-retweeted">
<svg viewBox="0 0 24 24" class="r-1re7ezh r-4qtqp9 r-yyyyoo r-1xvli5t r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-1xzupcd"><g><path d="M23.615 15.477c-.47-.47-1.23-.47-1.697 0l-1.326 1.326V7.4c0-2.178-1.772-3.95-3.95-3.95h-5.2c-.663 0-1.2.538-1.2 1.2s.537 1.2 1.2 1.2h5.2c.854 0 1.55.695 1.55 1.55v9.403l-1.326-1.326c-.47-.47-1.23-.47-1.697 0s-.47 1.23 0 1.697l3.374 3.375c.234.233.542.35.85.35s.613-.116.848-.35l3.375-3.376c.467-.47.467-1.23-.002-1.697zM12.562 18.5h-5.2c-.854 0-1.55-.695-1.55-1.55V7.547l1.326 1.326c.234.235.542.352.848.352s.614-.117.85-.352c.468-.47.468-1.23 0-1.697L5.46 3.8c-.47-.468-1.23-.468-1.697 0L.388 7.177c-.47.47-.47 1.23 0 1.697s1.23.47 1.697 0L3.41 7.547v9.403c0 2.178 1.773 3.95 3.95 3.95h5.2c.664 0 1.2-.538 1.2-1.2s-.535-1.2-1.198-1.2z"></path></g></svg>
${tweetObj.user.name} Retweeted
</span>`;
}
// Left column, just contains avatars and reply line
if (tweetObj.in_reply_to_status){
var replyClass = "has-reply"
} else {
var replyClass = ""
}
output += `<div class="leftcol ${replyClass}">`;
if (tweetObj.text == undefined){
var avatarURL = tweetObj.retweeted_status.user.image
} else if (tweetObj.in_reply_to_status){
var avatarURL = tweetObj.in_reply_to_status.user.image
} else {
var avatarURL = tweetObj.user.image
}
output += '<span class="avatar" style="background-image:url('+avatarURL+')"></span>';
output += '</div>';// end leftcol
output += `<div class="content ${replyClass}">`;
output += '<div class="header">';
// Make the name the person being replied to, or retweeted, or just who's tweeting
if (tweetObj.in_reply_to_status){
var mainUser = tweetObj.in_reply_to_status.user;
} else if (tweetObj.retweeted_status && !tweetObj.text){
var mainUser = tweetObj.retweeted_status.user;
} else {
var mainUser = tweetObj.user;
}
output += '<h3>'+mainUser.name+'</h3>';
if (mainUser.verified == "true") {
output += '<span class="verified"></span>';
}
output += `<span class="handle">@${mainUser.handle}</span> <span class="dot">•</span> <span class="time">${tweetObj.timestamp}</span> </span>`;
output += '</div>'; // end header
output += '<div class="tweet">';
// Make the tweet the person being replied to, or retweeted, or just who's tweeting
if (tweetObj.in_reply_to_status){
var tweet = tweetObj.in_reply_to_status;
} else if (tweetObj.retweeted_status && !tweetObj.text){
var tweet = tweetObj.retweeted_status;
var image = tweetObj.retweeted_status.image;
} else {
var tweet = tweetObj;
}
output += '<p>'+tweet.text+'</p>';
if (image){
output += `<span class="bg-image">
<img src="${image}" />
</span>`;
}
// Show a card if it's there. Otherwise, show the retweeted status :-)
if (tweet.card){
output += '<div class="card" style="background-color:white;">';
output += `<span class="bg-image">
<img src="${tweet.card.image}" />
</span>`;
output += '<h3>'+tweet.card.headline+'</h3>';
output += `<p class="domain">
<svg viewBox="0 0 24 24" class="r-4qtqp9 r-yyyyoo r-1xvli5t r-dnmrzs r-bnwqim r-1plcrui r-lrvibr"><g><path d="M11.96 14.945c-.067 0-.136-.01-.203-.027-1.13-.318-2.097-.986-2.795-1.932-.832-1.125-1.176-2.508-.968-3.893s.942-2.605 2.068-3.438l3.53-2.608c2.322-1.716 5.61-1.224 7.33 1.1.83 1.127 1.175 2.51.967 3.895s-.943 2.605-2.07 3.438l-1.48 1.094c-.333.246-.804.175-1.05-.158-.246-.334-.176-.804.158-1.05l1.48-1.095c.803-.592 1.327-1.463 1.476-2.45.148-.988-.098-1.975-.69-2.778-1.225-1.656-3.572-2.01-5.23-.784l-3.53 2.608c-.802.593-1.326 1.464-1.475 2.45-.15.99.097 1.975.69 2.778.498.675 1.187 1.15 1.992 1.377.4.114.633.528.52.928-.092.33-.394.547-.722.547z"></path><path d="M7.27 22.054c-1.61 0-3.197-.735-4.225-2.125-.832-1.127-1.176-2.51-.968-3.894s.943-2.605 2.07-3.438l1.478-1.094c.334-.245.805-.175 1.05.158s.177.804-.157 1.05l-1.48 1.095c-.803.593-1.326 1.464-1.475 2.45-.148.99.097 1.975.69 2.778 1.225 1.657 3.57 2.01 5.23.785l3.528-2.608c1.658-1.225 2.01-3.57.785-5.23-.498-.674-1.187-1.15-1.992-1.376-.4-.113-.633-.527-.52-.927.112-.4.528-.63.926-.522 1.13.318 2.096.986 2.794 1.932 1.717 2.324 1.224 5.612-1.1 7.33l-3.53 2.608c-.933.693-2.023 1.026-3.105 1.026z"></path></g></svg>
${tweet.card.domain}
</p>`;
output += '</div>';
} else if (tweet.retweeted_status){
output += '<div class="card" style="background-color:white;">';
output += '<div class="header">';
output += '<span class="avatar" style="background-image:url('+tweet.retweeted_status.user.image+')"></span>';
output += '<h3>'+tweet.retweeted_status.user.name+'</h3>';
if (tweet.retweeted_status.user.verified == "true") {
output += '<span class="verified"></span>';
}
output += `<span class="handle">@${tweet.retweeted_status.user.handle}</span> <span class="dot">•</span> <span class="time">${tweetObj.timestamp}</span> </span>`;
output += '</div>';
output += '<p>'+tweet.retweeted_status.text+'</p>';
output += `<span class="bg-image">
<img src="${tweet.retweeted_status.image}" />
</span>`;
output += '</div>';
}
// end if card
output += '</div>'; // end tweet
output += renderTweetStats()
output += '</div>'; // end content
// Add any replies if they exist
if (tweetObj.in_reply_to_status) {
output += `<div class="reply-spacer"></div>`;
output += `<div class="leftcol is-reply">`;
output += '<span class="avatar" style="background-image:url('+tweetObj.user.image+')"></span>';
output += '</div>';// end leftcol
output += '<div class="content">';
output += '<div class="header">';
var mainUser = tweetObj.user;
output += '<h3>'+mainUser.name+'</h3>';
if (mainUser.verified == "true") {
output += '<span class="verified"></span>';
}
output += `<span class="handle">@${mainUser.handle}</span> <span class="dot">•</span> <span class="time">${tweetObj.timestamp}</span> </span>`;
output += '</div>'; // end header
output += '<div class="tweet">';
var tweet = tweetObj;
output += '<p>'+tweet.text+'</p>';
output += '</div>'; // end tweet
output += renderTweetStats()
output += '</div>'; // end content
} // end reply check
function renderTweetStats(){
var output = `
<div class="stats">
<span class="replies">
<svg viewBox="0 0 24 24" class="r-4qtqp9 r-yyyyoo r-1xvli5t r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-1hdv0qi"><g><path d="M14.046 2.242l-4.148-.01h-.002c-4.374 0-7.8 3.427-7.8 7.802 0 4.098 3.186 7.206 7.465 7.37v3.828c0 .108.044.286.12.403.142.225.384.347.632.347.138 0 .277-.038.402-.118.264-.168 6.473-4.14 8.088-5.506 1.902-1.61 3.04-3.97 3.043-6.312v-.017c-.006-4.367-3.43-7.787-7.8-7.788zm3.787 12.972c-1.134.96-4.862 3.405-6.772 4.643V16.67c0-.414-.335-.75-.75-.75h-.396c-3.66 0-6.318-2.476-6.318-5.886 0-3.534 2.768-6.302 6.3-6.302l4.147.01h.002c3.532 0 6.3 2.766 6.302 6.296-.003 1.91-.942 3.844-2.514 5.176z"></path></g></svg>
${abbrNum(tweet.reply_count, 1)}
</span>
<span class="retweets">
<svg viewBox="0 0 24 24" class="r-4qtqp9 r-yyyyoo r-1xvli5t r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-1hdv0qi"><g><path d="M23.77 15.67c-.292-.293-.767-.293-1.06 0l-2.22 2.22V7.65c0-2.068-1.683-3.75-3.75-3.75h-5.85c-.414 0-.75.336-.75.75s.336.75.75.75h5.85c1.24 0 2.25 1.01 2.25 2.25v10.24l-2.22-2.22c-.293-.293-.768-.293-1.06 0s-.294.768 0 1.06l3.5 3.5c.145.147.337.22.53.22s.383-.072.53-.22l3.5-3.5c.294-.292.294-.767 0-1.06zm-10.66 3.28H7.26c-1.24 0-2.25-1.01-2.25-2.25V6.46l2.22 2.22c.148.147.34.22.532.22s.384-.073.53-.22c.293-.293.293-.768 0-1.06l-3.5-3.5c-.293-.294-.768-.294-1.06 0l-3.5 3.5c-.294.292-.294.767 0 1.06s.767.293 1.06 0l2.22-2.22V16.7c0 2.068 1.683 3.75 3.75 3.75h5.85c.414 0 .75-.336.75-.75s-.337-.75-.75-.75z"></path></g></svg>
${abbrNum(tweet.retweet_count, 1)}
</span>
<span class="likes">
<svg viewBox="0 0 24 24" class="r-4qtqp9 r-yyyyoo r-1xvli5t r-dnmrzs r-bnwqim r-1plcrui r-lrvibr r-1hdv0qi"><g><path d="M12 21.638h-.014C9.403 21.59 1.95 14.856 1.95 8.478c0-3.064 2.525-5.754 5.403-5.754 2.29 0 3.83 1.58 4.646 2.73.814-1.148 2.354-2.73 4.645-2.73 2.88 0 5.404 2.69 5.404 5.755 0 6.376-7.454 13.11-10.037 13.157H12zM7.354 4.225c-2.08 0-3.903 1.988-3.903 4.255 0 5.74 7.034 11.596 8.55 11.658 1.518-.062 8.55-5.917 8.55-11.658 0-2.267-1.823-4.255-3.903-4.255-2.528 0-3.94 2.936-3.952 2.965-.23.562-1.156.562-1.387 0-.014-.03-1.425-2.965-3.954-2.965z"></path></g></svg>
${abbrNum(tweet.favorite_count, 1)}
</span>
</div>`;
return output;
}
output += '</div>'; // end item div
return output;
} // end renderTweet
function updateNotificationsAndDMs(){
// Make the front-end match the values for
if (notifications == 0) {
var badgeHTML = ``;
} else {
var badgeHTML = `<span class="badge">${notifications}</span>`;
}
$(".icon-alerts .badge-holder").html(badgeHTML);
}
function activatTweetTracking(){
// Remove all existing listeners, so we don't double-count
$('.item').unbind('inview');
// Check when the footer's in viewm then generate some more tweets. That's it!
$('.item').on('inview', function(event, isInView) {
if (isInView) {
} else {
// element has gone out of viewport
console.log("tweet viewed")
tweetsViewed++;
}
});
} // end function
function pickARandom(array){
// If it's a string, we want to cache it and prevent duplicates
if (typeof array === 'string') {
//console.log("string")
// See if we already have a cached, pruned version
var matchFromCache = cache[array]
// If it's undefined, make it!
if (matchFromCache == undefined){
var originalArray = eval(array).slice(0);
cache[array] = originalArray
}
// Pick a random one
var randomIndex = returnRandom(0, cache[array].length-1);
var itemToReturn = cache[array][randomIndex]
// Remove it!
cache[array].splice(randomIndex, 1);
// If we've removed them all, add it back
if (cache[array].length == 0){
var originalArray = eval(array).slice(0);
cache[array] = originalArray
}
} else {
// If it's an array, just pick one and return it
var randomIndex = returnRandom(0, array.length-1);
var itemToReturn = array[randomIndex];
}
return itemToReturn;
}
function smartPlural(number, denom){
// Divide by the number - if it's 1
try{
// For example 60 / 1 seconds: 1 second, so it should be singluar
if (denom / number == denom) {
return "";
} else {
return "s"; // Otherwise return nothing
}
}
catch(e){
return "s"; // catch divide by zero
}
}
function getName(index, nounsClone){
return nounsClone[index]["name"];
}
function getImage(index, source){
//debugger;
//var person = G.nouns[Math.floor(Math.random()*G.nouns.length)];
var images = source[index]["images"];
var randomImageIndex = returnRandom(0, images.length-1);
return images[randomImageIndex];
}
function getRandomNounImage(){
var randomIndex = returnRandom(0, nounsClone.length-1);
//var person = G.nouns[Math.floor(Math.random()*G.nouns.length)];
//var randomIndex = returnRandom(0, G.readymade.length-1)
//var randomName = G.readymade[randomIndex];
//debugger; //TODO get random index from length of images array, and return a random 1
//return person["name"];
}
function getRandom(x){
return G[x][Math.floor(Math.random()*G[x].length)]
}
function randomWord(x, nounsClone) { //x is word type
var word = x[Math.floor(Math.random()*x.length)];
// if word contains an underscore, replace it with an unused noun, otherwise just return the whole thing
if (word.indexOf('_') > -1) {
var fields = word.split('_');
var o = fields[0];
//o += "Solomon";
//debugger;
var randomNounIndex = returnRandom(0, nounsClone.length-1);
var name = getName(randomNounIndex, nounsClone);
o += name;
o += fields[1];
return o;
//debugger;
} else {
return word;
}
// split the string to get the token
//
}
function percentChance(percent){
var randomnumber = Math.floor(Math.random()*101);
if(percent>randomnumber){
return true;
}else{
return false;
}
}
function getFirstWord(x) {
var arr = x.split(/\s+/);
return arr[0];
}
function returnRandom(x,y,z) {
//debugger;
if (z == "negOrPos") {
if (percentChance(50)) {
return Math.floor(Math.random()*(y-x+1)+x);
} else {
return -Math.floor(Math.random()*(y-x+1)+x);
}
} else {
return Math.floor(Math.random()*(y-x+1)+x);
}
}
function abbreviateNumber(value) {
var newValue = value;
if (value >= 1000) {
var suffixes = ["", "k", "m", "b","t"];
var suffixNum = Math.floor( (""+value).length/3 );
var shortValue = '';
for (var precision = 2; precision >= 1; precision--) {
shortValue = parseFloat( (suffixNum != 0 ? (value / Math.pow(1000,suffixNum) ) : value).toPrecision(precision));
var dotLessShortValue = (shortValue + '').replace(/[^a-zA-Z 0-9]+/g,'');
if (dotLessShortValue.length <= 2) { break; }
}
if (shortValue % 1 != 0) shortNum = shortValue.toFixed(1);
newValue = shortValue+suffixes[suffixNum];
}
return newValue;
}
function abbrNum(number, decPlaces) {
// 2 decimal places => 100, 3 => 1000, etc
decPlaces = Math.pow(10,decPlaces);
// Enumerate number abbreviations
var abbrev = [ "k", "m", "b", "t" ];
// Go through the array backwards, so we do the largest first
for (var i=abbrev.length-1; i>=0; i--) {
// Convert array index to "1000", "1000000", etc
var size = Math.pow(10,(i+1)*3);
// If the number is bigger or equal do the abbreviation
if(size <= number) {
// Here, we multiply by decPlaces, round, and then divide by decPlaces.
// This gives us nice rounding to a particular decimal place.
number = Math.round(number*decPlaces/size)/decPlaces;
// Handle special case where we round up to the next abbreviation
if((number == 1000) && (i < abbrev.length - 1)) {
number = 1;
i++;
}
// Add the letter for the abbreviation
number += abbrev[i];
// We are done... stop