-
Notifications
You must be signed in to change notification settings - Fork 6
/
SOUP.user.js
2296 lines (2172 loc) · 103 KB
/
SOUP.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 Stack Overflow Unofficial Patch
// @namespace https://github.com/vyznev/
// @description Miscellaneous client-side fixes for bugs on Stack Exchange sites
// @author Ilmari Karonen
// @version 1.56.2
// @copyright 2014-2019, Ilmari Karonen (https://stackapps.com/users/10283/ilmari-karonen)
// @license ISC; https://opensource.org/licenses/ISC
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
// @match *://*.serverfault.com/*
// @match *://*.stackapps.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.askubuntu.com/*
// @exclude https://stackoverflow.com/c/*
// @homepageURL https://stackapps.com/questions/4486/the-stack-overflow-unofficial-patch-soup
// @updateURL https://github.com/vyznev/soup/raw/master/SOUP.meta.js
// @downloadURL https://github.com/vyznev/soup/raw/master/SOUP.user.js
// @icon https://github.com/vyznev/soup/raw/master/icon/SOUP_icon_128.png
// @grant none
// @run-at document-start
// @noframes
// ==/UserScript==
// Copyright (C) 2014-2018 by Ilmari Karonen and other contributors
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
// In addition to the license granted above, I, Ilmari Karonen, to the extent I
// am authorized to do so, and subject to the disclaimer stated above, hereby
// grant Stack Exchange, Inc. permission to make use of this software in any
// way they see fit, including but not limited to incorporating all or parts of
// it within the Stack Exchange codebase, with or without credit to myself.
// This permission grant does not extend to any code written by third parties,
// unless said parties also agree to it.
( function () { // start of anonymous wrapper function (needed to restrict variable scope on Opera)
"use strict";
// Opera does not support @match, so re-check that we're on an SE site before doing anything
var include_re = /(^|\.)((stack(exchange|overflow|apps)|superuser|serverfault|askubuntu)\.com|mathoverflow\.net)$/;
if ( ! include_re.test( location.hostname ) ) return;
// also re-check Teams exclusion here, just in case
if ( /^\/c\//.test( location.pathname ) ) return;
// just in case @noframes doesn't work
try { if ( window.self !== window.top ) return } catch (e) { return }
// guard against double inclusion (e.g. user script + extension)
if ( document.getElementById( 'soup-init' ) ) {
if ( window.console && console.log ) console.log( "soup aborting double injection!" );
return;
}
var fixes = {};
//
// CSS-only fixes (injected *before* site CSS!):
//
fixes.mse145819 = {
title: "<hr/>'s do not get rendered in deleted answers",
url: "https://meta.stackexchange.com/q/145819",
css: ".wmd-preview hr { background-color: #ddd; color: #ddd }" +
".deleted-answer .post-text hr, .deleted-answer .wmd-preview hr " +
"{ background-color: #c3c3c3; color: #c3c3c3 }"
};
fixes.mse58760 = {
title: "<kbd> (yes, still <kbd>) doesn't play nice with lists",
url: "https://meta.stackexchange.com/q/58760",
credit: "Krazer",
// NOTE 2014-11-26: the main issue seems to have been fixed, but the secondary width/white-space issues still exist; report as new bug?
// "body" added to increase selector precedence above conflicting SE style
css: "body kbd { display: inline-block; max-width: 100%; white-space: normal }"
};
fixes.mse154788 = {
title: "Why are comments overlapping the sidebar?",
url: "https://meta.stackexchange.com/q/154788",
css: ".comment-body { overflow: auto; overflow-y: hidden; word-wrap: break-word }"
};
fixes.mse214830 = {
title: "Selecting text in profile activity comments causes unexpected clipping",
url: "https://meta.stackexchange.com/q/214830",
// TODO: Is this still reproducible?
css: "span.comments { padding-bottom: 0 }"
};
fixes.mse230392 = {
title: "Layout bug while viewing vote count in Meta Stackexchange",
url: "https://meta.stackexchange.com/q/230392",
css: "div.vote-count-separator { margin: 5px auto }"
};
fixes.mse224185 = {
title: "Links sometimes float above text in vote-to-close dialog on Firefox",
url: "https://meta.stackexchange.com/q/224185",
// TODO: Is this still reproducible on Firefox?
// "body" added to increase selector precedence over conflicting SE style
css: "body .close-as-off-topic-pane .action-name a, " +
"body .close-as-off-topic-pane .action-name { vertical-align: baseline }" +
"body .close-as-off-topic-pane input[type=radio] { vertical-align: top }" +
".close-as-off-topic-pane { line-height: 1.15 }" // related minor issue
};
fixes.mse233517 = {
title: "Badge symbol in notification is of the site you're on, not where badge was earned",
url: "https://meta.stackexchange.com/q/233517",
// some sites (like meta.SE) use !important in badge styles, so we have to use it too :-(
css: ".achievements-dialog .badge1, .achievements-dialog .badge2, .achievements-dialog .badge3 {" +
" height: 8px !important; width: 8px !important; border-radius: 50% !important; margin: 0px 2px 4px }" +
".achievements-dialog .badge1 { background: #ffcc00 !important }" +
".achievements-dialog .badge2 { background: #c5c5c5 !important }" +
".achievements-dialog .badge3 { background: #cc9966 !important }"
};
fixes.mse169225 = {
title: "Why does the bounty award button appear on deleted answers?",
url: "https://meta.stackexchange.com/q/169225",
// .vote added to ensure higher specificity than the physics5773 fix
css: ".deleted-answer .vote .bounty-vote-off { display: none }"
};
fixes.mse84296 = {
title: "RTL text can mess up comment timestamps",
url: "https://meta.stackexchange.com/q/84296",
// FIXME: this apparently breaks stuff on Safari, but SOUP doesn't really have proper Safari support anyway yet
// (this was briefly enabled on SE, but was reverted due to the Safari issue; re-adding it to SOUP for now)
// TODO: check if the Safari issue still persists now that fallbacks have been removed
// SEE ALSO: mso310158 (prevent runaway BiDi overrides in new comments)
// NOTE: the #chat-body selectors and the .soup-bidi-isolate class are used by the mse342361 fix
css: '.comment-copy, .comment-user, .user-details a, a[href^="/users/"], #chat-body .user-name, #chat-body .text, .soup-bidi-isolate { unicode-bidi: isolate }'
};
fixes.mse249859 = {
title: "<kbd> tags in headings are too small",
url: "https://meta.stackexchange.com/q/249859",
credit: "Doorknob",
// "body" added to increase selector precedence over conflicting SE style
css: "body kbd { font-size: 80% }"
};
fixes.mse248156 = {
title: "What's the purpose of the tagline in the Bounties section of the profile?",
url: "https://meta.stackexchange.com/q/248156",
css: "#user-tab-bounties #bounties-table .started { display: none }"
};
fixes.mse250081 = {
title: "Retract close vote UI",
url: "https://meta.stackexchange.com/q/250081",
credit: "style suggested by AstroCB",
// FIXME: This doesn't work on pt.SO or ja.SO; should find out how this tooltip is translated there
css: ".close-question-link[title^=\"You voted to\"] { color: #444 }"
};
fixes.mso287222 = {
title: "Clicking between lines fails",
url: "https://meta.stackoverflow.com/q/287222",
credit: "Travis J",
// TODO: Are the bottom margin/border hacks still needed?
// list of problem sites: cooking cstheory english gamedev gaming math photo programmers stats tex unix webapps
// see also: https://gaming.meta.stackexchange.com/questions/10227/sidebar-links-wobble-when-hovered
css: ".question-summary .answer-hyperlink, " +
".question-summary .question-hyperlink, " +
".module.community-bulletin .question-hyperlink, " +
".question-summary .result-link a { " +
" display: block; margin-bottom: -1px; border-bottom: 1px solid transparent }" +
".question-summary .activity-indicator { float: left; margin-top: 4px }" // https://github.com/vyznev/soup/issues/44
};
fixes.mso297678 = {
title: "Comment anchor links get “visited” highlighting",
url: "https://meta.stackoverflow.com/q/297678",
// TODO: Is this still reproducible?
// XXX: this selector needs to be more specific than ".comment-text a:not(.comment-user):visited"
css: "body .comment-date a.comment-link, " +
"body .comment-date a.comment-link:visited { color: inherit }"
};
fixes.mse242944 = {
title: "Long display name with no spaces breaks design of review history pages",
url: "https://meta.stackexchange.com/q/242944",
// TODO: Should the width:120px style be removed?
css: "body.review-page .history-table td:nth-child(1) " +
"{ width: 120px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; color: #999 }"
};
fixes.mse266258 = {
title: "Left side markdown diff outside of its area",
url: "https://meta.stackexchange.com/q/266258",
css: ".full-diff .diff-delete:after, .full-diff .diff-add:after { content: ''; font-size: 0px }"
};
fixes.mso342634 = {
title: "“Hot Meta Posts” with a 4-digit score wrap onto a second line",
url: "https://meta.stackoverflow.com/q/342634",
css: ".bulletin-item-type { white-space: nowrap }"
};
fixes.mse186748 = {
title: "Duplicate dialog close button causes preview to be too narrow",
url: "https://meta.stackexchange.com/q/186748",
css: ".popup-close { margin-left: -100% }" +
".popup .close-as-duplicate-pane #search-text, .popup .close-as-duplicate-pane .actual-edit-overlay" +
" { width: 100% !important; box-sizing: border-box }"
};
fixes.mse290496 = {
title: "Minor alignment issue in few of the Badge page's “Awarded to” text",
url: "https://meta.stackexchange.com/q/290496",
css: "body.badges-page .single-badge-table .single-badge-row-double .single-badge-awarded { width: 100% }"
};
fixes.mse291623 = {
title: "Links that are italics and bold not showing as links in Mobile Web",
url: "https://meta.stackexchange.com/q/291623",
// only the mobile view uses <main> tags
css: "main .post-text em, main .post-text a > em { color: inherit }"
};
fixes.mse287196 = {
title: "Tick sign is not centered on single badge page",
url: "https://meta.stackexchange.com/q/287196",
css: "body.badges-page .single-badge-table .single-badge-wrapper .single-badge-badge { vertical-align: baseline }"
};
fixes.mse302580 = {
title: "Printing an SE page in Firefox shows only the first page",
url: "https://meta.stackexchange.com/q/302580",
// TODO: Is this still reproducible on Firefox?
css: "@media print {\nbody { display: block !important }}"
};
fixes.mse302569 = {
title: "Alignment improvement in the flag dialog",
url: "https://meta.stackexchange.com/q/302569",
// TODO: Is this still reproducible?
css: "body .popup .already-flagged { margin-left: 23px }"
};
fixes.mse304096 = {
title: "Comments and answers have huge right margins when printed",
url: "https://meta.stackexchange.com/q/304096",
css: "@media print {\n" +
"body .container, body #mainbar, body .mainbar, body .post-text, body .comments, body #answers-header, body .answer, body pre { width: auto }" +
".question > table, .answer > table { width: 100% }" +
"}"
};
fixes.mso306552 = {
title: "Votes cast has upvote-like symbol and is confusing",
url: "https://meta.stackoverflow.com/q/306552",
path: /^\/users\/\d+/,
css: '.profile-cards div[title$="votes cast"] > div:nth-child(1) svg.iconArrowUp { display: none }' +
'.profile-cards div[title$="votes cast"] > div:nth-child(1) { background: url(data:image/svg+xml,' + encodeURIComponent(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 18 18" stroke="#9199a1">' +
'<path d="M3 7.5h12L9 1.5z" fill="#9199a1"/>' +
'<path d="M3 10.5h12L9 16.5z" fill="none"/>' +
'</svg>'
) + '); width: 18px; height: 18px }'
};
fixes.mse304247 = {
title: "Attempting to use too long tag breaks popup",
url: "https://meta.stackexchange.com/q/304247",
// TODO: Is the .message-text class still used anywhere?
css: ".message-text, .js-stacks-validation-message { word-wrap: break-word }"
};
// site-specific CSS fixes:
fixes.codegolf959 = {
title: "Add line-height shortener to the ascii-art tag",
url: "https://codegolf.meta.stackexchange.com/q/959",
sites: /^(codegolf|puzzling)\./,
css: "pre { line-height: 1.15 }"
};
if (false) fixes.math12902 = {
title: "Visited questions are practically indistinguishable in search results",
url: "https://math.meta.stackexchange.com/q/12902",
sites: /^math\.stackexchange\.com$/, // XXX: main site only!
// FIXME: Disabled temporarily due to conflicts with new CSS; fix or remove!
// "body" added to override conflicting SE styles
css: "body a, body .question-hyperlink { color: #145d8a }" +
"body a:visited, body .question-hyperlink:visited { color: #003b52 }" +
// stupid reduntant styles...
"body .user-show-new .question-hyperlink," +
"body .user-show-new .answer-hyperlink," +
"body .user-show-new .site-hyperlink { color: #145d8a !important }" +
"body .user-show-new .question-hyperlink:visited," +
"body .user-show-new .answer-hyperlink:visited," +
"body .user-show-new .site-hyperlink:visited { color: #003b52 !important }"
};
if (false) fixes.math12902_meta = {
title: "Visited questions are practically indistinguishable in search results (meta)",
url: "https://math.meta.stackexchange.com/q/12902",
sites: /^math\.meta\.stackexchange\.com$/,
// FIXME: Disabled temporarily due to conflicts with new CSS; fix or remove!
// "body" added to override conflicting SE styles
css: "body a { color: #a29131 } body a:visited { color: #736722 }"
};
fixes.mse250407 = {
title: "User signature cards on old revisions look funny",
url: "https://meta.stackexchange.com/q/250407",
css: "#revisions table.postcell { width: auto }" // for SO, applied globally
};
fixes.mse244587 = {
title: "“Top Network Users” should contain themselves!",
url: "https://meta.stackexchange.com/q/244587",
sites: /^stackexchange\.com$/,
css: "body .users-sidebar .userLinks { width: 185px; float: right; overflow: hidden; text-overflow: ellipsis }" +
// XXX: these extra rules are not really needed, but they make the layout more robust
"body .users-sidebar .userDetails img { margin-right: 0 }" +
"body .users-sidebar .userDetails { overflow: hidden }"
};
fixes.mse294574 = {
title: "Unbroken line in preview text causes whole post block to side scroll",
url: "https://meta.stackexchange.com/q/294574",
sites: /^stackexchange\.com$/,
css: "#question-list .question { word-wrap: break-word }"
};
fixes.mse306254 = {
title: "Annoying animation on reputation leagues",
url: "https://meta.stackexchange.com/q/306254",
sites: /^stackexchange\.com$/,
// TODO: Is this still reproducible? (Should be safe to keep this fix anyway.)
css: "body .league-container { overflow: hidden }"
};
//
// Chat-specific fixes:
//
fixes.mse155308 = {
title: "Ignoring somebody screws up the avatar list",
url: "https://meta.stackexchange.com/q/155308",
credit: "DaveRandom",
sites: /^chat\./,
css: "#present-users > .present-user.ignored { height: 16px }"
};
fixes.mse216760 = {
title: "The reply buttons in chat shouldn't reposition themselves on pinged messages",
url: "https://meta.stackexchange.com/q/216760",
sites: /^chat\./,
// TODO: Is this still reproducible?
// "body" added to increase selector precedence above conflicting SE style
css: "body .message.highlight { margin-right: 0px }" +
"body .message.highlight .flash { right: -38px }" // regression: https://meta.stackexchange.com/q/221733
};
fixes.mse222509 = {
title: "Getting Red Line under tags",
url: "https://meta.stackexchange.com/q/222509",
sites: /^chat\./,
css: ".ob-post-tags a:hover, .ob-user-tags a:hover, " +
"a.soup-mse222509-fix:hover { text-decoration: none }",
script: function () {
$('#main').on('mouseover', '.ob-post-tag, .ob-user-tag', function () {
$(this).closest('a').not('.soup-mse222509-fix').addClass('soup-mse222509-fix');
} );
}
};
fixes.mse134268 = {
title: "U+0008 inserted into chat @-pings",
url: "https://meta.stackexchange.com/q/134268",
sites: /^chat\./,
// TODO: Is this still reproducible on Firefox?
script: function () {
$('body#chat-body').on( 'keypress', function (e) {
if ( e.ctrlKey || e.altKey || e.metaKey ) return;
if ( !e.which || e.which == 32 || e.which >= 32 ) return;
e.stopPropagation();
} );
}
};
fixes.mse224233 = {
title: "Problem in css style loading in Search Bar after refresh page when using FF",
url: "https://meta.stackexchange.com/q/224233",
sites: /^chat\./,
script: function () {
$('#search:not([placeholder])').off('focus blur').attr( 'placeholder', function () {
var $this = $(this);
if ( $this.closest('#roomsearch').length ) return 'filter rooms';
else if ( $this.closest('#usersearch').length ) return 'filter users';
else return 'search';
} ).filter('.watermark').val('').removeClass('watermark');
}
};
fixes.mso342361 = {
title: "Minor (funny) chat star bug for Hebrew text",
url: "https://meta.stackoverflow.com/q/342361",
sites: /^chat\./,
// TODO: Has this really been fixed?
script: function () {
SOUP.hookAjax( /^\/chats\/stars\/\d+\b/, function () {
$('#starred-posts li').each( function () {
// jQuery doesn't work well with raw text nodes :(
var nodes = null;
for ( var node = this.firstChild; node; node = node.nextSibling ) {
if ( /\bpermalink\b/.test( node.className ) ) break;
else if ( /\bstars\b/.test( node.className ) ) nodes = [];
else if ( nodes ) nodes.push( node );
}
if ( ! nodes || nodes.length < 1 ) return;
// unwrap the trailing dash
var firstNode = nodes[0], lastNode = nodes[nodes.length - 1], text = lastNode.nodeValue;
var match = /(\s+-\s*)$/.exec( text );
if ( match ) {
nodes[nodes.length - 1] = document.createTextNode( text.substr(0, match.index) ); // wrap this...
lastNode.nodeValue = match[0]; // ...instead of this
}
var wrapper = document.createElement( 'span' );
wrapper.className = "soup-bidi-isolate"; // XXX: defined by mse84296 fix
this.insertBefore( wrapper, firstNode );
for ( var i = 0; i < nodes.length; i++ ) {
wrapper.appendChild( nodes[i] );
}
} );
} ).code();
},
css: "#starred-posts .relativetime { unicode-bidi: embed }" // fallback
};
fixes.mso362554 = {
title: "Why are the chat FAQ in almost identical links different?",
url: "https://meta.stackoverflow.com/q/362554",
credit: "suggested by mjpieters (https://github.com/vyznev/soup/issues/33), shim code by Frédéric Hamidi (https://stackoverflow.com/a/29298828)",
sites: /^chat\./,
jqinit: function () {
var slice = Array.prototype.slice;
if ( ! jQuery.curCSS ) jQuery.curCSS = function(element) {
var args = slice.call(arguments, 1);
SOUP.log( 'soup mso362554 jQuery.curCSS shim called on', element, 'with', args );
return jQuery.fn.css.apply(jQuery(element), args);
};
SOUP.log( 'soup mso362554 jQuery.curCSS shim applied' );
}
};
//
// General fixes that need scripting (run in page context after jQuery / SE framework is ready):
//
fixes.mse261721 = {
title: "Un-fade low-score answers on click/tap too",
url: "https://meta.stackexchange.com/q/261721",
credit: "based on fix by Manishearth",
script: function () {
$('#answers').on( 'click', '.answer.downvoted-answer .post-text', function () {
$(this).closest('.answer').addClass('downvoted-answer-clicked').removeClass('downvoted-answer');
} ).on( 'click', '.answer.downvoted-answer-clicked .post-text', function () {
$(this).closest('.answer').addClass('downvoted-answer').removeClass('downvoted-answer-clicked');
} );
}
};
fixes.mse66646 = {
title: "Confirming context menu entries via Enter triggers comment to be posted",
url: "https://meta.stackexchange.com/q/66646",
// TODO: Is this still reproducible on Firefox?
script: function () {
if ( !window.StackExchange || !StackExchange.helpers ) return;
// this function is copied from https://cdn-dev.sstatic.net/Js/stub.en.js, but with s/keyup/keydown/
// XXX: with this change, all the messing around with composition events should be unnecessary
StackExchange.helpers.submitFormOnEnterPress = function ($form) {
var $txt = $form.find('textarea');
var enterHeldDown = false;
$txt.keydown(function (event) {
if (event.which === 13 && !enterHeldDown) {
enterHeldDown = true;
if (!event.shiftKey && !$txt.prev("#tabcomplete > li:visible").length) $form.submit();
}
}).keyup(function (event) {
if (event.which === 13) enterHeldDown = false;
}).keypress(function (event) {
// disable hitting enter to produce a newline, but allow <shift> + <enter>
return event.which !== 13 || event.shiftKey;
});
};
}
};
fixes.mse210132 = {
title: "New top bar should render avatar with a transparent background",
url: "https://meta.stackexchange.com/q/210132",
script: function () {
$('.top-bar .my-profile .gravatar-wrapper-24 img.js-avatar-me[src*="//i.stack.imgur.com/"]').attr(
'src', function (i,v) { return v.replace( /\?.*$/, "" ) }
).css( { 'max-width': '24px', 'max-height': '24px' } );
}
};
fixes.mse220337 = {
title: "Election comments have no permalink link",
url: "https://meta.stackexchange.com/q/220337",
credit: "FEichinger",
path: /^\/election\b/,
script: function () {
var base = ( $('#tabs .youarehere').attr('href') || "" ).replace( /#.*/, "" );
SOUP.addContentFilter( function () {
var n = $('.comment-date').not(':has(a)').wrapInner( function () {
var id = $(this).closest('.comment').attr('id');
return $('<a class="comment-link"></a>').attr('href', base + '#' + id);
} ).length;
SOUP.log( 'mse220337: fixed ' + n + ' comments' );
}, 'mse220337 comment filter' );
// fix post links too, while we're at it
$('.post-menu a:contains("link")').attr( 'href', function (i, href) {
return href.replace( /^[^#]*/, base );
} );
}
};
fixes.mse172931 = {
title: "Please put answers underneath questions in Close review queue",
url: "https://meta.stackexchange.com/q/172931",
path: /^\/review\b/,
script: function () {
SOUP.hookAjax( /^\/review\/(next-task|task-reviewed)\b/, function () {
$('.reviewable-post').not(':has(.answer, .diffs)').each( function () {
var post = $(this), question = post.find('.question');
// initial check to see if there are any answers to load
var label = post.find('.reviewable-post-stats td.label-key:contains("answers")');
var count = label.first().next('td.label-value').text().trim();
var shown = $('.reviewable-answer').length; // XXX: don't needlessly reload sole answers in answer review
if ( count - shown < 1 ) return;
// find question URL
var url = post.find('h1 a.question-hyperlink').attr('href');
SOUP.log( 'soup loading ' + (count - shown) + ' missing answers from ' + url );
var injectAnswers = function ( html ) {
// new cleaner parsing!
var parser = new DOMParser();
var doc = parser.parseFromString( html, 'text/html' );
var rawAnswers = doc.querySelectorAll('.answer'); // XXX: don't use .getElementsByClassName(), loop below needs a static NodeList!
var answers = $('<div>'), n = 0;
for (var i = 0; i < rawAnswers.length; i++) {
if ( document.getElementById( rawAnswers[i].id ) ) continue;
answers[0].appendChild( rawAnswers[i] );
n++;
}
answers = answers.children();
SOUP.log( 'soup loaded ' + n + ' missing answers from ' + url );
// mangle the answer wrappers to look like the review page before injecting them
answers.find('.votecell button, .post-menu > *, .comments, .comments-link').remove();
answers.find('.votecell .js-vote-count').after( function () {
return '<div class="fs-caption fc-black-500 ta-center">vote' + ( this.textContent.trim() == 1 ? '' : 's' ) + '</div>';
} );
// inject answers into the review page
var header = $('<div id="answers-header"><div class="subheader answers-subheader"><h2></h2></div></div>');
header.find('h2').text( n + ( shown ? ' Other' : '') + ' Answer' + ( n == 1 ? '' : 's' ) );
header.insertAfter( question );
answers.insertAfter( header );
SOUP.runContentFilters( 'post', answers );
window.MathJax && MathJax.Hub.Queue(['Typeset', MathJax.Hub]);
};
$.ajax( { method: 'GET', url: url, dataType: 'html', success: injectAnswers } );
} );
} ).code();
}
};
fixes.mse224533 = {
title: "Soft-hyphen hides subsequent text when using Opera 12.16",
url: "https://meta.stackexchange.com/q/224533",
script: function () {
if ( SOUP.isMobile || ! window.opera ) return;
SOUP.addContentFilter( function (where) {
var preBlocks = $(where).find('pre:not(.soup-shy-fixed)').addClass('soup-shy-fixed');
SOUP.forEachTextNode( preBlocks, function ( text ) {
return text.replace( /\xAD/g, '' );
} );
}, 'Opera soft-hyphen fix' );
}
};
fixes.mse115702 = {
title: "Option to delete an answer only visible after a reload",
url: "https://meta.stackexchange.com/q/115702",
script: function () {
if ( ! window.StackExchange || ! StackExchange.options || ! StackExchange.options.user ) return;
if ( StackExchange.options.user.rep < ( SOUP.isBeta ? 4000 : 20000 ) ) return;
var html = '<a href="#" class="soup-delete-link" title="vote to delete this post">delete</a>';
var lsep = '<span class="lsep">|</span>';
function updateDeleteLinks( postid, score ) {
if ( /[^0-9]/.test(postid) ) {
return SOUP.log('SOUP mse115702 received invalid postid = "' + postid + '", aborting!');
}
var isAnswer = $('#answer-' + postid).length > 0;
if ( ! isAnswer ) return; // XXX: proper question handling requires detecting closed questions
var deleteLinks = $('[id="delete-post-' + postid + '"]'); // XXX: there might be several
if ( score >= (isAnswer ? 0 : -2) ) {
// XXX: just to be safe, don't remove any delete links that we didn't add
deleteLinks = deleteLinks.filter('.soup-delete-link');
deleteLinks.next('span.lsep').andSelf().hide();
} else if ( deleteLinks.length ) {
deleteLinks.next('span.lsep').andSelf().show(); // show existing links
} else {
// need to create a new delete link from scratch and slip it into the menu
var target = $('.flag-post-link[data-postid=' + postid + ']');
var lsep = target.prev('span.lsep').clone(true);
if (lsep.length == 0) lsep = $('<span class="lsep">|</span>');
$(html).attr('id', 'delete-post-' + postid).insertBefore(target).after(lsep);
}
}
SOUP.subscribeToQuestion( function (data) {
if ( data.a === 'score' ) updateDeleteLinks( data.id, data.score );
} );
// fallback to make this fix work in review too (TODO: hook the button clicks directly?)
SOUP.hookAjax( /^\/posts\/(\d+)\/vote\/[023]\b/, function ( event, xhr, settings, match ) {
var score = $.parseJSON( xhr.responseText ).NewScore;
var postid = match[1];
updateDeleteLinks( postid, score );
} );
}
};
fixes.mse231150 = {
title: "Clicking the top bar sometimes loads the SE homepage, sometimes shows the site switcher",
url: "https://meta.stackexchange.com/q/231150",
early: function () {
var buttonRegex = /(^|\s)js-(site-switcher|inbox|achievements|help)-button(\s|$)/;
document.addEventListener( 'click', function (event) {
if ( event.button != 0 ) return; // ignore right/middle clicks
var elem = event.target;
while ( elem && !buttonRegex.test(elem.className) ) elem = elem.parentNode;
if ( elem ) event.preventDefault();
}, false );
}
};
fixes.mse234680 = {
title: "Domain names in an URL are incorrectly encoded as escaped ASCII characters instead of punycode",
url: "https://meta.stackexchange.com/q/234680",
script: function () {
if ( !SOUP.punycode ) {
/*! https://mths.be/punycode v1.2.4 by @mathias */
// Copyright Mathias Bynens <https://mathiasbynens.be/>, distributed under the MIT license; see https://github.com/bestiejs/punycode.js/tree/1f0b9c4fc833e10728b13768396c702d66d641df/LICENSE-MIT.txt for full license text
!function(a){function b(a){throw RangeError(E[a])}function c(a,b){for(var c=a.length;c--;)a[c]=b(a[c]);return a}function d(a,b){return c(a.split(D),b).join(".")}function e(a){for(var b,c,d=[],e=0,f=a.length;f>e;)b=a.charCodeAt(e++),b>=55296&&56319>=b&&f>e?(c=a.charCodeAt(e++),56320==(64512&c)?d.push(((1023&b)<<10)+(1023&c)+65536):(d.push(b),e--)):d.push(b);return d}function f(a){return c(a,function(a){var b="";return a>65535&&(a-=65536,b+=H(a>>>10&1023|55296),a=56320|1023
&a),b+=H(a)}).join("")}function g(a){return 10>a-48?a-22:26>a-65?a-65:26>a-97?a-97:t}function h(a,b){return a+22+75*(26>a)-((0!=b)<<5)}function i(a,b,c){var d=0;for(a=c?G(a/x):a>>1,a+=G(a/b);a>F*v>>1;d+=t)a=G(a/F);return G(d+(F+1)*a/(a+w))}function j(a){var c,d,e,h,j,k,l,m,n,o,p=[],q=a.length,r=0,w=z,x=y;for(d=a.lastIndexOf(A),0>d&&(d=0),e=0;d>e;++e)a.charCodeAt(e)>=128&&b("not-basic"),p.push(a.charCodeAt(e));for(h=d>0?d+1:0;q>h;){for(j=r,k=1,l=t;h>=q&&b("invalid-input"),
m=g(a.charCodeAt(h++)),(m>=t||m>G((s-r)/k))&&b("overflow"),r+=m*k,n=x>=l?u:l>=x+v?v:l-x,!(n>m);l+=t)o=t-n,k>G(s/o)&&b("overflow"),k*=o;c=p.length+1,x=i(r-j,c,0==j),G(r/c)>s-w&&b("overflow"),w+=G(r/c),r%=c,p.splice(r++,0,w)}return f(p)}function k(a){var c,d,f,g,j,k,l,m,n,o,p,q,r,w,x,B=[];for(a=e(a),q=a.length,c=z,d=0,j=y,k=0;q>k;++k)p=a[k],128>p&&B.push(H(p));for(f=g=B.length,g&&B.push(A);q>f;){for(l=s,k=0;q>k;++k)p=a[k],p>=c&&l>p&&(l=p);for(r=f+1,l-c>G((s-d)/r)&&b(
"overflow"),d+=(l-c)*r,c=l,k=0;q>k;++k)if(p=a[k],c>p&&++d>s&&b("overflow"),p==c){for(m=d,n=t;o=j>=n?u:n>=j+v?v:n-j,!(o>m);n+=t)x=m-o,w=t-o,B.push(H(h(o+x%w,0))),m=G(x/w);B.push(H(h(m,0))),j=i(d,r,f==g),d=0,++f}++d,++c}return B.join("")}function l(a){return d(a,function(a){return B.test(a)?j(a.slice(4).toLowerCase()):a})}function m(a){return d(a,function(a){return C.test(a)?"xn--"+k(a):a})}var n="object"==typeof exports&&exports,o="object"==typeof module&&module&&module.
exports==n&&module,p="object"==typeof global&&global;(p.global===p||p.window===p)&&(a=p);var q,r,s=2147483647,t=36,u=1,v=26,w=38,x=700,y=72,z=128,A="-",B=/^xn--/,C=/[^ -~]/,D=/\x2E|\u3002|\uFF0E|\uFF61/g,E={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},F=t-u,G=Math.floor,H=String.fromCharCode;if(q={version:"1.2.4",ucs2:{decode:e,encode:f},decode:j,encode:k,toASCII:m,
toUnicode:l},"function"==typeof define&&"object"==typeof define.amd&&define.amd)define("punycode",function(){return q});else if(n&&!n.nodeType)if(o)o.exports=q;else for(r in q)q.hasOwnProperty(r)&&(n[r]=q[r]);else a.punycode=q}(SOUP);
}
var fixIDNLink = function (text) {
// The following two lines are copied from ui.prompt() in wmd.en.js:
text = text.replace(/^http:\/\/(https?|ftp):\/\//, '$1://');
if (!/^(?:https?|ftp):\/\//.test(text)) text = 'http://' + text;
// Separate URL and optional title, fix possibly broken % encoding in URL
// (based on properlyEncoded() from wmd.en.js, but simplified and debugged):
// XXX: this also fixes https://meta.stackexchange.com/q/285366
var m = /^\s*(.*?)(?:\s+"(.*)")?\s*$/.exec(text);
var url = m[1], title = m[2];
var normalized = url.replace(/%(?:[\da-fA-F]{2})|[^\w\d\-./[\]%?+]+/g, function (match) {
if (match.length === 3 && match.charAt(0) == "%") return match;
else return encodeURI(match);
} );
var link = document.createElement('a'); // work-around for cross-browser access to URLUtils
// On Chrome, link.hostname / link.href return Punycode host names, so
// just returning link.href would be enough; on Firefox, they return
// Unicode, so we need to use the punycode.js library to convert them.
// Either way, the following code should produce what we want:
link.href = normalized;
var host = SOUP.punycode.toASCII( link.hostname );
var fixed = link.href.replace( link.hostname, host );
if (url !== fixed) SOUP.log('soup mse234680 fixed ' + url + ' -> ' + normalized + ' -> ' + link.href + ' -> ' + fixed);
return typeof(title) === 'undefined' ? fixed : fixed + ' "' + title + '"';
};
SOUP.addEditorCallback( function (editor, postfix) {
// The insertLinkDialog hook takes a callback to insert the link into the
// post, and returns true/false. We want to modify the callback so that it
// punycode-encodes the hostname first. There is no HookCollection method
// to chain a new hook _before_ existing ones, but we can roll our own.
var originalHook = editor.hooks.insertLinkDialog;
if ( !originalHook ) return;
editor.hooks.insertLinkDialog = function (callback) {
return originalHook.call(this, function (text) {
return callback(fixIDNLink(text));
} );
};
} );
// also fix any links pasted into the textarea
SOUP.addPasteFilter( function (text) {
// AFAICT, [ "<>] are the only printable ASCII characters that no standard ever allows in URLs
return text.replace( /^(?:https?|ftp):\/\/[!#-;=?-~]*[^\0-\x9F][^\0- "<>\x7F-\x9F]*$/, fixIDNLink );
} );
// backup content filter for existing broken links with percent-encoded hostnames
SOUP.addContentFilter( function ( where ) {
var percentRegexp = /%[0-9A-Fa-f]{2}/;
$(where).find('a[href*="//"]').not('.soup-punycode-fixed').filter( function () {
if ( !percentRegexp.test( this.hostname ) ) return false;
this.hostname = decodeURIComponent( this.hostname );
return true;
} ).addClass('soup-punycode-fixed');
}, 'IDN escape fix' );
}
};
fixes.mse266852 = {
title: "Bar between “add a comment” and “show more comments” is inconsistent",
url: "https://meta.stackoverflow.com/q/266852",
credit: "based on script by Cameron Bernhardt (AstroCB)",
script: function () {
SOUP.addContentFilter( function () {
$('div[id^="comments-link-"] .js-link-separator:not(.lsep)').addClass('lsep').text('|');
}, 'mse266852', null, ['load', 'post'] );
},
// pure CSS fallback to minimize visibility changes on page load
css: 'div[id^="comments-link-"] .js-link-separator:not(.lsep) { visibility: hidden }'
};
fixes.mse240417 = {
title: "Should moderator diamonds be inside or outside the highlight box?",
url: "https://meta.stackoverflow.com/q/240417",
script: function () {
SOUP.addContentFilter( function () {
$('.comment-user > .mod-flair').each( function () { $(this).insertAfter(this.parentNode) } );
}, 'mse240417', null, ['load', 'post', 'comments'] );
}
};
fixes.mse243519 = {
title: "Dangling signature dash in comments",
url: "https://meta.stackoverflow.com/q/243519",
script: function () {
var wrapper = $('<div> <span style="white-space:nowrap">\u2013\xA0</span></div>').contents();
SOUP.addContentFilter( function () {
$('.comment-body > .comment-user').each( function () {
var prev = this.previousSibling;
if ( ! prev || prev.nodeType != 3 || ! /^[\xA0\s]*\u2013[\xA0\s]*$/.test(prev.nodeValue) ) return;
wrapper.clone().replaceAll(prev).append(this);
} );
}, 'mse243519', null, ['load', 'post', 'comments'] );
}
};
fixes.mse220611 = {
title: "Blue background on nominee comments only when expanded",
url: "https://meta.stackexchange.com/q/220611",
path: /^\/election\b/,
script: function () {
// XXX: This seems to only happen on the initial page view, so no need to make it a content filter.
$('body.election-page div[id^="post-"]').each( function () {
var $this = $(this), href = $this.find('.post-signature.owner .user-details > a:first').attr('href');
var match = /^\/users\/[0-9]+\//.exec( href );
if ( ! match ) return;
$this.find( '.comments .comment-user:not(.owner)[href^="' + match[0] + '"]').addClass('owner');
} );
}
};
fixes.mse121682 = {
title: "Links to election nominations don't work after nominations close",
url: "https://meta.stackexchange.com/q/121682",
script: function () {
var regex = /^(https?:)?(\/\/[^\/]+\/election\/\d+)#post-(\d+)$/, repl = '$2?tab=nomination#comment-$3';
// part A: if we've followed a broken link, fix it
if ( regex.test( location ) && $( location.hash ).length == 0 ) {
location.replace( location.toString().replace( regex, '$1' + repl ) );
}
// part B: fix inbox links directly
SOUP.hookAjax( /^\/topbar\/inbox\b/, function () {
$('.topbar-dialog.inbox-dialog .inbox-item a[href*="/election/"]').attr( 'href', function (i, href) {
return href.replace( regex, repl );
} );
} );
}
};
fixes.mse230536 = {
title: "Large down-vote count doesn't display negative sign",
url: "https://meta.stackexchange.com/q/230536",
script: function () {
SOUP.hookAjax( /^\/posts\/\d+\/vote-counts\b/, function () {
// XXX: the downvote element has no class, hence the silly selector
$('.js-vote-count > .vote-count-separator + div[style*="maroon"]').each( function () {
if ( $(this).children().length > 0 ) return;
this.textContent = this.textContent.replace( /^(\s*)([1-9])/, '$1-$2' );
} );
} );
}
};
fixes.mse248646 = {
title: "Comments left by the author of a spam/offensive post should be deleted from the post too",
url: "https://meta.stackexchange.com/q/248646",
css: "body:not(.soup-mse248646-fixed) .deleted-answer .comment { display: none }",
script: function () {
$('.deleted-answer').has('.hidden-deleted-answer').each( function () {
var $this = $(this), comments = $(this).find('.comment').hide();
if ( comments.length == 0 ) return;
var ui = StackExchange.comments.uiForPost($this);
var count = ui.remainingCommentsCount() + comments.length;
ui.setCommentsMenu(count);
ui.remainingCommentsCount(count);
} );
$(document.body).addClass('soup-mse248646-fixed');
}
};
fixes.mso284223 = {
title: "Newly upvoted cool comments get an uncolored score",
url: "https://meta.stackoverflow.com/q/284223",
credit: "thanks to tbodt for locating the bug",
script: function () {
var regex = /^\/posts\/comments\/(\d+)\/vote\/[02]\b/;
SOUP.hookAjax( regex, function ( event, xhr, settings, match ) {
$('#comment-' + match[1] + ' .comment-score span').each( function () {
if ( ! this.className ) this.className = 'cool';
} );
} );
}
};
fixes.mso297489 = {
title: "Add close option to the “Help and Improvement” queue to avoid cluttering flags?",
url: "https://meta.stackoverflow.com/q/297489",
path: /^\/review\/helper\b/,
script: function () {
SOUP.hookAjax( /^\/review\/(next-task|task-reviewed)\b/, function () {
StackExchange.vote_closingAndFlagging.init();
$('.post-menu .close-question-link').show();
} );
}
};
if (false) fixes.mso300679 = {
// temporarily disabled per https://github.com/vyznev/soup/issues/47
title: "Please block posts containing unsupported HTML",
url: "https://meta.stackoverflow.com/q/300679",
script: function () {
var message = 'Your post appears to contain HTML tags that are malformed, mismatched or <a href="/editing-help#html">not permitted in posts</a>, and which will be silently removed. Where possible, please use Markdown syntax instead of HTML. To enter code that contains the <tt><</tt> symbol, please use <a href="/editing-help#code">proper code formatting</a> (or write it as <tt>&lt;</tt>).';
var soupPreSanitize = function ( tag ) {
// kluge: replace <a> / <img> URLs so that sanitizeHtml() won't try to %-escape them
tag = tag.replace( /^(<a\shref="|<img\ssrc=")([^"]*)/i, '$1http://example.com/' );
// also replace comments, since we don't care if those get stripped
tag = tag.replace( /^<!(--(?:|(?:[^>-]|-[^>])(?:[^-]|-[^-])*)--)>$/, '' );
return tag;
}
SOUP.addEditorCallback( function (editor, postfix) {
if ( /[^0-9A-Za-z\-_]/.test(postfix) ) {
return SOUP.log('SOUP mso300679 received invalid postfix = "' + postfix + '", aborting!');
}
var $body = $('#wmd-input' + postfix), $popup;
var options = StackExchange.postValidation.getSidebarPopupOptions();
options.type = 'warning';
var isOK = true, timer = false, showPopup = function () {
if ( !isOK && !$popup ) $popup = StackExchange.helpers.showMessage( $body, message, options );
if ( timer !== false ) clearTimeout( timer );
timer = false;
};
$body.on( 'blur', showPopup );
editor.getConverter().hooks.chain( 'preSafe', function ( html ) { try {
if ( timer !== false ) clearTimeout( timer );
timer = false;
var stripped = html.replace( /<[^>]*>?/g, soupPreSanitize );
var sanitized = StackExchange.MarkdownEditor.sanitizeHtml( stripped );
var balanced = StackExchange.MarkdownEditor.balanceTags( sanitized );
isOK = ( balanced === stripped );
if ( isOK && $popup ) {
$popup.fadeOutAndRemove();
$popup = null;
} else if ( !isOK && !$popup ) {
timer = setTimeout( function () { timer = false; showPopup() }, 3000 );
}
return html;
} catch (e) { SOUP.log('mso300679 hook:', e) } } );
} );
}
};
fixes.mse266034 = {
title: "Link the title of the linked questions sidebar to the list of linked questions",
url: "https://meta.stackexchange.com/q/266034",
path: /^\/questions\/(\d+)\b/,
script: function () {
var m = /^\/questions\/(\d+)\b/.exec( location.pathname );
$('#h-linked').not(':has(a)').wrapInner('<a href="/questions/linked/' + m[1] + '"></a>');
},
css: "#h-linked a, #h-linked a:visited { color: inherit; font-size: 100%; font-family: inherit; font-weight: inherit; line-height: inherit; display: inline }"
};
fixes.mse265889 = {
title: "Improve answer navigation for screen readers",
url: "https://meta.stackexchange.com/q/265889",
credit: "based on script by rene: https://meta.stackexchange.com/a/266236",
script: function () {
var updateAnswerHeadings = function (where) {
$(where).filter('.answer').add( $('.answer', where) ).each( function () {
var answer = $(this);
var isDeleted = answer.hasClass('deleted-answer');
var signature = answer.find('.post-signature').eq(-1);
var isWiki = signature.find('.community-wiki').length > 0;
var author = signature.find('.user-details');
if ( author.find('a').length > 0 ) author = author.find('a[href^="/users/"]');
var voteCount = answer.find('.vote-count-post');
var score = Number( voteCount.text() );
if ( voteCount.find('.vote-count-separator').length > 0 ) {
var divs = voteCount.find('div'), up = divs.eq(0), down = divs.eq(-1);
score = Math.abs( up.text() ) - Math.abs( down.text() );
}
var isAccepted = answer.find('.vote-accepted-on').length > 0;
var attrs = [ 'score ' + score ];
if ( isAccepted ) attrs.push('accepted');
if ( isWiki ) attrs.push('community wiki');
var text = ( isDeleted ? 'Deleted answer' : 'Answer' );
text += ' (' + attrs.join(', ') + ')';
if ( author.length > 0 ) text += ' by ' + author.text().trim();
var heading = answer.find('.soup-answer-heading');
if ( heading.length < 1 ) heading = $('<h6 class="soup-answer-heading">');
heading.text(text).prependTo(answer.find('.answercell'));
} );
};
SOUP.addContentFilter( updateAnswerHeadings, 'mse265889', null, ['load', 'post'] );
SOUP.subscribeToQuestion( function (data) {
if ( /^(score|(un)?accept)$/.test( data.a ) ) setTimeout( function () {
updateAnswerHeadings( '#answer-' + (data.answerid || data.id) );
}, 10 );
} );
},
// http://webaim.org/techniques/css/invisiblecontent/
css: ".soup-answer-heading { overflow: hidden; height: 1px; width: 1px; position: absolute; left: -9999px }"
};
fixes.mse266523 = {
title: "Uploading an image from the web can leave paste broken in editor",
url: "https://meta.stackexchange.com/q/266523",
// TODO: Is this still reproducible?
script: function () {
$('#content').on('paste', function () {
if ( $('.modal-dropzone').length > 0 ) return;
SOUP.getEventHandlers( document.body, 'paste' ).forEach( function ( h ) {
if ( ! /\.modal-dropzone/.test( h.handler.toString() ) ) return;
$('body').off( 'paste', h.handler );
} );
} );
}
};
fixes.mse264307 = {
title: "Down arrow key won't work after using the Hyperlink button",
url: "https://meta.stackexchange.com/q/264307",
// TODO: Is this still reproducible on Firefox?
script: function () {
var proto = document.body;
while ( proto && proto.removeChild && !proto.hasOwnProperty('removeChild') ) {
proto = Object.getPrototypeOf( proto );
}
if ( !proto || !proto.removeChild ) return;
var oldRemoveChild = proto.removeChild;
proto.removeChild = function ( removed ) {
var active = document.activeElement, node = active;
while ( node && node !== removed ) node = node.parentNode;
if ( node ) active.blur();
return oldRemoveChild.apply( this, arguments );
};
}
};
fixes.mse153528 = {
title: "Don't ask for a comment when downvoting, if the user just voted on a comment",
url: "https://meta.stackexchange.com/q/153528",
script: function () {
if ( ! window.StackExchange ) return;
// TODO: add localized message variants?
var message = "Please consider adding a comment if you think this post can be improved.";
SOUP.hookAjax( /^\/posts\/(\d+)\/vote\/3$/, function ( event, xhr, settings, match ) {
var postid = match[1], data = $.parseJSON( xhr.responseText );
if ( data.Success && data.Message === message && $('#comments-' + postid + ' .comment-up-on').length > 0 ) {
$('.js-toast').filter( function () {
return this.textContent.trim() === message;
} ).remove();
}
} );
}
};
fixes.mse259325 = {
title: "Answer flashes orange when I click the “edit (1)” link to review a suggested edit",
url: "https://meta.stackexchange.com/q/259325",
script: function () {
// the initial hashchange event has already fired, so we can safely ignore any later
// events that don't correspond to an actual change in the hash
var oldHash = location.hash;
SOUP.getEventHandlers( window, 'hashchange' ).forEach( function (h) {
if ( ! h.namespace || h.namespace !== 'highlightDestination' ) return;
var oldHandler = h.handler;
h.handler = function (e) {
if ( oldHash === location.hash ) return;
oldHash = location.hash;
return oldHandler.apply( this, arguments );
};
} );
}
};
fixes.mse268584 = {
title: "When a user is deleted, OP highlighting is lost",
url: "https://meta.stackexchange.com/q/268584",
script: function () {
SOUP.addContentFilter( function () {
// XXX: in dupe review, there can be multiple questions on the page
$('.mainbar, #mainbar').each( function () {
var name = $(this).find('.question .post-signature.owner .user-details').not(':has(a)').text().trim();
if ( name === "" ) return;
$(this).find('span.comment-user:not(.owner)').filter( function () {
return this.textContent === name;
} ).addClass('owner');
} );
}, 'mse268584', null, ['load', 'post', 'comments'] );
},
css: "span.comment-user.owner { padding: 1px 5px }"
};