/
reddit_image_info.2.user.js
2407 lines (2340 loc) · 122 KB
/
reddit_image_info.2.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 reddit image info
// @namespace https://absurdlyobfuscated.com/reddit/
// @description Shows and highlights media/author information from imgur, gfycat, giphy, sli.mg, and more, adds an improved image/video expando, and detects reposted imgur comments.
// @include https://*.reddit.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @require https://github.com/EastDesire/jscolor/raw/master/jscolor.min.js
// @version 2.2.1.0
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_listValues
// @grant GM_deleteValue
// @grant GM_addStyle
// ==/UserScript==
function main()
{
GM_addStyle(
".imageInfoSprite { background-image: url('https://www.redditstatic.com/sprite-reddit.6Om8v6KMv28.png'); }\n" +
".imageInfoLink {cursor: pointer;}\n" +
".imageInfoButton { display: inline-block; border: 1px solid #666; padding: 1px 6px; border-radius: 3px; font-size: x-small; line-height: 12px; }\n" +
".imageInfoNotification { position: fixed; z-index: 100; top: 44px; right: 47px; padding: 20px; font-size: small; background-color: #eff7ff; }\n" +
".imageInfoNotificationClose, .imageInfoSettingsClose { float: right; }\n" +
".imageInfoNotificationClose:hover, .imageInfoSettingsClose:hover { background-color: red; color: white; }\n" +
".imageInfoNotificationText, .imageInfoSettingsContent { margin: 10px 0; }\n" +
".imageInfoSettings { position: absolute; z-index: 100; top: 44px; right: 47px; padding: 10px; font-size: small; background-color: #eff7ff; }\n" +
".imageInfoSettingArrayItem { border: 1px solid #cee3f8; margin: 0 0 5px 5px; border-radius: 3px; }\n" +
".imageInfoSettingArrayItem > .imageInfoSettingValue > .imageInfoSetting { margin-top: 14px; }\n" +
".imageInfoSettingArrayRemove { float: right; position: relative; left: -4px; top: 4px; width: 10px; height: 10px; background-position: -128px -1638px; }\n" +
".imageInfoSettingArrayAdd { width: 16px; height: 16px; background-position: 0 -1464px; }\n" +
".imageInfoSettingGroup { border: 1px solid #369; border-radius: 3px; margin: 10px 0; }\n" +
".imageInfoSettingGroupCollapsed > .imageInfoSettingItem { display: none; }\n" +
".imageInfoSettingCollapse { float: right; width: 16px; height: 18px; background-position: -118px -1267px; transform: rotate(90deg); opacity: 0.6; position: relative; top: -2px; }\n" +
".imageInfoSettingGroupCollapsed .imageInfoSettingCollapse { background-position: -118px -1211px; }\n" +
".imageInfoSettingGroupTitle { background-color: #cee3f8; padding: 5px; width: 432px; }\n" +
".imageInfoSettingItem { padding: 3px; }\n" +
".imageInfoSettingTitle, .imageInfoSettingArrayTitle { display: inline-block; padding-bottom: 5px; }\n" +
".imageInfoSettingTitle { width: 260px; }\n" +
".imageInfoSettingItem .imageInfoSettingItem .imageInfoSettingTitle { width: 250px; }\n" +
".imageInfoSettingItem .imageInfoSettingItem .imageInfoSettingItem .imageInfoSettingTitle { width: 240px; }\n" +
".imageInfoSettingValue { display: inline; }\n" +
".imageInfoSettingValueNonDefault { box-shadow: 0 0 6px yellow; }\n" +
".imageInfoSettingDesc { margin-bottom: 5px; font-size: x-small; background-color: #cee3f8; width: 423px; padding: 5px; }\n" +
".imageInfoSettingsButton { display: inline; background-color: #cee3f8; color: #369; font-weight: bold; margin-left: 5px; }\n" +
".imageInfoSettingReset, .imageInfoSettingCache, .imageInfoSettingCacheCurrent { float: right; }\n" +
".imageInfoSettingsTagDataInfo { display: inline-block; }\n" +
".imageInfoSettingsTagDataUpdate { float: right; margin-left: 4px; }\n" +
".imageInfoSettingsTagDataInfo div, .imageInfoSettingsTagDataUpdate { font-size: xx-small; color: grey; display: inline; }\n" +
".imageInfoFeedback { float: right; }\n" +
".imageInfo, .imageInfo div { font-size: x-small; display: inline; }\n" +
".imageInfoDesc { line-height: 15px; background-color: white; border: white; }\n" +
".imageInfoExpando { float: left; width: 24px; height: 24px; margin: 2px 5px 2px 0px; background-position: -116px -1406px; }\n" +
".imageInfoExpando:hover { background-position: -87px -1406px; }\n" +
".imageInfoExpandoExpanded { background-position: -29px -1435px; }\n" +
".imageInfoExpandoExpanded:hover { background-position: 0 -1435px; }\n" +
".imageInfoExpandoContent { display: none; max-width: 100%; min-height: 30px; margin: 0 4px 2px 0; }\n" +
".imageInfoExpandoMsg { position: absolute; width: 100%; }\n" +
".imageInfoExpandoError { position: absolute; }\n" +
".imageInfoAlbumControls, .imageInfoAlbumTitle, .imageInfoAlbumTitle div { display: inline; }\n" +
".imageInfoAlbumTitle, .imageInfoAlbumImageCount { font-weight: bold; }\n" +
".imageInfoAlbumTitle { margin-left: 8px; }\n" +
".imageInfoAlbumLeft, .imageInfoAlbumRight { display: inline; background-color: white; padding-right: 8px; }\n" +
".imageInfoAlbumLeft { margin-right: 3px; }\n" +
".imageInfoAlbumRight { margin-left: 3px; }\n" +
".imageInfoAlbumCurrentImage { text-align: right; }\n" +
".imageInfoAlbumCurrentImage, .imageInfoAlbumTotalImages { display: inline-block; width: 10px; }\n" +
".imageInfoAlbumCountDigits2 { width: 16px; }\n" +
".imageInfoAlbumCountDigits3 { width: 22px; }\n" +
".imageInfoAlbumContent { min-width: 200px; min-height: 200px; }\n" +
".imageInfoExpandoContent .imageInfo, .imageInfoAlbumTitle, .imageInfoAlbumControls { line-height: 16px; margin-bottom: 2px; font-size: x-small; }\n" +
".imageInfoExpandoImage, .imageInfoExpandoVideo { display: none; max-width: 100%; }\n" +
".imageInfoTitleDuration { display: inline; margin-right: 3px; }\n" +
".imageInfoShowAllHide { display: none; }\n" +
".imageInfoGfyLink { margin-right: 2px; background-color: #d1eac0; }\n" +
".imageInfoRedButton { background-color: red; color: white; }\n" +
".imageInfoOrangeButton { background-color: orange; color: white; }\n" +
".imageInfoGreyButton { background-color: grey; color: white; }\n" +
".imageInfoComment { display: inline-block; width: 24px; height: 15px; }\n" +
".imageInfoCommentInline { display: inline; }\n" +
".imageInfoCommentInlineExpando { display: inline-block; width: 24px; height: 15px; }\n" +
".imageInfoComment .imageInfo { display: none; position: absolute; margin-left: 2px; }\n" +
".imageInfoComment .imageInfo, .imageInfoCommentInline .imageInfo { background: white; border: 1px solid #eee; border-radius: 3px; padding: 3px; line-height: 16px; }\n" +
".imageInfoComment .imageInfoExpando { position: absolute; margin: 0 2px; }\n" +
".imageInfoCommentInline .imageInfoExpando { margin: 0; }\n" +
".imageInfoCommentInline .imageInfoExpando, .imageInfoComment:hover, .imageInfoComment:hover .imageInfo, .imageInfoCommentInline .imageInfo { display: inline-block; }\n"
);
var settingMetaData = {
version: 2.2,
type: "object",
children: {
groupTags: { name: "Tags", type: "group", children: {
authorTags: { name: "Media author tags", type: "array", tooltip: "Tags for imgur/gfycat/etc. media authors.", arrayItemName: "media author tag", arrayItem: {
type: "object", children: {
authorRegex: { name: "Author regex", type: "string", defaultValue: "", tooltip: "Regular expression used to match media author." },
tag: { name: "Tag", type: "string", defaultValue: "" },
tagDetails: { name: "Tag details", type: "string", defaultValue: "", tooltip: "Extra info shown in tag tooltip." },
tagColor: { name: "Tag highlight color", type: "color", defaultValue: "ff0000" },
tagTextColor: { name: "Tag text color", type: "color", defaultValue: "ffffff" }
}
} },
mediaTags: { name: "Media tags", type: "array", tooltip: "Tags for media matching the given width/height/size. Note that this is not very reliable and only matches specific versions of an image/video (and might have false positives).", arrayItemName: "media tag", arrayItem: {
type: "object", children: {
width: { name: "Width", type: "number", defaultValue: 0 },
height: { name: "Height", type: "number", defaultValue: 0 },
size: { name: "Size (bytes)", type: "number", defaultValue: 0 },
tag: { name: "Tag", type: "string", defaultValue: "" },
tagDetails: { name: "Tag details", type: "string", defaultValue: "", tooltip: "Extra info shown in tag tooltip." },
tagColor: { name: "Tag highlight color", type: "color", defaultValue: "ff0000" },
tagTextColor: { name: "Tag text color", type: "color", defaultValue: "ffffff" }
}
} }
}},
groupDescText: { name: "Media Text", type: "group", children: {
descriptionHighlight: { name: "Highlight text in media titles/descriptions", type: "array", defaultValue: [{ textRegex: "(instagram|facebook|twitter|twimg|pinterest|tumblr)\\.com", highlightDetails: "social media link", highlightColor: "7744bb", highlightTextColor: "ffffff" }], arrayItemName: "highlight text item", arrayItem: {
type: "object", children: {
textRegex: { name: "Text regex", type: "string", defaultValue: "", tooltip: "Regular expression used to match title/description text." },
highlightDetails: { name: "Details", type: "string", defaultValue: "", tooltip: "Extra info shown in tooltip." },
highlightColor: { name: "Highlight color", type: "color", defaultValue: "" },
highlightTextColor: { name: "Text color", type: "color", defaultValue: "" }
}
} },
highlightDescriptionLinks: { name: "Highlight links in titles/descriptions?", type: "boolean", defaultValue: true },
descriptionLinkColor: { name: "Link highlight color", type: "color", defaultValue: "ffff6e" },
descriptionLinkTextColor: { name: "Link text color", type: "color", defaultValue: "0079d3" }
}},
groupExpando: { name: "Expandos & Media Info", type: "group", children: {
addExpandos: { name: "Add single media item expandos/media info?", type: "boolean", defaultValue: true },
addAlbumExpandos: { name: "Add album expandos/media info?", type: "boolean", defaultValue: true },
addCommentExpandos: { name: "Add comment expandos/media info?", type: "boolean", defaultValue: true },
addMessageExpandos: { name: "Add modmail and message expandos/media info?", type: "boolean", defaultValue: true },
commentMediaInfoInline: { name: "Show comment/message media info inline?", type: "boolean", defaultValue: false, tooltip: "If not enabled, comment/message/modmail media info is shown when hovering over the expando." },
removeNativeExpandos: { name: "Remove native expandos?", type: "boolean", defaultValue: false, tooltip: "Remove reddit's (slow, low quality) native expandos that load media from redditmedia or embed.ly whenever a replacement expando and media info is available for a link." },
forceHttps: { name: "Always use HTTPS?", type: "boolean", defaultValue: false, tooltip: "Replace insecure expando links with secure HTTPS links. This will cause problems for sites that don't support secure connections." },
muteVideo: { name: "Mute expando videos by default?", type: "boolean", defaultValue: true },
loadReducedImgur: { name: "Load reduced size version of imgur images?", type: "boolean", defaultValue: true, tooltip: "Substitute a max 1024x1024 image when original image is higher resolution. Makes images load faster at the expense of a potential resolution loss for some images." },
//expandOnHover: { name: "Expand on hover?", type: "boolean", defaultValue: false, tooltip: "Expand when hovering mouse over expandos. Clicking the expando will keep it open." },
expandoRememberPlace: { name: "Resume after re-opening expando?", type: "boolean", defaultValue: true, tooltip: "After closing and re-opening a video or album expando, go to the previous time or album image." },
expandoMaxHeight: { name: "Max expando image/video height (pixels)", type: "number", defaultValue: 1000, tooltip: "Images and videos taller than this will be resized to fit. Zero for no maximum. Note that very wide images/videos are still resized to fit the page/comment width." },
expandoClickExpandHeight: { name: "Expand image/video full height on click?", type: "boolean", defaultValue: true, tooltip: "When an image or video is taller than the max expando height, clicking it toggles from resized to full height. Note that very wide images/videos are still resized to fit the page/comment width, and reduced size imgur images will still be limited to a 1024 pixel height." },
expandoResizeVideoNoPause: { name: "Don't pause videos when clicking to resize?", type: "boolean", defaultValue: true, tooltip: "Only affects browsers that play/pause videos when clicked (Firefox). Prevents pausing when clicking on a video taller than the max expando height in order to toggle the full height. Small videos are unaffected." }
}},
groupAnimated: { name: "Animated", type: "group", children: {
highlightAnimated: { name: "Highlight animated media?", type: "boolean", defaultValue: true, tooltip: "Highlights the thumbnail for webm/mp4/GIF/etc. media links." },
albumColor: { name: "Album color", type: "color", defaultValue: "d8bfd8", tooltip: "Color for albums containing animated media." },
galleryColor: { name: "Gallery color", type: "color", defaultValue: "ee82ee", tooltip: "Color for gallery and image pages containing animated media." },
gifvColor: { name: "Gifv color", type: "color", defaultValue: "8a2be2", tooltip: "Color for webm/mp4 compatibility pages." },
gfyColor: { name: "Gfy color type", type: "color", defaultValue: "800080", tooltip: "Color for gfycat pages." },
webmColor: { name: "Webm color", type: "color", defaultValue: "008080", tooltip: "Color for direct webm/mp4 links." },
gifColor: { name: "GIF color", type: "color", defaultValue: "ff7000", tooltip: "Color for direct GIF links." }
}},
groupDuration: { name: "Duration", type: "group", children: {
addDurationToTitle: { name: "Add duration to post titles?", type: "boolean", defaultValue: true },
highlightLongDuration: { name: "Highlight long animated media?", type: "boolean", defaultValue: true },
longDuration: { name: "Long duration (seconds)", type: "number", defaultValue: 15.1 },
longDurationColor: { name: "Long duration highlight color", type: "color", defaultValue: "ff8880" },
longDurationTextColor: { name: "Long duration text color", type: "color", defaultValue: "ffffff" },
useGradient: { name: "Use color gradient?", type: "boolean", defaultValue: true, tooltip: "Yellow to red gradient for long durations, from start to end durations." },
gradientDurationMin: { name: "Gradient start duration (seconds)", type: "number", defaultValue: 15.1, tooltip: "Durations closer to this will be yellow." },
gradientDurationMax: { name: "Gradient end duration (seconds)", type: "number", defaultValue: 20, tooltip: "Durations closer to this will be red." }
}},
groupFrameRates: { name: "Frame Rates", type: "group", children: {
accurateFrameRate: { name: "Show accurate frame rates?", type: "boolean", defaultValue: false, tooltip: "Determine the exact frame rate using the non-standard HTMLMediaElement.seekToNextFrame(). Currently only supported in Firefox, and requires you to enable media.seekToNextFrame.enabled in about:config. Note that this may add a slight delay before videos begin their first playback. If not enabled or supported by your browser or if this setting is off, frame rates are estimated based on browser playback timings when not given by the respective media API." },
highlightLowFrameRate: { name: "Highlight low frame rates?", type: "boolean", defaultValue: true },
lowFrameRate: { name: "Low frame rate", type: "number", defaultValue: 20 },
lowFrameRateColor: { name: "Low frame rate highlight color", type: "color", defaultValue: "ff9955" },
lowFrameRateTextColor: { name: "Low frame rate text color", type: "color", defaultValue: "ffffff" },
highlightHighFrameRate: { name: "Highlight high frame rates?", type: "boolean", defaultValue: true },
highFrameRate: { name: "High frame rate", type: "number", defaultValue: 40 },
highFrameRateColor: { name: "High frame rate highlight color", type: "color", defaultValue: "5599ff" },
highFrameRateTextColor: { name: "High frame rate text color", type: "color", defaultValue: "ffffff" }
}},
groupResolution: { name: "Resolution", type: "group", children: {
highlightLowResolution: { name: "Highlight low resolution media?", type: "boolean", defaultValue: true },
lowResolution: { name: "Low resolution (pixels)", type: "number", defaultValue: 400, tooltip: "The smaller of width and height considered to be low resolution." },
lowResolutionColor: { name: "Low resolution color", type: "color", defaultValue: "ff7755" },
lowResolutionTextColor: { name: "Low resolution text color", type: "color", defaultValue: "ffffff" },
highlightHighResolution: { name: "Highlight high resolution media?", type: "boolean", defaultValue: true },
highResolution: { name: "High resolution (pixels)", type: "number", defaultValue: 2000, tooltip: "The larger of width and height considered to be high resolution." },
highResolutionColor: { name: "High resolution highlight color", type: "color", defaultValue: "66ddff" },
highResolutionTextColor: { name: "High resolution text color", type: "color", defaultValue: "ffffff" }
}},
groupFileSize: { name: "Files Size", type: "group", children: {
highlightLargeSize: { name: "Highlight large media?", type: "boolean", defaultValue: true },
largeSize: { name: "Large size (bytes)", type: "number", defaultValue: 15728640 },
largeSizeColor: { name: "Large size highlight color", type: "color", defaultValue: "ff5555" },
largeSizeTextColor: { name: "Large size text color", type: "color", defaultValue: "ffffff" }
}},
groupSameTitle: { name: "Same Titles", type: "group", children: {
highlightSameTitle: { name: "Highlight similar titles?", type: "boolean", defaultValue: true, tooltip: "Highlight when the reddit title is similar to the imgur/gfycat/etc. media title." },
minimumTitleSimilarity: { name: "Minimum title similarity (percent)", type: "number", defaultValue: 75, tooltip: "Percent of matching characters between reddit and media title, non-letter/number characters excluded." },
sameTitleColor: { name: "Same title highlight color", type: "color", defaultValue: "ffff88" },
sameTitleTextColor: { name: "Same title text color", type: "color", defaultValue: "000000" }
}},
groupSameAuthors: { name: "Same Authors", type: "group", children: {
highlightSameAuthor: { name: "Highlight same author?", type: "boolean", defaultValue: true, tooltip: "Highlight when the reddit author matches the imgur/gfycat/etc. media author." },
sameAuthorColor: { name: "Same author highlight color", type: "color", defaultValue: "00e800" },
sameAuthorTextColor: { name: "Same author text color", type: "color", defaultValue: "ffffff" }
}},
groupGallery: { name: "Imgur Gallery", type: "group", children: {
loadImgurGalleryInfo: { name: "Load imgur gallery info?", type: "boolean", defaultValue: false, tooltip: "When an imgur image or album is in the public gallery, load extra details like score and comment count." },
highlightGalleryReposts: { name: "Highlight gallery reposts?", type: "boolean", defaultValue: true, tooltip: "Highlight when a reddit post is a repost of an imgur gallery post automatically created by a different reddit post." },
galleryRepostTimeDiff: { name: "Gallery repost time difference (minutes)", type: "number", defaultValue: 20, tooltip: "Difference between reddit post time and the time an automatic imgur gallery post was created. Gallery creation time does not necessarily reflect image upload or album creation time." },
galleryRepostColor: { name: "Gallery repost highlight color", type: "color", defaultValue: "ffa500" },
galleryRepostTextColor: { name: "Gallery repost text color", type: "color", defaultValue: "ffffff" },
highlightNonGalleryWithTitle: { name: "Highlight non-gallery posts with title/description?", type: "boolean", defaultValue: true, tooltip: "Highlight when imgur content is not in the gallery, but has a title or description. This could mean that it was previously an imgur gallery post but was removed from the public gallery listing, by the user or by imgur due to spam or a rule violation, or this might indicate spam or account farming behavior." },
galleryRemovedColor: { name: "Gallery removed highlight color", type: "color", defaultValue: "ff4400" },
galleryRemovedTextColor: { name: "Gallery removed text color", type: "color", defaultValue: "ffffff" }
}},
groupThumbnails: { name: "Thumbnails", type: "group", children: {
highlightThumbnailVersion: { name: "Highlight thumbnail versions?", type: "boolean", defaultValue: true, tooltip: "Highlight when a post links to a smaller or non-standard version of the original." },
thumbnailVersionColor: { name: "Thumbnail versions highlight color", type: "color", defaultValue: "ff7777" },
thumbnailVersionTextColor: { name: "Thumbnail versions text color", type: "color", defaultValue: "ffffff" }
}},
groupOldMedia: { name: "Old Media", type: "group", children: {
highlightOld: { name: "Highlight old media items?", type: "boolean", defaultValue: true },
oldTimeDiff: { name: "Old time (minutes)", type: "number", defaultValue: 24 * 60 },
oldColor: { name: "Old media item highlight color", type: "color", defaultValue: "ffe0bb" },
oldTextColor: { name: "Old media item text color", type: "color", defaultValue: "000000" }
}},
groupImgurCommentReposts: { name: "Imgur Comment Reposts", type: "group", children: {
highlightImgurCommentReposts: { name: "Highlight imgur comment reposts?", type: "boolean", defaultValue: true, tooltip: "Highlight when a reddit comment is copied from a comment in the corresponding imgur gallery post for the current reddit post." },
loadImgurCommentsAutomatically: { name: "Load comments automatically?", type: "boolean", defaultValue: true, tooltip: "Automatically retrieve imgur comments on page load and check for comment reposts. If not enabled, a button will allow you to check manually." },
checkTopLevelCommentsOnly: { name: "Check top level imgur comments only?", type: "boolean", defaultValue: false, tooltip: "Speeds up check time for posts with large numbers of comments, but won't show some comment reposts." },
minimumCommentLength: { name: "Minimum comment length", type: "number", defaultValue: 10, tooltip: "Minimum number of number/letter/space characters in a comment for it to be considered a comment repost." },
reportReasonText: { name: "Report reason text", type: "string", defaultValue: "copied imgur comment - ", tooltip: "Default text inserted in report reason when clicking the Report link on a reposted comment. The imgur comment URL is appended to this text." },
allowEditingOfReportReason: { name: "Allow editing of report reason?", type: "boolean", defaultValue: false, tooltip: "When clicking the Report link on a reposted comment, don't immediately submit the report after filling in the reason." }
}},
groupGifToGfy: { name: "GIF to Gfy", type: "group", children: {
showGfyConvertButton: { name: "Add gfy convert button?", type: "boolean", defaultValue: true, tooltip: "Adds a button next to GIF media links that converts them to gfycats and replaces the expando and media info with the gfy and gfy info. If an existing gfy transcode exists for a GIF, that gfy will load immediately." },
autoConvertGfy: { name: "Automatically convert GIFs to gfycats?", type: "boolean", defaultValue: false, tooltip: "Automatically convert GIFs on page load, or retrieve info for an existing gfy transcode if one exists. If not enabled, the gfy button will allow you to convert to gfy manually." }
}},
groupAdvanced: { name: "Advanced", type: "group", collapsedByDefault: true, children: {
imgurClientId: { name: "Imgur API client ID", type: "string", defaultValue: "1d8d9b36339e0e2", desc: "Client ID used to retrieve imgur info. Get one by registering an imgur app here: <a href=\"https://api.imgur.com/oauth2/addclient\">https://api.imgur.com/oauth2/addclient</a>." },
slimgClientId: { name: "Sli.mg API client ID", type: "string", defaultValue: "", desc: "Client ID used to retrieve sli.mg info. See <a href=\"https://sli.mg/public/api\">https://sli.mg/public/api</a>." },
// gfycatClientId: { name: "Gfycat API client ID", type: "string", defaultValue: "", desc: "Client ID used with gfycat client secret to convert GIFs to gfycats. See <a href=\"https://developers.gfycat.com/api/#authentication\">https://developers.gfycat.com/api/#authentication</a>." },
// gfycatClientSecret: { name: "Gfycat API client secret", type: "string", defaultValue: "" },
simultaneousLinks: { name: "Simultaneous links", type: "number", defaultValue: 10, tooltip: "Number of links processed in parallel. After media info is processed for a link, the next one in sequence begins, with the total number running at the same time limited by this setting. Depending on the speed of your network and various media APIs, a lower number will cause media info to appear slower, and a higher number may cause browser lag, timeouts, or hit API limits." },
simultaneousExpandos: { name: "Simultaneous expandos", type: "number", defaultValue: 2, tooltip: "Number of expandos that load at the same time when the "show all" button is clicked. After an expando loads (or reaches an error), the next expando in sequence will load." },
imgurPostCacheTime: { name: "Imgur post cache time (minutes)", type: "number", defaultValue: 1 * 60, tooltip: "Time to keep imgur post data (author/description/dimensions/etc.) saved in this script's local cache. Longer times reduce network overhead but media info shown may be out of date. Shorter times increase network overhead (and hit API limits faster) but info will be more up to date." },
imgurAlbumCacheTime: { name: "Imgur album cache time (minutes)", type: "number", defaultValue: 2 * 60, tooltip: "Time to keep imgur album data (author/description/list of pictures and their data) cached." },
imgurCommentsCacheTime: { name: "Imgur comments cache time (minutes)", type: "number", defaultValue: 2 * 60, tooltip: "Time to keep imgur gallery comments cached." },
gfycatPostCacheTime: { name: "Gfycat cache time (minutes)", type: "number", defaultValue: 12 * 60, tooltip: "Time to keep gfycat post data cached." },
slimgPostCacheTime: { name: "Slimg post cache time (minutes)", type: "number", defaultValue: 6 * 60, tooltip: "Time to keep slimg post data cached." },
slimgAlbumCacheTime: { name: "Slimg album cache time (minutes)", type: "number", defaultValue: 6 * 60, tooltip: "Time to keep slimg album data cached." },
otherCacheTime: { name: "Other items cache time (minutes)", type: "number", defaultValue: 12 * 60, tooltip: "Time to keep all other media data cached." }
}}
}
};
var settings;
var isCommentPage = /\/comments\//i.test(window.location.href);
var currentMediaTag;
var tagData;
var tagDataUpdateTime;
var currentExpandoList;
var currentLinkList;
var mediaTags;
var descriptionHighlight;
var selfPostInterval = {};
var frameRateInterval = {};
// https://gist.github.com/dperini/729294#file-regex-weburl-js
var urlRegex = "(?:(?:https?|ftp):\\/\\/)(?:\\S+(?::\\S*)?@)?(?:(?!(?:10|127)(?:\\s*\\.\\s*\\d{1,3}){3})(?!(?:169\\s*\\.\\s*254|192\\s*\\.\\s*168)(?:\\s*\\.\\s*\\d{1,3}){2})(?!172\\s*\\.\\s*(?:1[6-9]|2\\d|3[0-1])(?:\\s*\\.\\s*\\d{1,3}){2})(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])(?:\\s*\\.\\s*(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}(?:\\s*\\.\\s*(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))|(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)(?:\\s*\\.\\s*(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*(?:\\s*\\.\\s*(?:[a-z\\u00a1-\\uffff]{2,}))\\.?)(?::\\d{2,5})?(?:[/?#]\\S*)?";
var imgurIdRegex = /imgur\.com\/+(?:(gallery|a|r\/\w+|t(?:opic)?\/\w+|share\/i)\/)?([\d\w]{5}|[\d\w]{7})([sbtmlgh])?(\.(?=.+)|[^\d\w]|$)/i;
function cacheData(cacheId, dataObject, cacheTimeMinutes)
{
GM_setValue(cacheId, JSON.stringify({ exp: cacheTimeMinutes ? Date.now() + cacheTimeMinutes * 60000 : 0, data: dataObject}));
}
function getCachedData(cacheId, forceExpire)
{
var cacheString = GM_getValue(cacheId);
if (cacheString)
{
var cacheItem = JSON.parse(cacheString);
if (cacheItem)
{
if (!cacheItem.exp || (!forceExpire && Date.now() < cacheItem.exp))
return cacheItem.data;
GM_deleteValue(cacheId);
}
}
return null;
}
function cleanCache(forceExpire)
{
var removed = 0;
var startTime = Date.now();
var keys = GM_listValues();
for (var i = 0; i < keys.length; i++)
{
if (!getCachedData(keys[i], forceExpire))
removed++;
}
console.log("reddit image info cache cleanup: " + removed + " removed, " + (keys.length - removed) + " remaining (" + (Date.now() - startTime) + "ms)");
}
function showNotification(notificationHtml, autoCloseTime, closeEvent)
{
$(".imageInfoNotification").remove();
$("body").append($("<div class=\"imageInfoNotification imageInfoButton\"><b>reddit image info</b><div class=\"imageInfoNotificationClose imageInfoLink imageInfoButton\">X</div><div class=\"imageInfoNotificationText\">" + notificationHtml + "</div></div>"));
$(".imageInfoNotificationClose").click(function() {
$(".imageInfoNotification").remove();
if (closeEvent)
closeEvent();
});
if (autoCloseTime)
{
var closeTimeout = window.setTimeout(function() {
$(".imageInfoNotification").fadeTo(500, 0, function() {
if (closeTimeout)
$(".imageInfoNotificationClose").click();
});
}, autoCloseTime);
$(".imageInfoNotification").on("mouseover", function() {
window.clearTimeout(closeTimeout);
closeTimeout = null;
$(this).stop().fadeTo(50, 1);
});
}
}
function handleError(error, errorElement)
{
console.log("reddit image info error: " + error.message);
var errorText = " Page: " + window.location.pathname;
try
{
if (errorElement && errorElement.jquery)
errorText += "\n Element " + errorElement.parents(".thing").attr("id");
}
catch (err)
{
}
errorText += "\n " + error.message;
if (error.stack)
errorText += "\n " + error.stack.replace(/\n(?=.+)/g, "\n ").replace(/file:\/.+\//g, "");
var lastError = { errorTime: Date.now(), errorText: errorText };
cacheData("rii_lasterror", lastError);
showNotification("An error occurred.<br/><a class=\"imageInfoErrorReport\" target=\"_blank\" href=\"/message/compose/?to=absurdlyobfuscated&subject=" + encodeURIComponent("Reddit image info script error") + "&message=" + encodeURIComponent("Your script bugged out on me! https://www.youtube.com/watch?v=8ZCysBT5Kec\n\n" + errorText) + "\">Report this error.</a>", 5000);
}
function getDefaultSettings(metaData, currentSetting)
{
var defaultValue = typeof currentSetting == "undefined" ? metaData.defaultValue : currentSetting;
var hasDefaultValue = typeof defaultValue != "undefined" && defaultValue !== null;
if (metaData.type == "array")
{
var newSettingArray = [];
for (var i = 0; i < (hasDefaultValue ? defaultValue.length : 0); i++)
newSettingArray.push(getDefaultSettings(metaData.arrayItem, defaultValue[i]));
return newSettingArray;
}
else if (metaData.type == "object")
{
var newSettingObject = {};
for (var childSetting in metaData.children)
{
var childMetaData = metaData.children[childSetting];
if (childMetaData.type == "group")
{
if (hasDefaultValue)
newSettingObject[childSetting] = defaultValue[childSetting];
for (var groupChildSetting in childMetaData.children)
newSettingObject[groupChildSetting] = getDefaultSettings(childMetaData.children[groupChildSetting], hasDefaultValue ? defaultValue[groupChildSetting] : undefined);
}
else
newSettingObject[childSetting] = getDefaultSettings(childMetaData, hasDefaultValue ? defaultValue[childSetting] : undefined);
}
if (metaData.version)
newSettingObject.version = metaData.version;
return newSettingObject;
}
return defaultValue;
}
function attachEvents(events)
{
for (var i = 0; i < events.length; i++)
$(events[i].selector).each(events[i].event);
}
function arrayItemHtml(setting, metaData, settingValue, parentSetting, events, arrayItemName)
{
return "<div class=\"imageInfoSettingArrayItem\"><div class=\"imageInfoSettingArrayRemove imageInfoSprite imageInfoLink\" title=\"Remove this " + arrayItemName + "\" onclick=\"$(this).parent().remove();\"></div>" + settingHtml(metaData.type, setting, metaData, settingValue, parentSetting, events) + "</div>";
}
function settingHtml(type, setting, metaData, settingValue, parentSetting, events)
{
var settingsHtml = "";
if (type != "object")
{
settingsHtml += "<div class=\"imageInfoSettingItem\">";
if (metaData.name)
{
settingsHtml += "<div class=\"" + (type == "array" ? "imageInfoSettingArrayTitle" : "imageInfoSettingTitle");
if (metaData.tooltip)
settingsHtml += "\" title=\"" + metaData.tooltip;
settingsHtml += "\">" + metaData.name + "</div>";
}
}
settingsHtml += "<div class=\"imageInfoSettingValue";
if (type != "array" && type != "object" && typeof metaData.defaultValue != "undefined" && metaData.defaultValue !== "" && metaData.defaultValue !== 0 && settingValue != metaData.defaultValue)
{
settingsHtml += " imageInfoSettingValueNonDefault\" title=\"default value: ";
if (type == "string")
settingsHtml += """ + metaData.defaultValue + """;
else if (type == "boolean")
settingsHtml += metaData.defaultValue ? "checked" : "unchecked";
else
settingsHtml += metaData.defaultValue;
}
settingsHtml += "\">";
switch (type)
{
case "color":
settingsHtml += "<input type=\"text\" class=\"imageInfoSetting jscolor\" id=\"" + setting + "\"";
if (parentSetting)
settingsHtml += " data-parent=\"" + parentSetting + "\" />";
events.push({
selector: "#" + setting,
event: function() {
var picker = new jscolor(this, { uppercase: false });
picker.fromString(settingValue);
}
});
break;
case "string":
case "number":
settingsHtml += "<input type=\"text\" class=\"imageInfoSetting\" id=\"" + setting + "\"";
if (parentSetting)
settingsHtml += " data-parent=\"" + parentSetting + "\"";
settingsHtml += " value=\"" + settingValue + "\" />";
break;
case "boolean":
settingsHtml += "<input type=\"checkbox\" class=\"imageInfoSetting\" id=\"" + setting + "\"";
if (parentSetting)
settingsHtml += " data-parent=\"" + parentSetting + "\"";
settingsHtml += (settingValue ? "checked=\"checked\"" : "") + " />";
break;
case "array":
settingsHtml += "<div class=\"imageInfoSetting\"";
if (parentSetting)
settingsHtml += " data-parent=\"" + parentSetting;
settingsHtml += "\" id=\"" + setting + "\">";
for (var i = 0; i < settingValue.length; i++)
settingsHtml += arrayItemHtml(setting + "_" + i, metaData.arrayItem, settingValue[i], setting, events, metaData.arrayItemName);
settingsHtml += "</div><div class=\"imageInfoSettingArrayAdd imageInfoSprite imageInfoLink\" id=\"imageInfoSettingArrayAdd_" + setting + "\" title=\"Add new " + metaData.arrayItemName + "\" />";
var nextIndex = settingValue.length;
events.push({
selector: "#imageInfoSettingArrayAdd_" + setting,
event: function() {
$(this).click(function() {
var newEvents = [];
$("#" + setting).append($(arrayItemHtml(setting + "_" + (nextIndex++), metaData.arrayItem, metaData.arrayItem.defaultValue, setting, newEvents, metaData.arrayItemName)));
attachEvents(newEvents);
});
}
});
break;
case "object":
settingsHtml += "<div class=\"imageInfoSetting\"";
if (parentSetting)
settingsHtml += " data-parent=\"" + parentSetting + "\"";
settingsHtml += " id=\"" + setting + "\">";
for (var childSetting in metaData.children)
{
var childMetaData = metaData.children[childSetting];
if (childMetaData.type == "group")
{
settingsHtml += "<div class=\"imageInfoSettingGroup";
if (settingValue && settingValue[childSetting] ? settingValue[childSetting].collapsed : childMetaData.collapsedByDefault)
settingsHtml += " imageInfoSettingGroupCollapsed";
settingsHtml += "\" id=\"" + setting + "_" + childSetting + "\"><div class=\"imageInfoSettingGroupTitle\">" + childMetaData.name + "<div class=\"imageInfoSettingCollapse imageInfoSprite imageInfoLink\"></div></div>";
for (var groupChildSetting in childMetaData.children)
{
var groupChildMetaData = childMetaData.children[groupChildSetting];
settingsHtml += settingHtml(groupChildMetaData.type, setting + "_" + groupChildSetting, groupChildMetaData, settingValue ? settingValue[groupChildSetting] : groupChildMetaData.defaultValue, setting, events);
}
settingsHtml += "</div>";
}
else
settingsHtml += settingHtml(childMetaData.type, setting + "_" + childSetting, childMetaData, settingValue ? settingValue[childSetting] : childMetaData.defaultValue, setting, events);
}
settingsHtml += "</div>";
break;
}
settingsHtml += "</div>";
if (metaData && metaData.desc)
settingsHtml += "<div class=\"imageInfoSettingDesc\">" + metaData.desc + "</div>";
if (type != "object")
settingsHtml += "</div>";
return settingsHtml;
}
function readSetting(type, setting, metaData, settingInput, parentSetting)
{
var valid = true;
var settingValue;
switch (type)
{
case "color":
case "string":
settingValue = settingInput.val();
break;
case "number":
var value = +settingInput.val();
if (isNaN(value))
{
showNotification("Invalid numeric value for setting " + metaData.name + ": " + settingInput.val(), null, function() {
settingInput.focus();
});
valid = false;
break;
}
settingValue = value;
break;
case "boolean":
settingValue = settingInput.prop("checked");
break;
case "array":
var settingArray = [];
$(".imageInfoSetting[data-parent=" + setting + "]").each(function() {
settingArray.push(readSetting(metaData.arrayItem.type, $(this).attr("id"), metaData.arrayItem, $(this), setting));
});
settingValue = settingArray;
break;
case "object":
var settingObj = {};
for (var childSetting in metaData.children)
{
var childMetaData = metaData.children[childSetting];
if (childMetaData.type == "group")
{
settingObj[childSetting] = { collapsed: $("#" + setting + "_" + childSetting).hasClass("imageInfoSettingGroupCollapsed") };
for (var groupChildSetting in childMetaData.children)
{
var groupChildMetaData = childMetaData.children[groupChildSetting];
settingObj[groupChildSetting] = readSetting(groupChildMetaData.type, setting + "_" + groupChildSetting, groupChildMetaData, $("#" + setting + "_" + groupChildSetting), setting);
}
}
else
settingObj[childSetting] = readSetting(childMetaData.type, setting + "_" + childSetting, childMetaData, $("#" + setting + "_" + childSetting), setting);
}
if (metaData.version)
settingObj.version = metaData.version;
settingValue = settingObj;
break;
}
if (!valid)
throw new Error("invalid");
return settingValue;
}
function settingDiffText(settingName, metaData, settingValue, arrayDefaultValue)
{
var diffText = "";
var defaultValue = typeof arrayDefaultValue == "undefined" ? metaData.defaultValue : arrayDefaultValue;
if (metaData.type == "array")
{
if (!settingValue)
diffText += settingName + "\n";
else
{
for (var i = 0; i < settingValue.length; i++)
diffText += settingDiffText(settingName + " > Item " + i, metaData.arrayItem, settingValue[i], metaData.defaultValue && i < metaData.defaultValue.length ? metaData.defaultValue[i] : undefined);
}
}
else if (metaData.type == "object")
{
if (!settingValue)
diffText += settingName + "\n";
else
{
for (var childSetting in metaData.children)
{
var childMetaData = metaData.children[childSetting];
if (childMetaData.type == "group")
{
for (var groupChildSetting in childMetaData.children)
{
var groupChildMetaData = childMetaData.children[groupChildSetting];
diffText += settingDiffText(childMetaData.name + " > " + (groupChildMetaData.name || groupChildSetting), groupChildMetaData, settingValue[groupChildSetting], arrayDefaultValue ? arrayDefaultValue[groupChildSetting] : undefined);
}
}
else
diffText += settingDiffText((settingName ? settingName + " > " : "") + (childMetaData.name || childSetting), childMetaData, settingValue[childSetting], arrayDefaultValue ? arrayDefaultValue[childSetting] : undefined);
}
}
}
else if (settingValue != defaultValue)
diffText += settingName + ": " + defaultValue + " => " + settingValue + "\n";
return diffText;
}
function filterEmpty(value)
{
return !!value;
}
function getTextHighlightHtml(text)
{
if (text)
{
for (var i = 0; i < descriptionHighlight.length; i++)
{
var desc = descriptionHighlight[i];
var match = text.match(new RegExp(desc.textRegex, "i"));
if (match)
{
var matchStart = text.indexOf(match[0]);
var textHtml = text.substring(0, matchStart) + "<div style=\"background-color: #" + desc.highlightColor + "; color: #" + desc.highlightTextColor + ";\"";
if (desc.highlightDetails)
textHtml += " title=\"" + desc.highlightDetails + "\"";
textHtml += ">" + match[0] + "</div>" + getTextHighlightHtml(text.substring(matchStart + match[0].length));
return textHtml;
}
}
}
return text;
}
function linkify(text)
{
var match = text.match(/(<[a-z]+[^>]+>)(.*)(<\/[a-z]+>)/i);
if (match)
{
var tagStart = text.indexOf(match[0]);
return linkify(text.substring(0, tagStart)) + match[1] + getTextHighlightHtml(match[2]) + match[3] + linkify(text.substring(tagStart + match[0].length));
}
match = text.match(new RegExp(urlRegex, "i"));
if (match)
{
var urlStart = text.indexOf(match[0]);
var linkHtml = "<a class=\"imageInfoDescLink";
if (settings.highlightDescriptionLinks)
linkHtml += " imageInfoButton\" style=\"background-color: #" + settings.descriptionLinkColor + "; color: #" + settings.descriptionLinkTextColor;
linkHtml += "\" href=\"" + match[0].replace(/\s+/g, "") + "\">" + getTextHighlightHtml(match[0]) + "</a>";
return getTextHighlightHtml(text.substring(0, urlStart)) + linkHtml + linkify(text.substring(urlStart + match[0].length));
}
else
return getTextHighlightHtml(text);
}
function dateUnit(diff, unitDiv, unitMod, unitLabel, padDigits, optional)
{
var unitNum = Math.floor(diff / unitDiv);
if (optional && unitNum < 1)
return "";
if (unitMod)
unitNum %= unitMod;
if (padDigits)
return (Array(padDigits).join("0") + unitNum).slice(-padDigits) + unitLabel;
else
return unitNum + unitLabel;
}
function dateDiff(diff)
{
var diffText = diff < 0 ? "+" : "-";
diff = Math.abs(diff);
diffText += dateUnit(diff, 365 * 24 * 60 * 60 * 1000, 0, "Y ", 0, true);
diffText += dateUnit(diff, 24 * 60 * 60 * 1000, 365, "D ", 0, true);
diffText += dateUnit(diff, 60 * 60 * 1000, 24, ":", 2, false);
diffText += dateUnit(diff, 60 * 1000, 60, ":", 2, false);
diffText += dateUnit(diff, 1000, 60, "", 2, false);
return diffText;
}
function linkColor(href)
{
if (/\/a\/[\d\w]+/i.test(href))
return settings.albumColor;
if (/\.gifv$/i.test(href))
return settings.gifvColor;
if (/\.(webm|mp4)$/i.test(href))
return settings.webmColor;
if (/\.\w+((\?|#).+)?$/i.test(href))
return settings.gifColor;
return settings.galleryColor;
}
function durationColor(duration)
{
if (settings.useGradient)
return "ff" + ("0" + Math.floor(255 - Math.min(duration - settings.gradientDurationMin, settings.gradientDurationMax - settings.gradientDurationMin) * 255 / (settings.gradientDurationMax - settings.gradientDurationMin)).toString(16)).slice(-2) + "00";
return settings.longDurationColor;
}
function durationTextColor(duration)
{
if (settings.useGradient)
return Math.min(duration - settings.gradientDurationMin, settings.gradientDurationMax - settings.gradientDurationMin) / (settings.gradientDurationMax - settings.gradientDurationMin) > 0.2 ? "fff" : "000";
return settings.longDurationTextColor;
}
function highlightLink(entry, color)
{
if (!color)
color = "f00";
entry.parents("div.link").find("a.thumbnail").first().attr("style", "border: 3px solid #" + color + " !important");
}
function getAuthorTagHtml(authorTags, authorName)
{
var tagHtml = "";
for (i = 0; i < authorTags.length; i++)
{
var authorTag = authorTags[i];
if (authorTag.tag && new RegExp(authorTag.authorRegex, "i").test(authorName))
tagHtml += " <div class=\"imageInfoButton\" style=\"background-color: #" + authorTag.tagColor + "; color: #" + authorTag.tagTextColor + ";\"" + (authorTag.tagDetails ? " title=\"" + authorTag.tagDetails + "\"" : "") + ">" + authorTag.tag + "</div>";
}
return tagHtml;
}
function getDurationHtml(duration, minDuration, maxDuration)
{
var checkDuration = duration || maxDuration && minDuration;
if (!checkDuration)
return "";
var durationHtml = "<div";
if (settings.highlightLongDuration && (checkDuration >= settings.gradientDurationMin || checkDuration >= settings.longDuration))
durationHtml += " class=\"imageInfoButton\" style=\"background-color: #" + durationColor(checkDuration) + "; color: #" + durationTextColor(checkDuration) + ";\"";
if (duration)
durationHtml += ">" + (+duration).toFixed(2);
else
durationHtml += " title=\"approximate duration reported by API, expand for exact duration\">" + (+minDuration).toFixed(2) + "s - " + (+maxDuration).toFixed(2);
durationHtml += "s</div>, ";
return durationHtml;
}
function getFrameRateHtml(estFrameRate, exactFrameRate, apiframeRate, videoFrames, gifFrames, duration)
{
var frameRate = exactFrameRate;
var approximate = false;
var precision = 2;
if (!exactFrameRate)
{
if (duration && videoFrames)
frameRate = videoFrames / duration;
else if (duration && gifFrames)
frameRate = gifFrames / duration;
else
{
precision = 0;
if (estFrameRate)
{
frameRate = estFrameRate;
approximate = true;
}
else
frameRate = apiframeRate;
}
}
var frameRateHtml = "<div";
if (frameRate)
{
if (settings.highlightLowFrameRate && frameRate < settings.lowFrameRate)
frameRateHtml += " class=\"imageInfoButton\" style=\"background-color: #" + settings.lowFrameRateColor + "; color: #" + settings.lowFrameRateTextColor + ";\"";
else if (settings.highlightHighFrameRate && frameRate > settings.highFrameRate)
frameRateHtml += " class=\"imageInfoButton\" style=\"background-color: #" + settings.highFrameRateColor + "; color: #" + settings.highFrameRateTextColor + ";\"";
var titleText = [];
if (approximate)
titleText.push("approximate frame rate as reported by your browser");
if (duration && videoFrames)
titleText.push("frame rate based on " + duration.toFixed(3) + "s duration and " + videoFrames + " video frames" + (approximate ? ": " + (videoFrames / duration).toFixed(2) : ""));
else if (duration && gifFrames)
titleText.push("frame rate based on " + duration.toFixed(3) + "s duration and " + gifFrames + " GIF frames" + (approximate ? ": " + (gifFrames / duration).toFixed(2) : ""));
if (apiframeRate)
titleText.push("frame rate reported by API" + (exactFrameRate || estFrameRate || duration ? ": " + apiframeRate : ""));
if (titleText.length > 0)
frameRateHtml += " title=\"" + titleText.join(", ") + "\"";
}
frameRateHtml += ">";
if (frameRate)
frameRateHtml += (approximate ? "~" : "") + (+frameRate).toFixed(precision) + " FPS</div>, ";
else if (videoFrames || gifFrames)
frameRateHtml += (videoFrames ? "video" : "GIF") + " frames: " + (videoFrames || gifFrames) + "</div>, ";
else
frameRateHtml += "</div>";
return frameRateHtml;
}
function getDimensionsHtml(width, height)
{
var dimensionHtml = "<div";
if (settings.highlightLowResolution && Math.min(width, height) < settings.lowResolution)
dimensionHtml += " class=\"imageInfoButton\" style=\"background-color: #" + settings.lowResolutionColor + "; color: #" + settings.lowResolutionTextColor + ";\"";
else if (settings.highlightHighResolution && Math.max(width, height) > settings.highResolution)
dimensionHtml += " class=\"imageInfoButton\" style=\"background-color: #" + settings.highResolutionColor + "; color: #" + settings.highResolutionTextColor + ";\"";
dimensionHtml += ">" + width + "x" + height + "</div>, ";
return dimensionHtml;
}
function getSizeHtml(size, highlightLarge, label)
{
var sizeHtml = "<div ";
if (highlightLarge && settings.highlightLargeSize && size > settings.largeSize)
sizeHtml += " class=\"imageInfoButton\" style=\"background-color: #" + settings.largeSizeColor + "; color: #" + settings.largeSizeTextColor + ";\"";
sizeHtml += "title=\"" + label + " size: " + size + " bytes\">" + (size / 1024).toFixed(2) + " KB</div>";
return sizeHtml;
}
// https://en.wikipedia.org/wiki/Levenshtein_distance
function levenshteinDistance(stringA, stringB)
{
if (!stringA)
{
if (!stringB)
return 0;
return stringB.length;
}
if (!stringB)
return stringA.length;
var distance = [];
var i, j;
for (i = 0; i <= stringA.length; i++)
{
var distanceRow = new Array(stringB.length + 1);
distanceRow[0] = i;
for (j = 0; j <= (i > 0 ? 0 : stringB.length); distanceRow[j] = j++);
distance.push(distanceRow);
}
for (i = 1; i <= stringA.length; i++)
{
for (j = 1; j <= stringB.length; j++)
{
var cost = stringB[j - 1] == stringA[i - 1] ? 0 : 1;
var min1 = distance[i - 1][j] + 1;
var min2 = distance[i][j - 1] + 1;
var min3 = distance[i - 1][j - 1] + cost;
distance[i][j] = Math.min(Math.min(min1, min2), min3);
}
}
return distance[stringA.length][stringB.length];
}
function showMediaInfo(entry, positionElement, mediaInfo)
{
var timestamp = new Date(mediaInfo.datetime);
var diff = new Date(entry.find("time").attr("datetime")).getTime() - mediaInfo.datetime;
var infoHtmlItems = [];
var headerHtml = "";
if (mediaInfo.albumImageCount)
headerHtml += "<div class=\"imageInfoAlbumImageCount\">" + mediaInfo.albumImageCount + " image" + (mediaInfo.albumImageCount == 1 ? "" : "s") + "</div>";
if (mediaInfo.authorName)
{
if (mediaInfo.albumImageCount)
headerHtml += " ";
if (mediaInfo.authorLink)
headerHtml += "<a href=\"" + mediaInfo.authorLink + "\">" + mediaInfo.authorName + "</a>";
else
headerHtml += mediaInfo.authorName;
if (settings.highlightSameAuthor && mediaInfo.authorName.toLowerCase() == entry.find("p.tagline a.author").text().toLowerCase().replace(/[\-_]/g, ""))
headerHtml += " <div class=\"imageInfoButton\" style=\"background-color: #" + settings.sameAuthorColor + "; color: #" + settings.sameAuthorTextColor + ";\" title=\"reddit author matches " + mediaInfo.mediaName + " author\">=</div>";
if (tagData && tagData.authorTags)
headerHtml += getAuthorTagHtml(tagData.authorTags, mediaInfo.authorName);
if (settings.authorTags)
headerHtml += getAuthorTagHtml(settings.authorTags, mediaInfo.authorName);
if (mediaInfo.authorAltLink)
headerHtml += " (<a href=\"" + mediaInfo.authorAltLink + "\">" + mediaInfo.authorAltLinkName + "</a>)";
}
if (headerHtml)
infoHtmlItems.push(headerHtml);
if (mediaInfo.pageLink)
infoHtmlItems.push("<a href=\"" + mediaInfo.pageLink + "\">" + mediaInfo.pageLinkText + "</a>");
if (mediaInfo.pageExtraInfo)
infoHtmlItems.push(mediaInfo.pageExtraInfo);
var tagItems = [];
if (mediaInfo.mediaTagHtmlItems && mediaInfo.mediaTagHtmlItems.length > 0)
tagItems.push(mediaInfo.mediaTagHtmlItems.join(" "));
if (mediaInfo.rating)
tagItems.push("<div class=\"" + (/R|NSFW|Adult|Possibly Offensive/.test(mediaInfo.rating) ? "nsfw-stamp " : "") + "stamp\">" + mediaInfo.rating + "</div>");
if (mediaInfo.source)
tagItems.push("<a href=\"" + mediaInfo.source + "\">source</a>");
if (tagItems.length > 0)
infoHtmlItems.push(tagItems.join(" "));
if (!mediaInfo.albumImageCount)
{
var mediaDetailHtml = "<div class=\"imageInfoDuration\">";
if (mediaInfo.animated)
mediaDetailHtml += getDurationHtml(mediaInfo.duration, mediaInfo.minDuration, mediaInfo.maxDuration);
mediaDetailHtml += "</div><div class=\"imageInfoFrameRate\"";
if (mediaInfo.frameRate || mediaInfo.gifFrames || mediaInfo.videoFrames || mediaInfo.animated)
{
if (mediaInfo.frameRate)
mediaDetailHtml += "data-frame-rate=\"" + mediaInfo.frameRate + "\"";
if (mediaInfo.gifFrames)
mediaDetailHtml += "data-gif-frames=\"" + mediaInfo.gifFrames + "\"";
if (mediaInfo.videoFrames)
mediaDetailHtml += "data-video-frames=\"" + mediaInfo.videoFrames + "\"";
mediaDetailHtml += ">" + getFrameRateHtml(null, null, mediaInfo.frameRate, mediaInfo.videoFrames, mediaInfo.gifFrames, mediaInfo.duration);
}
else
mediaDetailHtml += ">";
mediaDetailHtml += "</div>";
if (mediaInfo.width && mediaInfo.height)
mediaDetailHtml += getDimensionsHtml(mediaInfo.width, mediaInfo.height);
else
mediaDetailHtml += "<div class=\"imageInfoDimensions\"></div>";
if (mediaInfo.videoSize)
{
mediaDetailHtml += getSizeHtml(mediaInfo.videoSize, true, "video");
if (mediaInfo.imageSize)
mediaDetailHtml += " / ";
}
if (mediaInfo.imageSize)
mediaDetailHtml += getSizeHtml(mediaInfo.imageSize, !mediaInfo.isVideoLink || !mediaInfo.videoSize, mediaInfo.animated ? "GIF" : "image");
if (mediaInfo.width && mediaInfo.height && (mediaInfo.videoSize || mediaInfo.imageSize))
mediaDetailHtml += " <div class=\"imageInfoTagMedia imageInfoLink\" title=\"tag this media item\">[T]</div>";
infoHtmlItems.push(mediaDetailHtml);
}
if (mediaInfo.datetime)
{
var dateHtml = "<div ";
if (settings.highlightOld && diff > settings.oldTimeDiff * 60000)
dateHtml += "class=\"imageInfoButton\" style=\"background-color: #" + settings.oldColor + "; color: #" + settings.oldTextColor + ";\" ";
dateHtml += "title=\"" + mediaInfo.mediaName + " time: " + timestamp.toGMTString() + "\">T" + dateDiff(diff) + "</div>";
infoHtmlItems.push(dateHtml);
}
var titleHtml = "";
if (mediaInfo.tags)
titleHtml += "[" + mediaInfo.tags + "] ";
if (mediaInfo.title)
{
var similarity = 0;
if (settings.highlightSameTitle)
{
var redditTitle = (positionElement.attr("href") ? positionElement : entry.find("a.title")).text().trim().toLowerCase();
var mediaTitle = mediaInfo.title.replace(/[\u00a0\s]+/g, " ").trim().toLowerCase();
var mediaTitleAlt = mediaTitle.replace(/imgur/gi, "reddit");
if (redditTitle == mediaTitle || redditTitle == mediaTitleAlt || redditTitle == mediaTitleAlt.replace(/\b(i|me|my|mine|myself|we|us|our|ours|ourselves|meet|itap)\b/gi, "").replace(/[\u00a0\s]+/g, " "))
titleHtml += "<div class=\"imageInfoButton\" style=\"background-color: #" + settings.sameTitleColor + "; color: #" + settings.sameTitleTextColor + ";\" title=\"reddit title matches " + mediaInfo.mediaName + " title\">same title</div> ";
else
{
var titleLength = Math.max(redditTitle.length, mediaTitle.length);
redditTitle = redditTitle.replace(/[^\w\s]/g, "");
mediaTitle = mediaTitle.replace(/[^\w\s]/g, "");
var fuzziness = redditTitle.length > mediaTitle.length ? levenshteinDistance(mediaTitle, redditTitle) : levenshteinDistance(redditTitle, mediaTitle);
similarity = Math.round(100 - fuzziness / titleLength * 100);
if (similarity >= settings.minimumTitleSimilarity)
titleHtml += "<div class=\"imageInfoButton\" style=\"background-color: #" + settings.sameTitleColor + "; color: #" + settings.sameTitleTextColor + ";\" title=\"reddit title is similar to " + mediaInfo.mediaName + " title (non-symbol character difference: " + fuzziness + ")\">similar title " + similarity + "%</div> ";
}
if (mediaInfo.title == mediaInfo.description)
titleHtml += "<div class=\"imageInfoButton\" style=\"background-color: #" + settings.sameTitleColor + "; color: #" + settings.sameTitleTextColor + ";\" title=\"" + mediaInfo.mediaName + " title matches " + mediaInfo.mediaName + " description, this is common with account farmers\">title/description match</div> ";
}
titleHtml += "<div class=\"imageInfoDesc imageInfoButton\">\"";
if (similarity)
titleHtml += "<div title=\"similarity to reddit title: " + similarity + "%\">" + linkify(mediaInfo.title) + "</div>";
else
titleHtml += linkify(mediaInfo.title);
titleHtml += (mediaInfo.description ? " /// " + linkify(mediaInfo.description).replace(/\n/g, " // ") : "") + "\"</div>";
}
else if (mediaInfo.description)
titleHtml += "<div class=\"imageInfoDesc imageInfoButton\">\"" + linkify(mediaInfo.description).replace(/\n/g, " // ") + "\"</div>";
if (titleHtml)
infoHtmlItems.push(titleHtml);
var infoHtml = "<div class=\"imageInfo\">" + infoHtmlItems.join(", ") + "</div>";
if (positionElement.attr("href"))
infoHtml = "<div class=\"" + (settings.commentMediaInfoInline ? "imageInfoCommentInline" : "imageInfoComment") + "\"><div class=\"imageInfoCommentInlineExpando\"></div>" + infoHtml + "</div>";
positionElement.nextAll(".imageInfoRetry").remove();
var mediaInfoElement = $(infoHtml).insertAfter(positionElement);
if (mediaInfo.width && mediaInfo.height && (mediaInfo.videoSize || mediaInfo.imageSize))
mediaInfoElement.find(".imageInfoTagMedia").click(function() {
$(".imageInfoSettingsButton").click();
$("#imageInfoSetting_groupTags").removeClass("imageInfoSettingGroupCollapsed");
$("#imageInfoSettingArrayAdd_imageInfoSetting_mediaTags").click();
var tagElements = $(".imageInfoSetting[data-parent=imageInfoSetting_mediaTags]").last().find("input").each(function(index) {
if (index === 0)
$(this).val(mediaInfo.width);
else if (index == 1)
$(this).val(mediaInfo.height);
else if (index == 2)
$(this).val(mediaInfo.imageSize || mediaInfo.videoSize);
else if (index == 3)
$(this).focus();
else
return false;
});
});
return mediaInfoElement;
}
function addRetryButton(link, positionElement, request, error)
{
positionElement.parent().find(".imageInfoRetry").remove();
var resp = request.responseJSON;
if (resp)
error = resp.error || (resp.data && resp.data.error) || error;
if (error == "Daily client requests exceeded")
showNotification("API rate limit exceeded. You may need to set a new API client ID in the reddit image info options.", 5000);
$("<div class=\"imageInfoRetry imageInfoButton imageInfoGreyButton imageInfoLink\" title=\"click to retry\">" + error + "</div>").insertAfter(positionElement).click(function() {
$(this).text("Retrying...");
checkLink(link);
});
}
function addMediaTagHtmlItems(tagHtmlItems, width, height, imgSize, videoSize)
{