forked from Shog9/flagtools
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MonicasFlagToC.user.js
2226 lines (2012 loc) · 98.5 KB
/
MonicasFlagToC.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 Monica's Flag ToC
// @namespace https://github.com/codygray/flagtools/
// @description Implement https://meta.stackexchange.com/questions/305984/suggestions-for-improving-the-moderator-flag-overlay-view/305987#305987
// @author Cody Gray
// @author Shog9
// @version 2.0.0
// @homepageURL https://github.com/codygray/flagtools
// @updateURL https://github.com/codygray/flagtools/raw/codygray-updates/MonicasFlagToC.user.js
// @downloadURL https://github.com/codygray/flagtools/raw/codygray-updates/MonicasFlagToC.user.js
// @supportURL https://github.com/codygray/flagtools/issues
//
// @match *://*.stackoverflow.com/questions/*
// @match *://*.stackoverflow.com/staging-ground/*
// @match *://*.stackexchange.com/questions/*
// @match *://*.superuser.com/questions/*
// @match *://*.serverfault.com/questions/*
// @match *://*.askubuntu.com/questions/*
// @match *://*.mathoverflow.net/questions/*
// @match *://local.mse.com/questions/*
// ==/UserScript==
/* eslint-disable no-multi-spaces */
/* global $:readonly */ // SO/SE sites always provides jQuery, free-of-charge
/* global StackExchange:readonly */ // this global object always exists on SO/SE domains
(function()
{
'use strict';
// User-configurable options:
const makeFlagInfoStickyAndFloatAbovePost = ((localStorage.getItem("flaaaaags.sticky" ) ?? 'true' ) === 'true');
const showWaffleBarTOC = ((localStorage.getItem("flaaaaags.toc" ) ?? 'false') === 'true');
const makeWaffleBarTOCVertical = ((localStorage.getItem("flaaaaags.vertical") ?? 'false') === 'true');
// Registered on Stack Apps in order to obtain an API key.
// Client ID is 18434 (https://stackapps.com/apps/oauth/view/18434)
const API_KEY = 'YVKZM9)1ozBP8NH)hlPj8Q((';
// Check that this is a Stack Exchange site, and that the user is a moderator.
if (typeof StackExchange === "undefined" || !StackExchange.options || !StackExchange.options.user || !StackExchange.options.user.isModerator)
{
return;
}
window.FlagFilter = window.FlagFilter || {};
initStyles();
initTools();
initQuestionPage();
function initStyles()
{
let flagStyles = document.createElement("style");
flagStyles.textContent = `
/*
General (Variables)
*/
body > .container
{
/* NOTE: Currently, the set of orange colors is forced here. This works well for SO and MSO, but
may not fit in well with the theme of other SE sites. But, I'm not a mod on any other
sites, so I don't have an easy way to verify that, nor do I have a compelling reason
to care about it (assuming no one complains). A potentially better alternative would be
to use the "--theme-primary-custom-NNN" variables, which reflect the site's color theme.
However, this is gray/black on MSO, which is a poor choice. Worse, this set of variables
is not responsive to dark mode, for reasons that I don't currently understand.
Thus, forcing orange seems better than being broken in dark mode and ugly on MSO.
But, custom variables are defined and used here so that this can be easily experimented
with and changed in the future.
NOTE: The "--theme-primary-custom-NNN" variables on SO produce colors that are *almost* the same
(though not exactly) as the orange theme. The main difference is "--theme-primary-custom-100",
which is darker than "--orange-100", so, for this, a custom "--theme-primary-custom-050" color
variable must be defined.
*/
/*
--theme-primary-custom-050: hsl( var(--theme-base-primary-color-h),
var(--theme-base-primary-color-s),
calc(var(--theme-base-primary-color-l)
+ ((100% - var(--theme-base-primary-color-l)) * .95)));
*/
--mod-tools-color-100: var(--orange-100); /* alt: var(--theme-primary-custom-050) */
--mod-tools-color-200: var(--orange-200); /* alt: var(--theme-primary-custom-200) */
--mod-tools-color-300: var(--orange-300); /* alt: var(--theme-primary-custom-300) */
--mod-tools-color-400: var(--orange-400); /* alt: var(--theme-primary-custom-400) */
--mod-tools-color-500: var(--orange-500); /* alt: var(--theme-primary-custom-500) */
--mod-tools-color-600: var(--orange-600); /* alt: var(--theme-primary-custom-600) */
}
/*
Waffle Bar
*/
.js-post-flag-bar
{
display: none !important;
background-color: var(--mod-tools-color-100) !important;
border-color: var(--mod-tools-color-200) !important;
}
.js-post-flag-bar.visible
{
display: flex !important;
}
.js-post-flag-bar > button
{
position: static !important;
align-self: center;
margin: 4px 4px 4px 0;
padding: 8px;
}
.js-post-flag-bar > a.s-btn,
.js-post-flag-bar > div.d-flex > a.s-btn
{
background-color: var(--mod-tools-color-200);
border-color: var(--mod-tools-color-200);
}
.js-post-flag-bar > a.s-btn:hover , .js-post-flag-bar > div.d-flex > a.s-btn:hover , .js-post-flag-bar > button:hover,
.js-post-flag-bar > a.s-btn:active, .js-post-flag-bar > div.d-flex > a.s-btn:active, .js-post-flag-bar > button:active
{
background-color: var(--mod-tools-color-300) !important;
border-color: var(--mod-tools-color-400) !important;
}
.js-post-flag-bar .flag-summary .note
{
display: flex;
justify-content: center;
align-items: center;
margin: 8px;
}
.flagToC
{
list-style-type: none;
margin: 0;
padding: 0;
align-self: start;
}
.flagToC > li
{
display: inline-block;
width: 32%;
min-width: 15em;
max-width: fit-content;
margin: 4px;
padding: 4px;
background-color: var(--white);
border: var(--su-static1) solid var(--mod-tools-color-200);
border-radius: var(--br-sm);
box-shadow: var(--bs-sm);
}
.flagToC > li ul
{
margin: 0;
padding: 0;
}
.flagToC > li ul > li::before
{
content: attr(data-count);
padding-right: 2px;
color: var(--fc-light);
}
.flagToC > li ul > li
{
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.flagToC > li ul > li.inactive,
.flagToC > li ul > li.inactive a
{
opacity: 0.7;
}
${makeWaffleBarTOCVertical ? `
.js-post-flag-bar
{
flex-direction: column;
width: 200px;
height: calc(100% - var(--top-bar-allocated-space));
border-right: 1px solid var(--mod-tools-color-200);
}
.js-post-flag-bar > button
{
align-self: end;
margin: 0;
}
.js-post-flag-bar > button:hover,
.js-post-flag-bar > button:active
{
background-color: var(--mod-tools-color-200) !important;
border-color: var(--mod-tools-color-300) !important;
}
.js-post-flag-bar > div.d-flex > a.s-btn
{
width: 40%;
margin: 0 4px 4px 4px;
justify-content: center;
}
.js-post-flag-bar > div.d-flex > a.s-btn:last-of-type
{
flex-direction: row-reverse;
}
.js-post-flag-bar .flag-summary
{
overflow-x: clip;
overflow-y: auto;
}
.flagToC > li
{
display: block;
width: auto;
min-width: auto;
max-width: none;
}
` : ``}
/*
Post/Comment Flag Info Box
*/
.mod-tools.mod-tools-post,
.mod-tools.mod-tools-comment-header
{
background-color: var(--mod-tools-color-100);
}
.mod-tools.mod-tools-post
{
display: flex;
flex-direction: column;
grid-column: 1 / span 2;
margin-bottom: 15px;
padding: 10px 12px;
${makeFlagInfoStickyAndFloatAbovePost ? `
position: sticky;
z-index: var(--zi-banners);
top: var(--top-bar-allocated-space);
` : `` }
}
.mod-tools.mod-tools-comment-header
{
padding: 10px 12px;
margin-top: -1px;
}
body.staging-ground .mod-tools.mod-tools-comment-header
{
margin-top: -8px;
margin-bottom: 8px;
}
.mod-tools.mod-tools-post,
.mod-tools.mod-tools-comment-header
{
border: 1px solid var(--mod-tools-color-200);
${makeFlagInfoStickyAndFloatAbovePost ? `` : `
box-shadow: none !important;
`}
}
.mod-tools.mod-tools-post.active-flag,
.mod-tools.mod-tools-comment-header.active-flag
{
border: 1px solid var(--mod-tools-color-400);
box-shadow:
${makeFlagInfoStickyAndFloatAbovePost ? `
var(--bs-md),
0 0 6px var(--mod-tools-color-400) !important
` : `
none !important
`}
;
}
.mod-tools .mod-tools-comment > :first-child
{
border-left: 8px solid var(--mod-tools-color-200);
}
.mod-tools .mod-tools-comment.active-flag > :first-child
{
border-left: 8px solid var(--mod-tools-color-400);
}
body.staging-ground .mod-tools .mod-tools-comment > :first-child
{
width: calc(var(--su-static16) * 2) !important;
margin-left: calc(var(--su-static16) * -1);
padding-left: calc(var(--su-static16) / 2);
}
body:not(.staging-ground) .mod-tools.mod-tools-comment-header,
body:not(.staging-ground) .mod-tools .mod-tools-comment > :first-child
{
/* compensate for border line */
margin-left: -8px;
}
.mod-tools .flag-summary .show-all-flags span.light
{
opacity: 0.5;
}
.mod-tools .flag-summary .show-all-flags svg
{
vertical-align: text-top;
margin-top: 2px;
margin-right: 4px;
}
.mod-tools.mod-tools-post > h3,
.mod-tools.mod-tools-comment-header > h3
{
margin: 0;
color: var(--mod-tools-color-600);
}
.mod-tools.mod-tools-post > h3 + button.s-popover--close
{
margin: 0;
padding: 8px;
border-radius: var(--br-sm);
color: var(--_bu-filled-fc);
display: none;
}
.mod-tools.mod-tools-post > h3 + button.s-popover--close:hover,
.mod-tools.mod-tools-post > h3 + button.s-popover--close:active,
.mod-tools.mod-tools-post > h3 + button.s-popover--close:focus
{
background-color: var(--mod-tools-color-200) !important;
border-color: var(--mod-tools-color-200) !important;
}
.mod-tools-comment .flag-text.revision-comment
{
background-color: var(--mod-tools-color-100);
padding: 2px 0 !important;
}
.mod-tools-comment.deleted-comment .flag-text.revision-comment,
.mod-tools.mod-tools-post .revision-comment
{
background-color: var(--mod-tools-color-200);
}
.mod-tools.mod-tools-post .active-flag .revision-comment
{
font-weight: 600;
}
.mod-tools.mod-tools-post .dismiss-flag-popup-buttons
{
float: right;
margin-left: 9px;
}
.mod-tools.mod-tools-post .dismiss-flag-popup-buttons .flag-dismiss-helpful,
.mod-tools.mod-tools-post .dismiss-flag-popup-buttons .flag-dismiss-decline
{
color: var(--_bu-fc);
}
.mod-tools.mod-tools-post .dismiss-flag-popup-buttons .flag-dismiss-helpful:hover,
.mod-tools.mod-tools-post .dismiss-flag-popup-buttons .flag-dismiss-decline:hover
{
color: var(--_bu-fc-hover);
}
.mod-tools ul.flags, .mod-tools ul.reviews
{
margin: 0 0 0 10px;
padding: 0;
overflow: auto;
}
.mod-tools ul.flags:not(:empty)
{
margin: 6px 0 0 10px;
${makeFlagInfoStickyAndFloatAbovePost ? `
min-height: 2em;
max-height: 40vh;
` : ``}
}
${makeFlagInfoStickyAndFloatAbovePost ? `
.mod-tools ul.flags:not(:empty).expanded
{
max-height: unset;
}
` : ``}
.mod-tools ul.flags > li
{
margin: 10px 0 10px 10px;
list-style: none;
}
.mod-tools ul.flags > li:first-child
{
margin-top: 0;
}
.mod-tools ul.flags > li:last-child
{
margin-bottom: 0;
}
.mod-tools ul.flags > li:before,
.mod-tools ul.flags > li:after
{
content: ' ';
display: table;
}
.mod-tools ul.flags > li:after
{
clear: both;
}
.mod-tools .flag-outcome
{
margin-left: 20px;
}
.comment .flag-dismiss-comment
{
grid-column: 1 / span 2;
padding-left: 2px;
text-align: center;
color: var(--mod-tools-color-500);
}
.comment .flag-dismiss-comment:hover
{
color: var(--mod-tools-color-600);
}
.mod-tools ul.flags .flag-info
{
/* white-space: nowrap; */
}
.mod-tools .dismiss-flags-popup
{
margin: 6px 0 0 0;
padding: 0;
clear: both;
display: none;
}
.mod-tools .dismiss-flags-popup form
{
display: grid;
}
.mod-tools .dismiss-flags-popup button,
.mod-tools .dismiss-flags-popup .-input
{
margin: 2px 0;
}
.mod-tools .dismiss-flags-popup button
{
font-size: 93%;
padding: 6px;
}
.mod-tools .dismiss-flags-popup div.-btn
{
float: right;
margin-right: 1px;
}
.mod-tools .dismiss-flags-popup button[type="submit"]
{
padding-left: 14px;
padding-right: 14px;
}
.mod-tools .dismiss-flags-popup .mark-flag-declined.-btn
{
color: var(--_bu-fc-selected);
}
.mod-tools .dismiss-flags-popup form>button.g-col
{
text-align: left;
}
.mod-actions
{
margin: 0 -4px;
}
.mod-actions:not(:empty)
{
margin-top: 10px;
}
.mod-actions:before,
.mod-actions:after
{
content: ' ';
display: table;
}
.mod-actions:after
{
clear: both;
}
.mod-actions button
{
margin: 0 3px;
float: right;
}
.mod-actions .flag-delete-plagiarism,
.mod-actions .flag-dispute-spam,
.mod-actions .migrate-btn
{
float: left;
}
.mod-actions .migrate-btn img
{
margin: -6px 2px -6px -3px;
padding: 0;
}
.mod-tools ul.flags .flag-info .flag-creation-user
{
white-space: nowrap;
}
/*
Deleted Answers:
*/
.question-page #answers .answer.deleted-answer
{
/* Match .deleted-answer { border-top } */
border-bottom: 1px solid var(--red-300);
}
/*
Comment Delete Links
(put them in a consistent place):
*/
.comment, .comment .flags
{
clear: both;
}
.comment .js-comment-delete
{
float: right;
margin: 0;
padding: 0;
}
.comment .js-comment-delete span
{
visibility: visible;
margin: 0;
padding: 0;
}
@supports (display: grid) and (not (display: contents) )
{
ul.comments-list .active-flag .comment-actions
{
width: 54px;
}
}
/*
Staging Ground Comment Tools
(make them always visible):
*/
body.staging-ground .comment-body .hover-only-label
{
visibility: visible !important;
}
/* TODO: Insert "Delete" link inline, instead of leaving it buried in a drop-down menu.
`;
document.head.appendChild(flagStyles);
}
// Generally-useful moderation routines
function initTools()
{
window.FlagFilter.tools = $.extend({}, window.FlagFilter.tools,
{
// hate safari
parseISODate: function(isoDate, def)
{
const parsed = Date.parse((isoDate||'').replace(' ','T'));
return parsed ? new Date(parsed) : def;
},
formatDate: function(date)
{
if (!date.getTime()) { return "(??)"; }
// mostly stolen from SE.com
const delta = (((new Date()).getTime() - date.getTime()) / 1000);
if (delta < 2) { return 'just now'; }
if (delta < 60) { return Math.floor(delta) + ' secs ago'; }
if (delta < 120) { return '1 min ago'; }
if (delta < 3600) { return Math.floor(delta / 60) + ' mins ago'; }
if (delta < 7200) { return '1 hour ago'; }
if (delta < 86400) { return Math.floor(delta / 3600) + ' hours ago'; }
if (delta < 172800) { return 'yesterday'; }
if (delta < 259200) { return '2 days ago'; }
return date.toLocaleString(undefined, {month: "short", timeZone: "UTC"})
+ ' ' + date.toLocaleString(undefined, {day: "2-digit", timeZone: "UTC"})
+ ((delta > 31536000) ? ' \'' + date.toLocaleString(undefined, {year: "2-digit", timeZone: "UTC"}) : '')
+ ' at '
+ date.toLocaleString(undefined, {minute: "2-digit", hour: "2-digit", hour12: false, timeZone: "UTC"});
},
formatISODate: function(date)
{
return date.toJSON().replace(/\.\d+Z/, 'Z');
},
getTicks: function()
{
return StackExchange.moderator.renderTimeTicks || (Date.now() * 10000 + 621355968000000000);
},
hitEndpoint: function(reloadOnSuccess, url, params = { fkey: StackExchange.options.user.fkey })
{
$.post(url, params)
.fail(function(err) { alert(`Failed to hit a Stack Exchange HTTP endpoint:\n${err}`); })
.done(function(data)
{
if (data && data.success) { if (reloadOnSuccess) { location.reload(true); } }
else { alert(data?.message || "A Stack Exchange HTTP endpoint failed without any error information."); }
});
},
voteOnPost: function(postId, voteId)
{
window.FlagFilter.tools.hitEndpoint(false, `/posts/${postId}/vote/${voteId}`);
},
downvotePost: function(postId) { window.FlagFilter.tools.voteOnPost(postId, 3); },
deletePost : function(postId) { window.FlagFilter.tools.voteOnPost(postId, 10); },
undeletePost: function(postId) { window.FlagFilter.tools.voteOnPost(postId, 11); },
disputeSpamAbusiveFlags: function(postId)
{
window.FlagFilter.tools.hitEndpoint(true, `/admin/posts/${postId}/clear-offensive-spam-flags`);
},
deleteAsPlagiarism: function(postId)
{
window.FlagFilter.tools.hitEndpoint(true, `/admin/posts/${postId}/delete-as-plagiarism`);
},
moveCommentsToChat: function(postId)
{
window.FlagFilter.tools.hitEndpoint(false, `/admin/posts/${postId}/move-comments-to-chat`);
},
annotateUser: function(userId, annotation)
{
window.FlagFilter.tools.hitEndpoint(false, `/admin/users/${userId}/annotate`,
{
'fkey' : StackExchange.options.user.fkey,
'mod-actions': 'annotate',
'annotation' : annotation,
});
},
reviewBanUser: function(userId, days, explanation)
{
const params = {
'fkey' : StackExchange.options.user.fkey,
'userId' : userId,
'reviewBanDays': days,
};
if (explanation)
{
params.explanation = explanation;
}
window.FlagFilter.tools.hitEndpoint(false, '/admin/review/ban-user', params);
},
dismissFlag: function(postId, flagIds, helpful, declineId, comment)
{
const ticks = window.FlagFilter.tools.getTicks();
return $.post(`/messages/delete-moderator-messages/${postId}/${ticks}?valid=${helpful}&flagIdsSemiColonDelimited=${flagIds.join ? flagIds.join(';') : flagIds}`,
{ fkey: StackExchange.options.user.fkey,
comment: comment || declineId || '',
});
},
dismissAllFlags: function(postId, helpful, declineId, comment)
{
const ticks = window.FlagFilter.tools.getTicks();
return $.post(`/messages/delete-moderator-messages/${postId}/${ticks}?valid=${helpful}`,
{ fkey: StackExchange.options.user.fkey,
comment: comment || declineId || '',
});
},
dismissAllCommentFlags: function(commentId, flagIds)
{
// Shog sez: "although the UI implies it's possible, we can't currently dismiss individual comment flags"
return $.post(`/admin/comment/${commentId}/clear-flags`,
{ fkey: StackExchange.options.user.fkey });
},
reopenQuestion: function(postId)
{
if ((typeof postId === 'undefined') || (postId === null))
{
return;
}
else
{
return $.post(`/flags/questions/${postId}/reopen/add`,
{ fkey: StackExchange.options.user.fkey });
}
},
// closeReasonId: 'SiteSpecific', 'NeedMoreFocus', 'NeedsDetailsOrClarity', 'OpinionBased', 'Duplicate'
// if closeReasonId is 'SiteSpecific', offtopicReasonId : 11-norepro, 13-nomcve, 16-toolrec, 3-custom/other, 2-migrate
closeQuestion: function(postId,
closeReasonId,
offTopicReasonId,
duplicateOfQuestionId = null,
belongsOnBaseHostAddress = null,
offTopicOtherText = 'I’m voting to close this question because ')
{
if (typeof postId === 'undefined' || postId === null) return;
if (typeof closeReasonId === 'undefined' || closeReasonId === null) return;
if (closeReasonId === 'SiteSpecific' && (typeof offTopicReasonId === 'undefined' || offTopicReasonId === null)) return;
if (closeReasonId === 'Duplicate')
{
if (duplicateOfQuestionId === null)
{
return;
}
offTopicReasonId = null;
}
if (closeReasonId === 'SiteSpecific' && offTopicReasonId === 2)
{
if (belongsOnBaseHostAddress === null)
{
return;
}
}
if (offTopicOtherText === null)
{
offTopicOtherText = 'I’m voting to close this question because ';
}
return $.post(
{
url: `/flags/questions/${postId}/close/add`,
data:
{
'fkey': StackExchange.options.user.fkey,
'closeReasonId': closeReasonId,
'duplicateOfQuestionId': duplicateOfQuestionId,
'siteSpecificCloseReasonId': offTopicReasonId,
'siteSpecificOtherText': offTopicOtherText,
//'siteSpecificOtherCommentId': '',
'originalSiteSpecificOtherText': 'I’m voting to close this question because ',
'belongsOnBaseHostAddress': belongsOnBaseHostAddress,
}
});
},
migrateTo: function(postId, destinationHost)
{
return window.FlagFilter.tools.closeQuestion(postId, 'SiteSpecific', 2, null, destinationHost);
},
/*
makeWait: function(msecs)
{
return function()
{
const args = arguments;
const result = $.Deferred();
setTimeout(function() { result.resolve.apply(result, args) }, msecs);
return result.promise();
}
},
*/
flagHelpfulUI: function(uiParent, isQuestion)
{
const result = $.Deferred();
let helpfulForm = uiParent.nextAll(".dismiss-flags-popup.dismiss-flags-popup-helpful");
if (!helpfulForm.length)
{
helpfulForm = $(`
<div class="dismiss-flags-popup dismiss-flags-popup-helpful">
<form class="g-column _gutters" style="width: 100%;">
<label class="f-label">Mark flag(s) as helpful because…</label>
<div class="g-col g-row _gutters">
<div class="g-col -input" style="width: 100%;">
<textarea maxlength="200" placeholder="optional feedback (visible to the user)" class="s-input s-input__sm s-textarea__sm"></textarea>
</div>
<span class="text-counter cool">Enter nothing at all, or up to 200 characters of cheerful guidance</span>
<div class="g-col -btn">
<button class="s-btn s-btn__filled s-btn__primary mark-flag-helpful" type="submit">Submit</button>
</div>
</div>
</form>
</div>
`).insertAfter(uiParent);
const handleSubmitHelpful = (ev) =>
{
ev.preventDefault();
const container = helpfulForm.closest(".mod-tools-post");
container.find("h3 + button.s-popover--close").fadeOut();
container.find("ul.flags").removeClass("expanded");
helpfulForm.remove();
result.resolve(
{
helpful: true,
declineId: 0,
comment: helpfulForm.find("textarea").val()
});
}
helpfulForm.find("textarea")
.charCounter({min: 0, max: 200, target: helpfulForm.find(".text-counter")})
.on("keydown", function(ev)
{
// Make <Enter> key presses submit the form, not insert a new line.
// <Shift>+<Enter> still inserts a new line, not that it's useful to do so.
if ((ev.which === 13) && !ev.shiftKey)
{
handleSubmitHelpful(ev);
}
// Make <Esc> key presses clear the textarea and hide the dismissal controls.
if (ev.which === 27)
{
helpfulForm.closest(".mod-tools-post").find("h3 + button.s-popover--close").click();
this.value = "";
}
});
helpfulForm.find(".mark-flag-helpful").click(handleSubmitHelpful);
}
const container = uiParent.closest(".mod-tools-post");
container.find(".dismiss-flags-popup").not(helpfulForm).slideUp(250);
container.find("h3 + button.s-popover--close").fadeIn();
container.find("ul.flags").addClass("expanded");
helpfulForm.slideDown(250)
.find("button,input").first().focus();
return result.promise();
},
flagDeclineUI: function(uiParent, isQuestion, flag)
{
const reasons =
{
technicalwrong:
{
id: 1,
text: "Flags should not be used to indicate technical inaccuracies, or an altogether wrong answer. You should downvote such answers.",
prompt: "flags should not be used to indicate technical inaccuracies, or an altogether <b>wrong answer</b>",
title: "use when the post does not violate the standards of the site, but is simply misleading or inaccurate",
limitTo: "answer",
},
stdflags:
{
id: 4,
text: "",
prompt: "using <b>standard flags</b> helps us prioritize problems and resolve them faster...",
title: "use when the flagger used a custom flag in a situation where a standard flag would be more appropriate",
onlyFor: [ "<custom>" ],
},
noevidence:
{
id: 2,
text: "",
prompt: "a moderator reviewed your flag, but found <b>no evidence</b> to support it",
title: "use when you were unable to find any evidence that the problem described by the flag actually occurred",
},
nomods:
{
id: 3,
text: "",
prompt: "flags should only be used to make moderators aware of content that requires their intervention",
title: "use when the problem described could be corrected by the flagger, passers-by, the passage of time, or being less pedantic",
},
needsedits:
{
id: -1,
text: "The issue(s) you note with this post can be corrected simply by editing it. Even anonymous users have the ability to suggest edits to posts. This does not require moderator intervention.",
prompt: "post <b>needs editing, not moderator</b> intervention",
title: "use when the post needs edits (either by the flagger or someone else), rather than moderator intervention",
},
notspamquestion:
{
id: -2,
text: "While this question is of extremely low quality and needs to be closed, it is not spam. Please review the list of flag options that are available to you, and choose a more appropriate flag next time.",
prompt: "while this question is of extremely low quality and needs to be closed, it is <b>not spam</b>...",
title: "use when the flagger has raised a spam flag on garbage (recognizes the legitimacy of their concerns, but gently corrects the specific flag choice)",
limitTo: "question",
onlyFor: [ "spam" ],
},
notspamanswer:
{
id: -3,
text: "While this answer is of extremely low quality and needs to be deleted, it is not spam. Please review the list of flag options that are available to you, and choose a more appropriate flag next time.",
prompt: "while this answer is of extremely low quality and needs to be deleted, it is <b>not spam</b>...",
title: "use when the flagger has raised a spam flag on NAA/VLQ (recognizes the legitimacy of their concerns, but gently corrects the specific flag choice)",
limitTo: "answer",
onlyFor: [ "spam" ],
},
notabusive:
{
id: -4,
text: "While we understand your concern(s), the \"rude/abusive\" flag should only be used when the post is completely unsalvageable and needs deletion. This post can (and should have been) fixed by editing.",
prompt: "post is problematic but <b>not irredeemably rude/abusive</b>; you should have edited instead",
title: "use when the flagger has raised a \"rude/abusive\" flag on something that should just be edited (recognizes the legitimacy of their concerns, but gently corrects the specific flag choice)",
onlyFor: [ "rude or abusive" ],
},
notvlqquestion:
{
id: -5,
text: "Only flag as \"very low quality\" when a question should be immediately deleted. To indicate that it's low quality, downvote it. If it should be closed, raise a \"needs improvement\" flag or close vote.",
prompt: "question is <b>not VLQ</b>, just needs to be closed",
title: "use when the flagger has raised a \"very low quality\" flag on a question when they should have voted/flagged to close it instead",
limitTo: "question",
onlyFor: [ "very low quality" ],
},
notdupe:
{
id: -6,
text: "If you disagree that a question is a duplicate, you should edit the question to clarify the difference and why those answers didn't solve the problem. See: https://meta.stackoverflow.com/q/252252",
prompt: "if you <b>disagree that a question is a duplicate</b>...",
title: "use when the flag is complaining to a moderator that the question was incorrectly closed as a duplicate",
limitTo: "question",
onlyFor: [ "<custom>" ],
},
badmigration:
{
id: -7,
text: "Questions should not be migrated away unless they are clearly (1) off-topic for the site where they were originally asked, (2) on-topic for the proposed target site, (3) of notably high quality.",
prompt: "this question should <b>not be migrated</b> elsewhere",
title: "use when the flag is requesting migration of a question that is unsuitable for migration",
limitTo: "question",
onlyFor: [ "<custom>" ],
},
oldmigration:
{
id: -8,
text: "Questions that are more than 60 days old cannot be migrated to other Stack Exchange sites.",
prompt: "questions <b>more than 60 days old</b> cannot be migrated",
title: "use when the flag is requesting migration of a question that is too old (> 60 days) to migrate",
limitTo: "question",
onlyFor: [ "<custom>" ],
},
nodeletion:
{
id: -9,
text: `We do not routinely delete questions that have received answers, as those answers may prove useful to future viewers. Please see: ${window.location.hostname}/help/what-to-do-instead-of-deleting-question`,
prompt: "we <b>do not routinely delete</b> questions that have received answers...",
title: "use when the flagger is requesting deletion of a question with answers that you don't think should be deleted",
limitTo: "question",
onlyFor: [ "<custom>" ],
},
changeaccept:
{
id: -10,
text: `Moderators cannot set or change the accepted answer. This can only be done by the original asker, and is optional. Please see: ${window.location.hostname}/help/accepted-answer`,
prompt: "moderators cannot set or change the <b>accepted answer</b>...",
title: "use when the flagger is requesting that the accepted answer be set/changed",