-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathfacebookdemetricator.user.js
4627 lines (3587 loc) · 306 KB
/
facebookdemetricator.user.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
// ==UserScript==
// @name Facebook Demetricator
// @version 1.7.1
// @namespace facebookdemetricator
// @description Removes all the metrics from Facebook
// @updateURL http://bengrosser.com/fbd/facebookdemetricator.meta.js
// @downloadURL https://bengrosser.com/fbd/facebookdemetricator.user.js
//
//
// @match *://*.facebook.com/*
// @include *://*.facebook.com/*
// @include *://*.facebookcorewwwi.onion/*
// @exclude *://*.facebook.com/ai.php*
// @exclude *://*.facebook.com/ajax/*
// @exclude *://*.facebook.com/dialog/*
// @exclude *://*.facebook.com/connect/*
// @exclude *://*.facebook.com/xti.php*
// @exclude *://developers.facebook.com/*
// @exclude *://code.facebook.com/*
// @exclude *://*.facebookcorewwwi.onion/ai.php*
// @exclude *://*.facebookcorewwwi.onion/ajax/*
// @exclude *://*.facebookcorewwwi.onion/dialog/*
// @exclude *://*.facebookcorewwwi.onion/connect/*
// @exclude *://*.facebookcorewwwi.onion/xti.php*
// @exclude *://developers.facebookcorewwwi.onion/xti.php*
// @exclude *://code.facebookcorewwwi.onion/xti.php*
//
// @icon http://bengrosser.com/fbd/fbd-logo-32.png
//
// ==/UserScript==// -----------------------------------------
// -----------------------------------------------------------------
// Facebook Demetricator
// 2012-present
//
// Benjamin Grosser
// http://bengrosser.com
//
// Winner of a Terminal Award for 2012-13
// http://terminalapsu.org
//
// Version 1.7.1
// http://bengrosser.com/projects/facebook-demetricator/
//
// Major Exhibitions:
// 2012 Prospectives '12, University of Reno at Nevada
// 2013 The Public Private, New School, NY, NY
// 2013 Public Assembly, The White Building, London, UK
// 2014 Arte Laguna Finalist Exhibition, Telecom Italia Future Centre, Venice, Italy
// 2014 Theorizing the Web, Windmill Studios, Brooklyn, NY
// 2014 Suggestions for Art That Could Be Called Red, Museum of Contemporary Cuts, online
// 2015 #nfcdab digital.art.biennale, Wroclaw, Poland
// 2015 Systems Under Liberty, Galerie Charlot, Paris, France
// 2016 Unlike, Chapelle des Augustins, Poitiers, France
// 2016 Data Materialities, SIGGRAPH, Los Angeles, CA
// ------------------------------------------------------------------------------------
// THANKS to my beta test team!!
// Selina, Hugh, Jeff, Dan B., Dan G., Keith, Ashley, Janelle, Elizabeth, Keri, Kate
//
// THANKS to my graph search beta test team!
// Joe, Molly
//
// TODO fully demetricate new messages interface (have a few quick fixes for now)
// TODO photoTextSubtitle settings/public icon should stay showing
// globals
var startURL; // page that loaded the userscript
var curURL = ''; // supposed url of the current page
var j; // jQuery
var demetricatorON = true; // loads ON by default
var currentChatCount; // tracks the chat count
var currentMoreChatCount;
var currentLikeCount; // for tracking likes in the dialog
var currentTitleText; // current (non-metric) count of $('title')
var timelineView = false;
var searchBarWidth = "350px";
var newSearchBarWidth = 350;
var newSearchBarWidthNarrow = 350;
// constants
var FADE_SPEED = 175; // used in jQuery fadeIn()/fadeOut()
var ELEMENT_POLL_SPEED = 750; // waitForKeyElements polling interval
var VERSION_NUMBER = '1.7.1'; // used in the console logging
var KEY_CONTROL = false; // debug kb control
var FAN_PAGE_URL = 'http://bengrosser.com';
var DEMETRICATOR_HOME_URL = 'http://bengrosser.com/projects/facebook-demetricator/';
var GROSSER_URL = 'http://bengrosser.com/';
var IS_SAFARI_OR_FIREFOX_ADDON = false; // is this a Firefox or Safari addon?
var IS_FIREFOX_ADDON = false; // is this just Firefox? Need to adjust some things for FF' slow performance
var DBUG = false; // more debugging
var FUNCTION_REPORT = false; // rudimentary function reporting to the console
var HAS_GRAPH_SEARCH = true; // does the user have graph search?
// setInterval element counts
var streamStoryCount = 0;
var timelineUnitCount = 0;
var commentCount = 0;
var photoGridCount = 0;
var favoritesCount = 0;
var friendBrowserCount = 0;
var notificationItemCount = 0;
var graphSearchPhotoCount = 0;
var graphSearchResultCount = 0;
var appSectionCount = 0;
var appSectionCountVER2 = 0;
var friendBlockCount = 0;
var friendBlockCountVER2 = 0;
// state
var demetricating = false;
// jQuery selectors that fade in/out on toggle
var fadeClasses = [
'.facebookmetric_fade'
];
// jQuery selectors that hide/show on toggle
var hideShowClasses = [
'.facebookmetric_hideshow'
];
// some metrics need to be set to opacity:0 instead of hidden, so that the space
// they occupy doesn't collapse
var opacityClasses = [
'.fbtimelineblockcount',
'.fbTimelineHeadlineStats',
'.photoText .fsm.fwn.fcg',
'.facebookmetric_opacity'
];
// sometimes metrics need to be swapped with something else (e.g. generic text)
// there are toggleON and toggleOFF classes, corresponding to demetrication states
var toggleOnOffClasses = [
'.facebookmetric_toggle'
];
// cleaner syntax than match()
String.prototype.contains = function(it) { return this.indexOf(it) != -1; };
// toggleDemetricator()
//
// called whenever the checkbox is toggled to fade/hide/show metrics in/out
// most of this is handled through the hiding/showing of classes that have already
// been inserted into FB's HTML via demetricate()
function toggleDemetricator() {
if(demetricatorON) {
if(DBUG) console.time('demetricatorON timer');
// red/white top-left notification icons
j('span.facebookmetricreq').fadeOut(FADE_SPEED);
j('span.facebookmetricmsg').fadeOut(FADE_SPEED);
j('span.facebookmetricnot').fadeOut(FADE_SPEED);
// after fading the metric, hide its parent
setTimeout(function() {
j('.facebookmetricreqp').hide();
j('.facebookmetricmsgp').hide();
j('.facebookmetricnotp').hide();
}, 500);
// do this here so it happens before searchbar length changes
demetricateHomeCount();
// re-run demetricate() in case of new content
if(FUNCTION_REPORT) console.log("calling demetricate from toggleDemetricator()");
demetricate();
// graph search
if(HAS_GRAPH_SEARCH) {
demetricateGraphSearchResults();
// --- REMOVE 1.7
//demetricateGraphSearchSelectorOverview();
}
// fade out all selectors in fadeClasses
j.each(fadeClasses, function(index, value) { j(value).fadeOut(); });
// hide all selectors in hideShowClasses
j.each(hideShowClasses, function(index, value) { j(value).hide(); });
// hide all toggle classes in toggleOnOffClasses
j.each(toggleOnOffClasses, function(index, value) {
j(value+'OFF').hide();
j(value+'ON').show();
});
// FB changes, 2/20/2012
j('.fbNubButton span.label').hide();
j('.fbNubButton span.fbdchatlabel').show();
// drop-down on the timeline ribbon
j('.fbTimelineMoreButton').find('.fbTimelineRibbon').find('.text').animate({color:"#fff"}, FADE_SPEED);
// a few metrics need to fade out while holding their space
j.each(opacityClasses, function(index, value) { j(value).animate({opacity:0}, FADE_SPEED); });
// view all XX comments
j('.fbviewallcomments').each(function() { j(this).attr('value',j(this).attr('newvalue')); });
// timeline add friend +1 icons
j('#pagelet_friends span.FriendLink i').hide();
j('#pagelet_friends span.FriendLink a').css('padding-left','0px');
// newsfeed attachment +1 icons
j('.addButton i').not('.FriendRequestAdd').hide();
j('.addButton').not('.FriendRequestAdd').css('padding-left','0px');
// event and timeline activity counts (possibly elsewhere)
j('.counter').fadeOut(FADE_SPEED);
if(DBUG) console.timeEnd('demetricatorON timer');
}
// else reveal all the previously demetricated metrics
else {
if(DBUG) console.time('demetricatorOFF timer');
// removing the style attr on the parents enables care-free automatic updating
// of the notification numbers.
j('span.facebookmetricreqp').removeAttr('style');
j('span.facebookmetricmsgp').removeAttr('style');
j('span.facebookmetricnotp').removeAttr('style');
// do this here before search bar length changes
j('.facebook_homecount').show();
// only if the notification counts are > 0 do we want them to fade in
// otherwise, remove the style attribute alltogether so it doesn't interfere w/ FB's
// method for updating the count and showing the number when it wants to
if(parseInt(j('#requestsCountValue').text())) j('.facebookmetricreq').fadeIn(FADE_SPEED);
if(parseInt(j('#mercurymessagesCountValue').text())) j('.facebookmetricmsg').fadeIn(FADE_SPEED);
if(parseInt(j('#notificationsCountValue').text())) {
j('.facebookmetricnot').fadeIn(FADE_SPEED);
j('.facebookmetricnotp').fadeIn(FADE_SPEED);
}
// new structure FOR SOME jul 2016
if(parseInt(j('.facebookmetricnot').text())) {
j('.facebookmetricnot').fadeIn(FADE_SPEED);
j('.facebookmetricnotp').fadeIn(FADE_SPEED);
}
var notificationsTotal = 0;
// new structure, if we don't have the IDs, then use this method instead
if(j('#requestsCountValue').length > 0) {
notificationsTotal =
parseInt(j('#requestsCountValue').text()) +
parseInt(j('#mercurymessagesCountValue').text()) +
parseInt(j('#notificationsCountValue').text());
} else {
//console.log("1: "+notificationsTotal);
j('.facebookmetricnot').each(function() {
notificationsTotal += parseInt(j(this).text());
//console.log("2: "+notificationsTotal);
//console.log("in else, txt = "+parseInt(j(this).text()));
});
}
if(notificationsTotal) {
j('title').text('('+notificationsTotal+') '+currentTitleText);
//console.log("notT if: "+notificationsTotal);
} else {
j('title').text(currentTitleText);
//console.log("notT else: "+notificationsTotal);
}
// fade in all fadeClasses
j.each(fadeClasses, function(index, value) { j(value).fadeIn(); });
// show all selectors in hideShowClasses
j.each(hideShowClasses, function(index, value) { j(value).show(); });
// show all toggle classes in toggleOnOffClasses
j.each(toggleOnOffClasses, function(index, value) {
j(value+'ON').hide();
j(value+'OFF').show();
});
// FB changes, 2/20/2012
j('.fbNubButton span.fbdchatlabel').hide();
j('.fbNubButton span.label').not('.fbdchatlabel').show();
// REMOVE 1.7.0
// timeline ribbon dropdown is too much trouble to hide/show due to how
// FB updates it after clicking, so I instead animate its color for fade in/out
// j('.fbTimelineMoreButton').find('.fbTimelineRibbon').find('.text').animate({color:RIBBON_TEXT_COLOR});
// view all XX comments - restore them to my previously stored count in the oldvalue attribute
j('.fbviewallcomments').each(function() { j(this).attr('value',j(this).attr('oldvalue')); });
// tiny +1 icons
j('.facebookmetric_hideshow_plusone_img').show();
j('.facebookmetric_hideshow_plusone_text').css('padding-left','18px');
// timeline add friend +1 icons
j('#pagelet_friends span.FriendLink i').show();
j('#pagelet_friends span.FriendLink a').css('padding-left','18px');
// newsfeed attachment +1 icons
// STILL NEEDED? CONFLICTING WITH NEW PAGELET ESCAPE HATCH ON NEW TIMELINE 5/2013
j('.addButton i').not('.FriendRequestAdd').show();
j('.addButton').not('.FriendRequestAdd').css('padding-left','18px');
// a few metrics need to fade out while holding their space
j.each(opacityClasses, function(index, value) { j(value).animate({opacity:1}, FADE_SPEED); });
// event and timeline activity counts, need to make sure they aren't 0 before revealing
j('.counter').each(function() {
var cnt = parseInt(j(this).text());
if(cnt) j(this).fadeIn(FADE_SPEED);
});
if(DBUG) console.timeEnd('demetricatorOFF timer');
}
setTimeout(function() {
j('#fbdtoggleindicator').hide();
// adjusting to new changes in nav items and that search results pages are narrower
j('#navFacebar').css('width',searchBarWidth);
j('.fbFacebar').css('width',searchBarWidth);
// search results pages are narrower than all other pages
j('._585-').css('width',newSearchBarWidth+"px");
}, 250);
}
// main():
//
// gets run on first load of userscript, sets up all future function calls
// (either by binding them to interface elements or dynamic element emergence)
//
// note that 'first load' is less often w/ FB than some sites. clicks on links
// w/in FB that appear to load new pages (and thus would typically reload the
// userscript) are not truly new page loads, just dynamic rewritings. therefore
// we use other techniques to detect those apparent page changes for demetrication
//
function main() {
// store away the URL we landed on
startURL = window.location.href;
if(!startURL) return;
// Firefox/Safari Addons don't allow excludes in the URL match, so we do it here.
if(IS_SAFARI_OR_FIREFOX_ADDON) {
if(startURL.contains("ai.php") ||
startURL.contains("/ajax/") ||
startURL.contains("/dialog/") ||
startURL.contains("/connect/") ||
startURL.contains("code.facebook.com") ||
startURL.contains("developers.facebook.com")
) return;
}
// added catch for the like button on my scaremail project dialog box, which was triggering demetricator
if((startURL.contains("/plugins/") && !startURL.contains("bengrosser")) || startURL.contains("scaremail")) return;
// some new "page" getting loaded, causing browser issues jul 2016
if(startURL.contains("ajaxpipe")) {
return;
}
// console reporting
console.log("Facebook Demetricator v"+VERSION_NUMBER);
console.log(" --> "+startURL);
// setup jQuery on j to avoid any possible conflicts
j = jQuery.noConflict();
// if this is a Like button plugin on the dialog, hide and exit ASAP
// facilitates demetrication of the like button in the Demetricator dialog box
if(startURL.contains('FBD_TOGGLE_STATE_ON')) {
j('._5n6h._2pih').css('opacity','0');
return;
}
// --- REMOVE GSSO 1.7.0
//demetricateGraphSearchSelectorOverview();
// 1.7 why is this here?
//demetricateGraphSearchResults();
// FBD DIALOG -----------------
// Facebook Like Button for the Demetricator Project Homepage (in the dialog box)
var likebutton =
'<iframe id="fbd_like_button" src="//www.facebook.com/plugins/like.php?href='+DEMETRICATOR_HOME_URL+'&send=false&layout=button_count&width=90&show_faces=false&action=like&colorscheme=light&font&height=21&data-ref=FBD_TOGGLE_STATE_ON" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:90px; height:21px;margin:30px 0px 25px 0px;" allowTransparency="true"></iframe>';
// HTML for the dialog box
var dialoghtml =
'<div style="display:none; width: 350px; height: 244px; margin: 0px auto; background-color: white;border:1px solid #e5e6e9;border-radius:3px;" class="-cx-PUBLIC-uiDialog__border" id="modaldialog">'+
'<div style="margin:5px;" id="modalheader"> <label style="margin:5px;float:right;" class="simplemodal-close uiCloseButton"></label><br><br> </div> <center> <h1><a href="'+DEMETRICATOR_HOME_URL+'" target="_blank">Facebook Demetricator</a></h1> <span class="messageBody">Hides all the metrics on Facebook</span><br/>'
+likebutton+
'<h3><span class="fcg" style="font-weight:normal">by</span> Benjamin Grosser</h3> <span class="fsm fcg"><a href="'+GROSSER_URL+'" target="_blank">bengrosser.com</a></span> </center> <div id="modalfooter" style="margin:15px 25px 25px 25px;"> <p style="float:left;" class="fcg">version '+VERSION_NUMBER+'</p> <p style="float:right;" class="fcg"><a href="'+DEMETRICATOR_HOME_URL+'" target="_blank">More info/feedback...</a></p> </div> </div>';
// insert the dialog into the page
j('body').append(dialoghtml);
// FBD TOGGLE AND NAVBAR -------------------
// new nav feb 2016
var fbdtoggleblock = '<img id="fbdtoggleindicator" class="loadingIndicator img" src="https://s-static.ak.facebook.com/rsrc.php/v2/yb/r/GsNJNwuI-UM.gif" alt="" width="16" height="11" style="display:none;margin:14px 0px 0 10px;">';
var fbdtoggleblockmar2016 = '<li class="_3zm-"><img id="fbdtoggleindicator" class="loadingIndicator img" src="https://s-static.ak.facebook.com/rsrc.php/v2/yb/r/GsNJNwuI-UM.gif" alt="" width="16" height="11" style="display:none;margin:4px 8px 0 10px;"></li>';
var navbarfeb2016 = '<div class="_1uh-"><div class="_4kny"> <div class="_4q39"><input id="demetricatortoggle" name="demetricatordb" type="checkbox" checked="checked" style="margin-top:8px;margin-right:-2px;"><a id="demetricatorlink" class="_2s25 _5yf" style="color:white;padding-left:6px;">Demetricator</a></div></div></div>';
var navbarmar2016 = '<li class="_3zm-"><input id="demetricatortoggle" name="demetricatordb" type="checkbox" checked="checked" style="margin-top:3px;margin-right:0;"><a id="demetricatorlink" class="_1ayn" style="padding-left:6px;">Demetricator</a></li><li class="_2wnm _56lq"></li>';
// MARCH split navbar codebase fix
// JUN '16 --- may no longer need this?
var latestnav = j('div[role="navigation"]:not("#sideNav")');
if(latestnav.length) {
// div structure feb 2016 -- but still active jul 2016 (ONLY FOR SOME)
latestnav.addClass('fbd_modified');
latestnav.find('div:first').addClass("_2s24 _398g").css("padding-left","10px");
latestnav.prepend(navbarfeb2016);
latestnav.prepend(fbdtoggleblock);
j('div._4kny._50tm').css('width',searchBarWidth);
} else {
latestnav = j('ul[role="navigation"]');
if(latestnav.length) {
// ul structure mar 2016
latestnav.addClass('fbd_modified');
latestnav.find('li:first').addClass("_55bh").find('a').removeClass('_2dpe');
latestnav.prepend(navbarmar2016);
latestnav.prepend(fbdtoggleblockmar2016);
j('div._585-').css('width',searchBarWidth);
}
}
// keeps clicks on checkbox from triggering surrounding 'a' click
j('#demetricatortogglelabel').click(function(event) { event.stopPropagation(); });
// bind toggleDemetricator() to the checkbox
j('#demetricatortoggle').change(function() {
if(j(this).is(':checked')) demetricatorON = true;
else demetricatorON = false;
j('._585-').css('width',newSearchBarWidth-40+"px");
j('#fbdtoggleindicator').show();
setTimeout(function() {
togglebeingchecked = false;
toggleDemetricator();
}, 250);
});
// setup demetrication of the Demetricator dialog Like button to activate whenever the dialog is loaded
j('#demetricatorlink').click(function() {
if(demetricatorON) {
var oldsrc = j('#fbd_like_button').attr('src');
var newsrc = oldsrc.replace('FBD_TOGGLE_STATE_OFF','FBD_TOGGLE_STATE_ON');
j('#fbd_like_button').attr('src',newsrc);
} else {
var oldsrc = j('#fbd_like_button').attr('src');
var newsrc = oldsrc.replace('FBD_TOGGLE_STATE_ON','FBD_TOGGLE_STATE_OFF');
j('#fbd_like_button').attr('src',newsrc);
}
j('#modaldialog').modal({
opacity:65,
overlayClose:true,
overlayCss: {backgroundColor:"#000"}
});
});
// enables kb control of Demetricator for testing
if(KEY_CONTROL) j(document).bind('keydown','ctrl+f',function() {
j('#demetricatortoggle').click();
});
// remove the metrics from our landing page
if(demetricatorON) {
demetricate(launchPolling);
}
}
// launchPolling()
//
// called via callback through demetricate(), used to launch a series
// of persistent CSS element polls that watch for dynamically changed
// content in order to trigger various demetrications
//
function launchPolling() {
//console.log("main() demetricate done: in launchPolling()");
// watch for new pages so we can recall demetricate as needed
setInterval(checkForNewPage, ELEMENT_POLL_SPEED);
// count the story blocks to know if there's new content to demetricate
// catches additional pages of content when they're loaded, as well as
// new stories inserted at the top. works better than triggering off
// the morepager at the bottom because it catches top stories as well
// also catches dynamically loaded ticker stories when hovered over (?)
if(IS_FIREFOX_ADDON) COUNT_INTERVAL = 1500;
else COUNT_INTERVAL = 800;
COUNT_INTERVAL = 800;
setInterval(function() {
// feb2016 var lateststorycount = j('.uiStreamStory, ._5jmm').length;
// feb2016 var latestfavoritescount = j('.uiFavoritesStory').length;
// ._4ikz --- substream section??
//var lateststorycount = j('._5jmm').length;
var lateststorycount = j('._4ikz').length;
var latesttimelineblockcount = j('.fbTimelineUnit').length;
var latestphotogridcount = j('.fbPhotoStarGridElement').length;
// REMOVE 1.7? //var latestgraphsearchphotocount = j('._by0').length;
// REMOVE 1.7? //var latestgraphsearchresultcount = j('._6a').length;
// new timeline
// feb2016 var latestappsectioncount = j('.-cx-PRIVATE-fbTimelineAppSection__header').length;
// REMOVE 1.7? var latestappsectioncountVER2 = j('._3cz').length;
// new timeline friend blocks
// feb2016 var latestfriendblockcount = j('.-cx-PRIVATE-fbTimelineFriendsCollection__grid').length;
// var latestfriendblockcountVER2 = j('._262m').length;
// jul 2016 change
var latestfriendblockcountVER2 = j('._262m').length;
// REMOVE 1.7 var latestnotificationitemcount = j('._33c').length;
//var latestfriendbrowsercount = j('.friendBrowserListUnit').length;
// track followListItem for subscriber entries
// TODO
// streamStoryCount isn't getting triggered anymore b/c they changed the class
if((
lateststorycount > streamStoryCount ||
latesttimelineblockcount > timelineUnitCount)
)
{
setTimeout(function() {
if(demetricatorON) {
if(FUNCTION_REPORT) console.log("calling demetricate() from lateststorycount poll");
demetricate(function() {
if(FUNCTION_REPORT) console.log("demetricate from lsc finished.");
});
}
}, 25);
}
if(latestphotogridcount > photoGridCount) {
setTimeout(function() { if(demetricatorON) demetricatePhotoIndex(); }, 250);
}
/*
if(latestgraphsearchphotocount > graphSearchPhotoCount) {
setTimeout(function() { if(demetricatorON) demetricatePhotoIndex(); }, 250);
}
if(latestgraphsearchresultcount > graphSearchResultCount) {
setTimeout(function() { if(demetricatorON) demetricateGraphSearchResults(); }, 250);
}
*/
/*
if(latestappsectioncountVER2 > appSectionCountVER2) {
setTimeout(function() { if(demetricatorON) demetricateNewTimeline(); }, 250);
setTimeout(function() { if(demetricatorON) { demetricateNewTimeline(); } }, 2000);
setTimeout(function() { if(demetricatorON) { demetricateNewTimeline(); } }, 3000);
}
*/
/*
if(latestnotificationitemcount > notificationItemCount) {
setTimeout(function() { if(demetricatorON) demetricateTimestamps(); }, 250);
}
*/
/*
if(latestfriendblockcountVER2 > friendBlockCountVER2) {
setTimeout(function() { if(demetricatorON) demetricateFriendPageBlocks(); }, 250);
}
*/
timelineUnitCount = latesttimelineblockcount;
streamStoryCount = lateststorycount;
photoGridCount = latestphotogridcount;
// graphSearchPhotoCount = latestgraphsearchphotocount;
// graphSearchResultCount = latestgraphsearchresultcount;
// appSectionCountVER2 = latestappsectioncountVER2;
friendBlockCountVER2 = latestfriendblockcountVER2;
// notificationItemCount = latestnotificationitemcount;
}, COUNT_INTERVAL);
// graph search autosuggest results
waitForKeyElements('._21c', demetricateGraphSearchAutoSuggest, false);
// notifications drop down timestamps
// REMOVE 1.7
/*
waitForKeyElements('a.messagesContent', function() {
demetricateTimestamps();
}, false);
*/
// dynamic comment changes (insertions, likes, timestamps)
waitForKeyElements('.UFIComment', function() {
demetricateTimestamps();
demetricateCommentLikeButton();
}, false);
waitForKeyElements('.UFIPagerLink span', demetricateViewAllComments, false);
// friend-finder
// not operating, need to redo or abandon jul 2016
//waitForKeyElements('.friendBrowserListUnit', demetricateFriendBrowserBlocks, false);
//waitForKeyElements('title', demetricateTitle, false);
// browser 'title' tag (e.g. tab title or window title, gets a notification metric: '(2) Facebook')
if(j('title').length) {
setInterval(function() {
if(demetricatorON) demetricateTitle();
}, 1000);
}
// deals w/ what happens on an 'unlike' click -- needs a different trigger
// FB update 2/20/2012
// pretty sure inoperable in jul 2016 ... REMOVE 1.7?
// waitForKeyElements('.UFILikeSentence span a[rel="dialog"]', demetricateLikesThis, false);
// reaction metric like sentence updates
waitForKeyElements('._3t53:not(".facebookcount")', attachReactionDemetricator, false);
// tooltips
//waitForKeyElements('.uiContextualLayerPositioner:not(".fbd_tracked, #__sizzle__", :contains("#facebar_typeahead_view_list"))', attachTooltipDemetricator, false);
//waitForKeyElements('.uiContextualLayerPositioner:not(".fbd_tracked, #__sizzle__", :contains(".uiTooltipX"))', attachTooltipDemetricator, false);
//waitForKeyElements('.uiContextualLayerPositioner:not(".fbd_tracked", :contains("#facebar_typeahead_view_list"))', function(n) { console.log(n.html()); }, false);
//waitForKeyElements('.uiContextualLayerPositioner:not("#__sizzle__")', attachTooltipDemetricator, true);
// reaction metric dialogs
//waitForKeyElements('._10.uiLayer:not(".fbd_tracked")',attachReactionDialogDemetricator, false);
//waitForKeyElements('._4t2a:not(".fbd_tracked")',attachReactionDialogDemetricator, false);
waitForKeyElements('._50f4:not(".fbd_tracked")',attachReactionDialogDemetricator, false);
// pop up notifications to tell you about your notifications (yes, seriously)
waitForKeyElements('._53ii ._5bov ._42ef._8u', function() {
var s = j(this).find('span:first');
if(s.hasClass('facebookcount')) {
s.addClass('facebookcount');
wrapNumberInString(s);
}
}, false);
// messages counter getting updated on sidebar
waitForKeyElements('.countValue:not(".facebookcount")', function() {
j(this).addClass('facebookcount facebookmetric_opacity').css('opacity','0');
j(this).parent().addClass("facebookmetric_opacity").css("opacity",'0');
}, false);
// friend list +1 icons within 'add friend' buttons
// REMOVE 1.7 or fix?
// waitForKeyElements('.fbProfileBrowserListItem, .fbProfileBrowserList', demetricateAddFriendButtons, false);
// waitForKeyElements('.detailedsearch_result', demetricateAddFriendButtons, false);
// new timeline 5/2013
waitForKeyElements('.FriendButton', demetricateAddFriendButtons, false);
// search result items
// needs work
//waitForKeyElements('ul.search li', demetricateSearchResultEntries, false);
// thumbs-up like counts on comments
waitForKeyElements('.UFICommentLikeButton', demetricateCommentLikeButton, false);
// ego section (news feed sidebar)
waitForKeyElements('.ego_column', demetricateEgoSection, false);
// chat list (e.g. 'MORE ONLINE FRIENDS (8)')
waitForKeyElements('._55oc', function() {
setTimeout(function() { demetricateChatSeparator(); }, 50);
}, false);
// chat tabs
//waitForKeyElements('.fbMercuryChatTab', demetricateChatTab, false);
waitForKeyElements('.fbNubButton', demetricateChatTab, false);
// new 'related' boxes that show up after you click a link on the new new newsfeed
//waitForKeyElements('._5d73', function(jn) {
//waitForKeyElements('._4_ck', function(jn) {
//waitForKeyElements('ul._5h5a', function(jn) {
// jn.find('._4pp').not('.facebookcount').addClass('facebookcount facebookmetric_hideshow').hide();
//}, false);
waitForKeyElements('._3lkn', function(jn) {
console.log("HERljkasdlfkjasdfj");
console.log("--> "+jn.html());
setTimeout(function() {
// related/suggested items SHARED counts
jn.find('div.mts span span').not('.facebookcount').each(function() {
wrapNumberInString(j(this));
});
// suggested videos VIEWED counts
jn.find('div.mts span').not('.facebookcount').each(function() {
j(this).addClass('facebookcount');
var h = j(this).html();
if(h) {
var parsed = h.match(/(\s·\s)(\d+(?:[,,.]\d+)*[K|M|k|m]?\s)(.*)/);
if(parsed) {
var newh = parsed[1]+
"<span class='facebookmetric_hideshow' style='display:none;'>"+parsed[2]+"</span>"+
parsed[3];
j(this).html(newh);
}
}
});
}, 500);
});
// new metrics in the search bar 2016
waitForKeyElements('.injectedSearchSuggestion div', function(jn) {
if(jn.not('.facebookcount')) {
jn.addClass('facebookcount');
wrapNumberInString(jn);
}
}, true);
// storage
//var notificationsFlyoutNode = document.getElementById("fbNotificationsFlyout");
// OBSERVERS -- MutationObservers (new method -- alternative to polling)
var observerConfig = { childList: true };
var containerNode = document.getElementById("globalContainer");
var bodyNode = document.getElementsByTagName("body");
var photoOverlayNode = document.getElementsByClassName("fbPhotoSnowliftContainer");
var notificationsFlyoutNode = j("#fbNotificationsFlyout div._33p div")[0];
// new structure jul 2016 ONLY FOR SOME USERS
if(notificationsFlyoutNode == undefined) {
notificationsFlyoutNode = j("._5fwu:eq(2)")[0];
}
/*
if(containerNode == null) console.log('containerNode == null');
if(bodyNode == null) console.log('bodyNode == null');
if(photoOverlayNode == null) console.log('photoOverlayNode == null');
*/
// containerNode is the globalContainer, the parent of most hovercards
if(containerNode != undefined) hovercardObserver.observe(containerNode, observerConfig);
// photoOverlayNode is the parent of hovercards when in photo viewing mode
bodyObserver.observe(bodyNode[0], observerConfig);
// for dropdown notifications from the navbar icon
if(notificationsFlyoutNode != undefined) {
notificationsObserverLauncher.observe(notificationsFlyoutNode, { childList: true, subtree: true} );
}
// launch an observer manually if we happened to have loaded a direct link to a photo overlay
// (e.g. someone pasted or clicked a link directly to an image)
var existingPhotoOverlay = document.getElementsByClassName('fbPhotoSnowlift');
if(existingPhotoOverlay.length > 0) {
var photoOverlayNode = existingPhotoOverlay[0].getElementsByClassName('fbPhotoSnowliftContainer')[0];
if(photoOverlayNode) hovercardObserver.observe(photoOverlayNode, observerConfig);
}
} // end launchPolling()
// demetricateTitle()
// called by launchPolling() and demetricate()
// removes the parenthetic prefix on the 'title' tag
// stores the rest of the title for later restoration
function demetricateTitle() {
var currentTitle = j('#pageTitle');
var txt = currentTitle.text();
var parsed = txt.match(/^(\(\d+(?:,\d+)*\))\s(.*)/);
if(parsed) {
currentTitle.text(parsed[2]);
if(currentTitleText != undefined) currentTitleText = parsed[2];
else currentTitleText = 'Facebook';
}
}
// OBSERVERS
//
var bodyObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var observerConfig = { childList: true };
var nl = mutation.addedNodes;
if(nl.length > 0) {
for(var i = 0; i < nl.length; ++i) {
var nlc = nl[i].getAttribute("class");
if(nlc) {
if(nlc.contains("fbPhotoSnowlift")) {
var photoOverlayNode = nl[i].getElementsByClassName('fbPhotoSnowliftContainer')[0];
//if(photoOverlayNode) hovercardObserver.observe(photoOverlayNode, observerConfig);
} else if(nlc.contains("uiContextualLayerPositioner")) {
// might be the account menu, hide countValues
j(nl[i]).find('.countValue:not(".facebookcount")').addClass('facebookcount').hide();
// notification popup notifications (seriously wtf)
var notificationPopup = j(nl[i]).find('._42ef._8u');
if(notificationPopup.length > 0) {
notificationPopup.each(function() {
j(this).addClass('facebookcount');
console.log("found a notification popup notification -->");
console.log(j(this).html());
var h = j(this).html();
if(h) {
var parsed = h.match(/(.*-->)(\d+(?:[,,.]\d+)*[K|M|k|m]?\s)(notification.*)/);
if(parsed) {
var n =
parsed[1]+
'<span style="display:none;" class="facebookmetric_hideshow">'+parsed[2]+'</span>'+
parsed[3];
j(this).html(n);
}
}
});
} else {
var searchResultsNode = nl[i];
if(searchResultsNode) {
/*
console.log("launching observer for SR");
console.log(searchResultsNode.nodeType);
console.log(searchResultsNode.nodeName);
console.log(searchResultsNode.nodeValue);
console.log(searchResultsNode.baseURI);
console.log(searchResultsNode.getAttribute("class"));
*/
hovercardObserver.observe(searchResultsNode, {childList: true, subtree: true});
}
}
}
}
}
}
});
});
// the notification dropdown UL doesn't exist until the nav item has been clicked
// this observer watches the parent and waits for the UL to get created
var notificationsObserverLauncher = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
console.log("got a mutation: "+mutation);
var observerConfig = { childList: true };
var nl = mutation.addedNodes;
if(nl.length > 0) {
for(var i = 0; i < nl.length; ++i) {
var nlt = nl[i].tagName;
if(nlt.contains("UL")) {
// demetricate the first batch of li
j(nl[i]).find('li').each(function() { demetricateNotificationItem(j(this)); });
// start an observer to watch for additional li's (on scroll)
notificationsObserver.observe(nl[i], observerConfig);
// disconnect the launcher observer
notificationsObserverLauncher.disconnect();
}
}
}
});
});
// watches for new LI notification items in the notification dropdown
var notificationsObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var observerConfig = { childList: true };
var nl = mutation.addedNodes;
if(nl.length > 0) {
demetricateTimestamps();
for(var i = 0; i < nl.length; ++i) {
demetricateNotificationItem(j(nl[i]));
}
}
});
});
// demetricates a notification LI
function demetricateNotificationItem(n) {
var notification = n.find('._4l_v span:first').not('fbd_tracked');
n.addClass('fbd_tracked');
if(!notification) return;
var h = notification.html();
var parsed = h.match(/(.*\s)(\d+(?:[,,.]\d+)*[K|M|k|m]?\s)(other.*)/);
if(parsed) {
var newh =
parsed[1] +
"<span class='facebookmetric_hideshow' style='display:none;'>"+parsed[2]+"</span>"+
parsed[3];
notification.html(newh);
}
}
var hovercardObserver = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
//console.log("got mutation");
var nl = mutation.addedNodes;
if(nl.length > 0) {
for(var i = 0; i < nl.length; ++i) {
// only process nodeType 1 (element)
var nlNT = nl[i].nodeType;
//console.log("\n\nNEW nl.nT: "+nlNT);
if(nl[i].nodeType != 1) {
// console.log("found nT != 1, ignore rest of loop");
continue;
} else {
/*
console.log("nodeType == 1");
console.log(".. html: "+j(nl[i]).html());
console.log(".. so moving on...");
*/
}