-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules_queuetools.js.html
1654 lines (1455 loc) · 76.3 KB
/
modules_queuetools.js.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>modules/queuetools.js - Documentation</title>
<script src="scripts/prettify/prettify.js"></script>
<script src="scripts/prettify/lang-css.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
<script src="scripts/nav.js" defer></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
<div class="navicon"></div>
</label>
<label for="nav-trigger" class="overlay"></label>
<nav >
<input type="text" id="nav-search" placeholder="Search" />
<h2><a href="index.html">Home</a></h2><h2><a href="https://github.com/toolbox-team/reddit-moderator-toolbox" target="_blank" class="menu-item" >Github</a></h2><h2><a href="https://www.reddit.com/r/toolbox" target="_blank" class="menu-item" >Subreddit</a></h2><h3>Classes</h3><ul><li><a href="Module.html">Module</a><ul class='methods'><li data-type='method'><a href="Module.html#get">get</a></li><li data-type='method'><a href="Module.html#getEnabled">getEnabled</a></li><li data-type='method'><a href="Module.html#init">init</a></li><li data-type='method'><a href="Module.html#set">set</a></li><li data-type='method'><a href="Module.html#setEnabled">setEnabled</a></li></ul></li><li><a href="TBListener.html">TBListener</a><ul class='methods'><li data-type='method'><a href="TBListener.html#clear">clear</a></li><li data-type='method'><a href="TBListener.html#on">on</a></li><li data-type='method'><a href="TBListener.html#start">start</a></li><li data-type='method'><a href="TBListener.html#stop">stop</a></li></ul></li></ul><h3>Global</h3><ul><li><a href="global.html#DISPLAY_BOTTOM">DISPLAY_BOTTOM</a></li><li><a href="global.html#DISPLAY_CENTER">DISPLAY_CENTER</a></li><li><a href="global.html#FEEDBACK_NEGATIVE">FEEDBACK_NEGATIVE</a></li><li><a href="global.html#FEEDBACK_NEUTRAL">FEEDBACK_NEUTRAL</a></li><li><a href="global.html#FEEDBACK_POSITIVE">FEEDBACK_POSITIVE</a></li><li><a href="global.html#ModNotesBadge">ModNotesBadge</a></li><li><a href="global.html#ModNotesPager">ModNotesPager</a></li><li><a href="global.html#ModNotesPopup">ModNotesPopup</a></li><li><a href="global.html#NoteTableRow">NoteTableRow</a></li><li><a href="global.html#RandomFeedback">RandomFeedback</a></li><li><a href="global.html#RandomQuote">RandomQuote</a></li><li><a href="global.html#TBsettingsObject">TBsettingsObject</a></li><li><a href="global.html#actionButton">actionButton</a></li><li><a href="global.html#addModSubsToSidebar">addModSubsToSidebar</a></li><li><a href="global.html#addToSiteTable">addToSiteTable</a></li><li><a href="global.html#addTrophiesToSidebar">addTrophiesToSidebar</a></li><li><a href="global.html#alert">alert</a></li><li><a href="global.html#baseDomain">baseDomain</a></li><li><a href="global.html#browserName">browserName</a></li><li><a href="global.html#buildSha">buildSha</a></li><li><a href="global.html#buildType">buildType</a></li><li><a href="global.html#button">button</a></li><li><a href="global.html#checkForActions">checkForActions</a></li><li><a href="global.html#cleanSubredditName">cleanSubredditName</a></li><li><a href="global.html#clearCache">clearCache</a></li><li><a href="global.html#colorNameToHex">colorNameToHex</a></li><li><a href="global.html#contextTrigger">contextTrigger</a></li><li><a href="global.html#createDeferredProcessQueue">createDeferredProcessQueue</a></li><li><a href="global.html#daysToMilliseconds">daysToMilliseconds</a></li><li><a href="global.html#debounce">debounce</a></li><li><a href="global.html#debugInformation">debugInformation</a></li><li><a href="global.html#defaultNoteLabelValueToLabelType">defaultNoteLabelValueToLabelType</a></li><li><a href="global.html#delay">delay</a></li><li><a href="global.html#displayNotes">displayNotes</a></li><li><a href="global.html#domain">domain</a></li><li><a href="global.html#escapeHTML">escapeHTML</a></li><li><a href="global.html#fetchModSubs">fetchModSubs</a></li><li><a href="global.html#fetchNewsNotes">fetchNewsNotes</a></li><li><a href="global.html#figureOutMulti">figureOutMulti</a></li><li><a href="global.html#filterModdable">filterModdable</a></li><li><a href="global.html#getActions">getActions</a></li><li><a href="global.html#getAllModNotes">getAllModNotes</a></li><li><a href="global.html#getAnonymizedSettings">getAnonymizedSettings</a></li><li><a href="global.html#getCache">getCache</a></li><li><a href="global.html#getContextURL">getContextURL</a></li><li><a href="global.html#getLastVersion">getLastVersion</a></li><li><a href="global.html#getLatestModNote">getLatestModNote</a></li><li><a href="global.html#getModSubs">getModSubs</a></li><li><a href="global.html#getModlog">getModlog</a></li><li><a href="global.html#getRandomNumber">getRandomNumber</a></li><li><a href="global.html#getSetting">getSetting</a></li><li><a href="global.html#getSettingAsync">getSettingAsync</a></li><li><a href="global.html#getSettings">getSettings</a></li><li><a href="global.html#getSubmissionFullname">getSubmissionFullname</a></li><li><a href="global.html#getSubredditColors">getSubredditColors</a></li><li><a href="global.html#getTime">getTime</a></li><li><a href="global.html#getToolboxDevs">getToolboxDevs</a></li><li><a href="global.html#handleMessage">handleMessage</a></li><li><a href="global.html#handleTBThings">handleTBThings</a></li><li><a href="global.html#handleThing">handleThing</a></li><li><a href="global.html#hideModActionsThings">hideModActionsThings</a></li><li><a href="global.html#htmlDecode">htmlDecode</a></li><li><a href="global.html#htmlEncode">htmlEncode</a></li><li><a href="global.html#humaniseDays">humaniseDays</a></li><li><a href="global.html#init">init</a></li><li><a href="global.html#initialLoadPromise">initialLoadPromise</a></li><li><a href="global.html#isConfigValidVersion">isConfigValidVersion</a></li><li><a href="global.html#isEquivalent">isEquivalent</a></li><li><a href="global.html#isModSub">isModSub</a></li><li><a href="global.html#isNewModmail">isNewModmail</a></li><li><a href="global.html#isOldReddit">isOldReddit</a></li><li><a href="global.html#labelColors">labelColors</a></li><li><a href="global.html#labelNames">labelNames</a></li><li><a href="global.html#link">link</a></li><li><a href="global.html#listenerAliases">listenerAliases</a></li><li><a href="global.html#literalRegExp">literalRegExp</a></li><li><a href="global.html#makeCommentThread">makeCommentThread</a></li><li><a href="global.html#makeQueueOverlay">makeQueueOverlay</a></li><li><a href="global.html#makeSingleComment">makeSingleComment</a></li><li><a href="global.html#makeSubmissionEntry">makeSubmissionEntry</a></li><li><a href="global.html#makeUserSidebar">makeUserSidebar</a></li><li><a href="global.html#messageHandlers">messageHandlers</a></li><li><a href="global.html#millisecondsToDays">millisecondsToDays</a></li><li><a href="global.html#minutesToMilliseconds">minutesToMilliseconds</a></li><li><a href="global.html#modbarExists">modbarExists</a></li><li><a href="global.html#moveArrayItem">moveArrayItem</a></li><li><a href="global.html#newModmailSidebar">newModmailSidebar</a></li><li><a href="global.html#niceDateDiff">niceDateDiff</a></li><li><a href="global.html#notification">notification</a></li><li><a href="global.html#overlay">overlay</a></li><li><a href="global.html#pager">pager</a></li><li><a href="global.html#pagerForItems">pagerForItems</a></li><li><a href="global.html#parseComments">parseComments</a></li><li><a href="global.html#parser">parser</a></li><li><a href="global.html#popup">popup</a></li><li><a href="global.html#progressivePager">progressivePager</a></li><li><a href="global.html#purify">purify</a></li><li><a href="global.html#purifyObject">purifyObject</a></li><li><a href="global.html#regExpEscape">regExpEscape</a></li><li><a href="global.html#relativeTime">relativeTime</a></li><li><a href="global.html#reloadIframe">reloadIframe</a></li><li><a href="global.html#reloadToolbox">reloadToolbox</a></li><li><a href="global.html#remove">remove</a></li><li><a href="global.html#removeLastDirectoryPartOf">removeLastDirectoryPartOf</a></li><li><a href="global.html#removeQuotes">removeQuotes</a></li><li><a href="global.html#replaceAll">replaceAll</a></li><li><a href="global.html#replaceTokens">replaceTokens</a></li><li><a href="global.html#saneSort">saneSort</a></li><li><a href="global.html#saneSortAs">saneSortAs</a></li><li><a href="global.html#saveSettingsToBrowser">saveSettingsToBrowser</a></li><li><a href="global.html#searchProfile">searchProfile</a></li><li><a href="global.html#setCache">setCache</a></li><li><a href="global.html#setSetting">setSetting</a></li><li><a href="global.html#setSettingAsync">setSettingAsync</a></li><li><a href="global.html#settings">settings</a></li><li><a href="global.html#settingsToObject">settingsToObject</a></li><li><a href="global.html#shortVersion">shortVersion</a></li><li><a href="global.html#showNote">showNote</a></li><li><a href="global.html#sortBy">sortBy</a></li><li><a href="global.html#standardColors">standardColors</a></li><li><a href="global.html#stringToColor">stringToColor</a></li><li><a href="global.html#submissionFullnamesCache">submissionFullnamesCache</a></li><li><a href="global.html#tbRedditEvent">tbRedditEvent</a></li><li><a href="global.html#textFeedback">textFeedback</a></li><li><a href="global.html#timeConverterRead">timeConverterRead</a></li><li><a href="global.html#title_to_url">title_to_url</a></li><li><a href="global.html#toolboxVersion">toolboxVersion</a></li><li><a href="global.html#toolboxVersionName">toolboxVersionName</a></li><li><a href="global.html#typeNames">typeNames</a></li><li><a href="global.html#unescapeHTML">unescapeHTML</a></li><li><a href="global.html#unescapeJSON">unescapeJSON</a></li><li><a href="global.html#verifiedSettingsSave">verifiedSettingsSave</a></li><li><a href="global.html#watchForURLChanges">watchForURLChanges</a></li><li><a href="global.html#wrapWithLastValue">wrapWithLastValue</a></li><li><a href="global.html#zlibDeflate">zlibDeflate</a></li><li><a href="global.html#zlibInflate">zlibInflate</a></li></ul>
</nav>
<div id="main">
<h1 class="page-title">modules/queuetools.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import $ from 'jquery';
import * as TBApi from '../tbapi.ts';
import * as TBCore from '../tbcore.js';
import * as TBHelpers from '../tbhelpers.js';
import TBListener from '../tblistener.js';
import {Module} from '../tbmodule.jsx';
import * as TBStorage from '../tbstorage.js';
import * as TBui from '../tbui.js';
const self = new Module({
name: 'Queue Tools',
id: 'QueueTools',
enabledByDefault: true,
settings: [
{
id: 'showActionReason',
type: 'boolean',
default: true,
description:
'Show previously taken actions next to submissions. Based on the last 500 actions in the subreddit modlog',
},
{
id: 'expandActionReasonQueue',
type: 'boolean',
default: true,
description: 'Automatically expand the mod action table in queues',
},
{
id: 'expandReports',
type: 'boolean',
default: false,
description: 'Automatically expand reports on mod pages.',
},
{
id: 'queueCreature',
type: 'selector',
values: ['kitteh', 'puppy', '/r/babyelephantgifs', '/r/spiderbros', 'piggy', 'i have no soul'],
default: 'kitteh',
description: 'Queue Creature',
},
{
id: 'subredditColor',
type: 'boolean',
default: false,
description: 'Add a border to items in the queue with color unique to the subreddit name.',
},
{
id: 'subredditColorSalt',
type: 'text',
default: 'PJSalt',
description: 'Text to randomly change the subreddit color',
advanced: true,
hidden: async () => !await self.get('subredditColor'),
},
{
id: 'showReportReasons',
type: 'boolean',
default: false,
beta: false,
description: 'Add button to show reports on posts with ignored reports.',
},
//
// Old reddit specific settings go below.
//
{
id: 'autoActivate',
type: 'boolean',
default: true,
description: 'Automatically activate mass queuetools on queue pages.',
oldReddit: true,
},
{
id: 'highlightNegativePosts',
type: 'boolean',
default: false,
description: 'Highlight posts with a score of 0.',
oldReddit: true,
},
{
id: 'hideActionedItems',
type: 'boolean',
default: false,
description: 'Hide items after mod action.',
oldReddit: true,
},
{
id: 'showAutomodActionReason',
type: 'boolean',
default: true,
description: 'Show the action reason from automoderator below submissions and comments.',
oldReddit: true,
},
{
id: 'linkToQueues',
type: 'boolean',
default: false,
description: 'Link to subreddit queue on mod pages.',
oldReddit: true,
},
{
id: 'reportsOrder',
type: 'selector',
advanced: true,
values: ['age', 'edited', 'removed', 'score', 'reports'],
default: 'age',
description:
'Sort by. Note that "edited" and "removed" includes the post time if there is no edit or removal time.',
oldReddit: true,
},
{
id: 'reportsThreshold',
type: 'number',
advanced: true,
min: 0,
max: null,
step: 1,
default: 0,
description: 'Reports threshold.',
oldReddit: true,
},
{
id: 'reportsAscending',
type: 'boolean',
advanced: true,
default: false,
description: 'Sort ascending.',
oldReddit: true,
},
{
id: 'botCheckmark',
type: 'list',
default: ['AutoModerator'],
description:
`Make bot approved checkmarks have a different look <img src="data:image/png;base64,${TBui.iconBot}">. Bot names should be entered separated by a comma without spaces and are case sensitive.`,
oldReddit: true,
},
{
id: 'highlightAutomodMatches',
type: 'boolean',
default: true,
beta: false,
description:
'Highlight words in Automoderator report and action reasons which are enclosed in []. Can be used to highlight automod regex matches.',
oldReddit: true,
},
{
id: 'groupCommentsOnModPage',
type: 'boolean',
default: false,
advanced: true,
description: 'Group comments by their parent submission when viewing mod listings.',
oldReddit: true,
},
],
}, init);
self.queuetoolsOld = function ({
autoActivate,
highlightNegativePosts,
hideActionedItems,
showAutomodActionReason,
linkToQueues,
subredditColor,
subredditColorSalt,
queueCreature,
highlightAutomodMatches,
groupCommentsOnModPage,
botCheckmark,
reportsOrder,
reportsAscending,
reportsThreshold,
expandReports,
}) {
const $body = $('body');
// var SPAM_REPORT_SUB = 'spam', QUEUE_URL = '';
let QUEUE_URL = '';
if (linkToQueues) {
if (TBCore.isModQueuePage) {
QUEUE_URL = 'about/modqueue/';
} else if (TBCore.isUnmoderatedPage) {
QUEUE_URL = 'about/unmoderated/';
}
}
const $noResults = $body.find('p#noresults');
if (TBCore.isModpage && queueCreature !== 'i_have_no_soul' && $noResults.length > 0) {
self.log(queueCreature);
if (queueCreature === 'puppy') {
$noResults.addClass('tb-puppy-old');
} else if (queueCreature === 'kitteh') {
$noResults.addClass('tb-kitteh-old');
} else if (queueCreature === '/r/babyelephantgifs') {
$noResults.addClass('tb-begifs-old');
} else if (queueCreature === '/r/spiderbros') {
$noResults.addClass('tb-spiders-old');
} else if (queueCreature === 'piggy') {
// https://www.flickr.com/photos/michaelcr/5797087585
$noResults.addClass('tb-piggy-old');
}
}
async function colorSubreddits () {
const $this = $(this);
const subredditName = TBHelpers.cleanSubredditName($this.find('a.subreddit').text());
$this.addClass('color-processed');
const isMod = await TBCore.isModSub(subredditName);
if (!isMod) {
return;
}
const colorForSub = TBHelpers.stringToColor(subredditName + subredditColorSalt);
$this.attr('style', `border-left: solid 3px ${colorForSub} !important`);
$this.addClass('tb-subreddit-color');
}
if (subredditColor) {
self.log('adding sub colors');
$('.thing').each(colorSubreddits);
}
// Negative post highlighting
function highlightBadPosts () {
const $this = $(this);
$this.addClass('highlight-processed');
let score = $this.find('.likes .score.likes, .unvoted .score.unvoted, .dislikes .score.dislikes').text();
score = /\d+/.test(score) ? parseInt(score) : 1; // If the score is still hidden, we'll assume it's fine
if (score > 0) {
return;
}
$this.addClass('tb-zero-highlight');
}
if (highlightNegativePosts && TBCore.isModpage) {
$('.thing').not('.highlight-processed').each(highlightBadPosts);
}
// NER for these things.
window.addEventListener('TBNewThings', () => {
if (subredditColor) {
self.log('adding sub colors (ner)');
$('.thing').not('.color-processed').each(colorSubreddits);
}
if (highlightNegativePosts && TBCore.isModpage) {
self.log('adding zero-score highlights');
$('.thing').not('.highlight-processed').each(highlightBadPosts);
}
if (TBCore.isModpage && highlightAutomodMatches) {
highlightedMatches();
}
});
// Add modtools buttons to page.
function addModtools () {
let listingOrder = reportsOrder;
let allSelected = false;
let sortAscending = reportsAscending;
const numberRX = /-?\d+/;
const viewingspam = !!location.pathname.match(/\/about\/(spam|trials)/);
const viewingreports = !!location.pathname.match(/\/about\/reports/);
const EXPAND_TITLE = 'expand reports';
const COLLAPSE_TITLE = 'collapse reports';
if (viewingspam && listingOrder === 'reports') {
listingOrder = 'removed';
}
// Get rid of promoted links & thing rankings
$('#siteTable_promoted,#siteTable_organic,.rank').remove();
// remove stuff we can't moderate (in non-mod queues only)
function removeUnmoddable () {
if (!TBCore.isModpage && !TBCore.isSubCommentsPage) {
$('.thing').each(async function () {
const $thing = $(this);
const $sub = $thing.find('.subreddit');
// Remove if the sub isn't moderated
if ($sub.length > 0) {
const sub = TBHelpers.cleanSubredditName($sub.text());
const isMod = await TBCore.isModSub(sub);
if (!isMod) {
$thing.remove();
}
} else if ($thing.find('.parent').text().endsWith('[promoted post]')) {
// Always remove things like sponsored links (can't mod those)
$thing.remove();
}
});
}
}
removeUnmoddable();
$body.find('.modtools-on').parent().remove();
// Make visible any collapsed things (stuff below /prefs/ threshold)
$('.entry .collapsed:visible a.expand:contains("[+]")').click();
// Add checkboxes, tabs, menu, etc
$('#siteTable').before(`
<div class="modtools-duplicate" style="display: none; visibility: hidden;"></div>
<div class="menuarea modtools" style="padding: 5px 0;margin: 5px 0;top: 0px">
<input style="margin:5px;float:left" title="Select all/none" type="checkbox" id="select-all" title="select all/none"/>
<span>
<a href="javascript:;" class="tb-general-button invert inoffensive" accesskey="I" title="invert selection">invert</a>
<a href="javascript:;" class="tb-general-button open-expandos inoffensive" title="toggle all expando boxes">[+]</a>
<a href="javascript:;" class="tb-general-button inoffensive select"> [select...]</a>
&nbsp;
<a href="javascript:;" class="tb-general-button inoffensive unhide-selected" accesskey="U">unhide&nbsp;all</a>
<a href="javascript:;" class="tb-general-button inoffensive hide-selected" accesskey="H">hide&nbsp;selected</a>
<a href="javascript:;" class="tb-general-button inoffensive toggle-reports" >${EXPAND_TITLE}</a>
<a href="javascript:;" class="pretty-button action negative" accesskey="S" type="negative" tabindex="3">spam&nbsp;selected</a>
<a href="javascript:;" class="pretty-button action neutral" accesskey="R" type="neutral" tabindex="4">remove&nbsp;selected</a>
<a href="javascript:;" class="pretty-button action positive" accesskey="A" type="positive" tabindex="5">approve&nbsp;selected</a>
<a href="javascript:;" class="pretty-button action ignore" accesskey="G" type="ignore" tabindex="6">ignore&nbsp;reports&nbsp;on&nbsp;selected</a>
</span>
${
viewingspam
? ''
: `<span><a><label for="modtab-threshold">Report threshold: </label><input id="modtab-threshold" type="number" min="0" value="${reportsThreshold}" /></a></span>`
}
<span class="dropdown-title lightdrop" style="float:right"> sort:
<div class="tb-dropdown lightdrop">
<span class="selected sortorder">${listingOrder}</span>
</div>
<div class="tb-drop-choices lightdrop sortorder-options">
<a class="choice" href="javascript:;">age</a>
<a class="choice" href="javascript:;">edited</a>
<a class="choice" href="javascript:;">removed</a>
${viewingspam ? '' : '<a class="choice" href="javascript:;">reports</a>'}
<a class="choice" href="javascript:;">score</a>
</div>
</span>
</div>`);
const $closePopup = () => {};
$body.on('click', '.tb-general-button.select', function (event) {
// close popup if it exists
$closePopup();
const $this = $(this);
const $overlay = $this.closest('.tb-page-overlay');
const positions = TBui.drawPosition(event);
let $appendTo;
if ($overlay.length) {
$appendTo = $overlay;
} else {
$appendTo = $('body');
}
const popupSelectContent = `
<div class="lightdrop select-options">
<h2>Types</h2>
${
viewingreports
? ''
: `<p><label><input type="checkbox" class="choice inoffensive" name="banned" /> shadow-banned</label></p>
<p><label><input type="checkbox" class="choice inoffensive" name="filtered"/> spam-filtered</label></p>
${
viewingspam
? ''
: '<p><label><input type="checkbox" class="choice inoffensive" name="reported"/> reported</label></p>'
}`
}
<p><label><input type="checkbox" class="choice" name="comments" /> comments</label></p>
<p><label><input type="checkbox" class="choice" name="links" /> submissions</label></p>
<p><label><input type="checkbox" class="choice" name="self" /> text posts</label></p>
<p><label><input type="checkbox" class="choice" name="flair" /> posts with flair</label></p>
<p class="divider"><input type="text" class="choice tb-input" name="domain" placeholder="domain..." /></p>
<p><input type="text" class="choice tb-input" name="user" placeholder="user..." /></p>
<p><input type="text" class="choice tb-input" name="title" placeholder="title..." /></p>
<p><input type="text" class="choice tb-input" name="subreddit" placeholder="subreddit..." /></p>
<h2 class="divider">Conditional</h2>
<p><input type="text" class="choice tb-input" name="pointsgt" placeholder="points >..." /></p>
<p><input type="text" class="choice tb-input" name="pointslt" placeholder="points <..." /></p>
<h2 class="divider">Acted on</h2>
<p><label><input type="checkbox" class="choice dashed" name="spammed"/> [ spammed ]</label></p>
<p><label><input type="checkbox" class="choice" name="removed" /> [ removed ]</label></p>
<p><label><input type="checkbox" class="choice" name="approved" /> [ approved ]</label></p>
<p><label><input type="checkbox" class="choice" name="ignored" /> [ reports ignored ]</label></p>
<p><label><input type="checkbox" class="choice" name="actioned" /> [ actioned ]</label></p>
</div>`;
TBui.popup({
title: 'Select items',
tabs: [
{
title: 'Tab1',
tooltip: 'NA',
content: popupSelectContent,
footer: TBui.actionButton('Select items', 'select-queue-tools'),
},
],
cssClass: 'queuetools-select-popup',
draggable: true,
}).appendTo($appendTo)
.css({
left: positions.leftPosition,
top: positions.topPosition,
display: 'block',
});
});
$body.on('click', '.tb-dropdown:not(.active)', e => {
e.stopPropagation();
const $element = $(e.currentTarget);
$element.addClass('active');
$element.siblings('.tb-drop-choices').not('.inuse').css('top', `${e.offsetHeight}px`).each(function () {
$(this).css('left', `${$element.position().left}px`).css(
'top',
`${$element.height() + $element.position().top}px`,
);
}).addClass('inuse');
});
$body.on('click', () => {
$body.find('.tb-dropdown.active').removeClass('active');
$body.find('.tb-drop-choices.inuse').removeClass('inuse');
});
// Check if the tab menu exists and create it if it doesn't
$('.thing.link, .thing.comment').prepend(
'<input type="checkbox" tabindex="1" style="margin:5px;float:left;" />',
);
$('.buttons .pretty-button').attr('tabindex', '2');
// add class to processed threads.
const $things = $('.thing');
$things.addClass('mte-processed');
if (expandReports) {
const $toggleReports = $('.toggle-reports');
$toggleReports.addClass('expanded');
$toggleReports.text(COLLAPSE_TITLE);
$('.reported-stamp').siblings('.report-reasons').show();
}
// Add context & history stuff TODO: Figure out what the hell this did. History has been moved to historybutton though.
// $body.append('<div class="pretty-button inline-content" style="z-index:9999;display:none;position:absolute;line-height:12px;min-width:100px"/>');
// $('#siteTable .comment .flat-list.buttons:has( a:contains("parent"))').each(function () {
// $(this).prepend('<li><a class="context" href="' + $(this).find('.first .bylink').attr('href') + '?context=2">context</a></li>');
// });
// Fix the position of the modtools. We do it like this so we can support custom css
const $modtoolsMenu = $body.find('.menuarea.modtools');
const $modtoolsMenuDuplicate = $body.find('.modtools-duplicate');
const offset = $modtoolsMenu.offset();
const offsetTop = offset.top;
const offsetSticky = offset.left;
const rightPosition = $('.side').outerWidth() + 10;
$modtoolsMenu.css({
'margin-right': `${rightPosition}px`,
'margin-left': '5px',
'left': '0',
'margin-top': '0',
'position': 'relative',
'padding-top': '9px',
});
let frame = null;
window.addEventListener('scroll', () => {
let position = 'relative';
const modtoolsHeight = $modtoolsMenu.outerHeight(true);
if (frame) {
cancelAnimationFrame(frame);
}
if (window.scrollY + offsetSticky > offsetTop) {
position = 'fixed';
} else {
position = 'relative';
}
frame = requestAnimationFrame(() => {
$modtoolsMenu.css({
left: position === 'fixed' ? offsetSticky : 0,
right: position === 'fixed' ? offsetSticky : 0,
top: position === 'fixed' ? offsetSticky : 0,
position,
});
$modtoolsMenuDuplicate.css({
display: position === 'fixed' ? 'block' : 'none',
height: modtoolsHeight,
});
});
});
// // Button actions ////
// Select thing when clicked
const noAction = ['A', 'INPUT', 'TEXTAREA', 'BUTTON', 'IMG'];
$body.on('click', '.thing .entry', function (e) {
if (noAction.indexOf(e.target.nodeName) + 1) {
return;
}
self.log('thing selected.');
$(this).parent('.thing').find('input[type=checkbox]:first').click();
});
// NB: the reason both the above method and the next one use .click() instead of .prop() is so they act as a toggle
// when the report button is pressed. See https://github.com/toolbox-team/reddit-moderator-toolbox/issues/421
// This way, if it was already checked by the user, the following call will re-check it. If it wasn't
// the following call will uncheck it.
$body.on('click', '.reported-stamp', function () {
self.log('reports selected.');
$(this).closest('.thing').find('input[type=checkbox]:first').click();
});
// Change sort order
$('.sortorder-options a').click(function () {
const $sortOrder = $('.sortorder');
const order = $(this).text();
const toggleAsc = order === $sortOrder.text();
if (toggleAsc) {
sortAscending = !sortAscending;
}
self.set('reportsAscending', sortAscending);
self.set('reportsOrder', order);
$sortOrder.text(order);
sortThings(order, sortAscending);
});
// Invert all the things.
$('.invert').click(() => {
$('.thing:visible input[type=checkbox]').click();
});
// Select / deselect all the things
$('#select-all').click(function () {
$('.thing:visible input[type=checkbox]').prop('checked', allSelected = this.checked);
});
$body.on('click', '.thing input[type=checkbox]', () => {
const checks = $('.thing:visible input[type=checkbox]');
const selected = checks.filter(':checked').length;
allSelected = !checks.not(':checked').length;
$('#select-all').prop({
indeterminate: !!selected && !allSelected,
checked: allSelected,
});
});
// Select/deselect certain things
$body.on('click', '.select-queue-tools', () => {
// reset
const $things = $('.thing:visible');
const $selectOptions = $('.select-options input').filter((_, el) =>
el.type === 'checkbox' && el.checked || el.type === 'text' && el.value.length
);
$things.find('input[type=checkbox]').prop('checked', false);
function selectThings () {
const $this = $(this);
let shouldSelect = null;
$selectOptions.each((_, el) => {
let selector = '';
let min;
let max;
switch (el.name) {
case 'banned':
selector = '.banned-user';
break;
case 'filtered':
selector = '.spam:not(.banned-user)';
break;
case 'reported':
selector = ':has(.reported-stamp)';
break;
case 'spammed':
selector =
'.spammed,:has(.pretty-button.negative.pressed),:has(.remove-button:contains(spammed))';
break;
case 'removed':
selector =
'.removed,:has(.pretty-button.neutral.pressed),:has(.remove-button:contains(removed))';
break;
case 'approved':
selector =
'.approved,:has(.approval-checkmark,.pretty-button.positive.pressed),:has(.approve-button:contains(approved))';
break;
case 'ignored':
selector = ':has(.pretty-button.pressed[data-event-action*="ignorereports"])'; // could be "ignorereports" or "unignorereports", hence the *=
break;
case 'actioned':
selector =
`.flaired,.approved,.removed,.spammed,:has(.approval-checkmark,.pretty-button.pressed),
:has(.remove-button:contains(spammed)),:has(.remove-button:contains(removed)),:has(.approve-button:contains(approved))`;
break;
case 'domain':
selector = `:has(.domain:contains(${el.value.toLowerCase()}))`;
break;
case 'user':
selector = `:has(.author:contains(${el.value}))`;
break;
case 'title':
selector = `:has(a.title:contains(${el.value}))`;
break;
case 'subreddit':
selector = `:has(a.subreddit:contains(${el.value}))`;
break;
case 'comments':
selector = '.comment';
break;
case 'links':
selector = '.link';
break;
case 'self':
selector = '.self';
break;
case 'flair':
selector = ':has(.linkflairlabel)';
break;
case 'pointsgt':
min = parseInt(el.value);
selector = (_, el) => $(el).find('.score.unvoted').attr('title') > min;
break;
case 'pointslt':
max = parseInt(el.value);
selector = (_, el) => $(el).find('.score.unvoted').attr('title') < max;
break;
}
shouldSelect = $this.is(selector);
return shouldSelect !== false;
});
return shouldSelect;
}
$things.filter(selectThings).find('input[type=checkbox]').prop('checked', true);
$closePopup();
});
$('.hide-selected').click(() => {
$('.thing:visible:has(input:checked)').hide();
$('.thing input[type=checkbox]').prop('checked', false);
});
$('.unhide-selected').click(() => {
$('.thing').show();
});
// Expand reports on click.
$('.toggle-reports').click(function () {
const $this = $(this);
if ($this.hasClass('expanded')) {
$this.removeClass('expanded');
$this.text(EXPAND_TITLE);
$('.reported-stamp').siblings('.report-reasons').hide();
} else {
$this.addClass('expanded');
$this.text(COLLAPSE_TITLE);
$('.reported-stamp').siblings('.report-reasons').show();
}
});
// Mass spam/remove/approve/ignore
$('.pretty-button.action').click(function () {
const approve = this.type === 'positive';
const spam = !approve && this.type === 'negative';
const ignore = this.type === 'ignore';
// Apply action
const $actioned = $('.thing:visible > input:checked').parent().each(function () {
const id = $(this).attr('data-fullname');
if (approve) {
TBApi.approveThing(id).then(() => {
TBCore.sendEvent(TBCore.events.TB_APPROVE_THING);
});
} else if (ignore) {
TBApi.ignoreReports(id);
} else {
TBApi.removeThing(id, spam);
}
});
$actioned.css('opacity', '1');
$actioned.removeClass('flaired spammed removed approved');
$actioned.addClass(approve ? 'approved' : spam ? 'spammed' : 'removed');
if (hideActionedItems) {
$actioned.hide();
}
});
// menuarea pretty-button feedback.
$('.menuarea.modtools .pretty-button').click(function () {
$(this).clearQueue().addClass('pressed').delay(200).queue(function () {
$(this).removeClass('pressed');
});
});
// Uncheck anything we've taken an action, if it's checked.
$body.on('click', '.pretty-button', function () {
const $this = $(this);
const $thing = $this.closest('.thing');
$thing.find('input[type=checkbox]').prop('checked', false);
if (hideActionedItems) {
self.log('hiding item');
$thing.hide();
} else if ($this.hasClass('negative')) {
$thing.removeClass('removed approved');
$thing.addClass('spammed');
} else if ($this.hasClass('neutral')) {
$thing.removeClass('spammed approved');
$thing.addClass('removed');
} else if ($this.hasClass('positive')) {
$thing.removeClass('removed spammed');
$thing.addClass('approved');
}
});
// Set reports threshold (hide reports with less than X reports)
$('#modtab-threshold').on('input', function (e) {
e.preventDefault();
const threshold = +$(this).val();
if (isNaN(threshold)) {
return;
}
$(this).val(threshold);
self.set('reportsThreshold', threshold);
const $allThings = $('.thing');
setThreshold($allThings);
});
function setThreshold (things) {
const threshold = reportsThreshold;
things.show().find('.reported-stamp').text(function (_, str) {
if (str.match(/\d+/) < threshold) {
$(this).closest('.thing').hide();
}
});
// treat modqueue entries without .reported-stamp as 0 reports
if (threshold > 0) {
things.not(':has(.reported-stamp)').hide();
}
}
if (!viewingspam) {
setThreshold($things);
}
function replaceSubLinks () {
const $this = $(this).find('a.subreddit');
const href = $this.attr('href') + QUEUE_URL;
$this.attr('href', href);
}
if (linkToQueues && QUEUE_URL) {
$things.each(replaceSubLinks);
}
// NER support.
window.addEventListener('TBNewThings', () => {
self.log('proc new things');
const things = $('.thing').not('.mte-processed');
processNewThings(things);
});
// Toggle all expando boxes
let expandosOpen = false;
$('.open-expandos').on('click', () => {
if (!expandosOpen) {
self.log('expanding all expandos.');
$('.open-expandos').text('[-]');
$('.expando-button.collapsed').each(function (index) {
const $button = $(this);
const $checkBox = $button.closest('.thing').find('input[type=checkbox]');
setTimeout(() => {
$button.click();
$checkBox.prop('checked', false);
}, index * 1000);
});
expandosOpen = true;
} else {
self.log('collapsing all expandos.');
$('.open-expandos').text('[+]');
$('.expando-button.expanded').each(function () {
const $button = $(this);
const $checkBox = $button.closest('.thing').find('input[type=checkbox]');
$button.click();
$checkBox.prop('checked', false);
});
expandosOpen = false;
}
});
// Process new things loaded by RES or flowwit.
function processNewThings (things) {
// Expand reports on the new page, we leave the ones the user might already has collapsed alone.
if (expandReports) {
$(things).find('.reported-stamp').siblings('.report-reasons').show();
}
// add class to processed threads.
$(things).addClass('mte-processed');
$(things).prepend(
`<input type="checkbox" tabindex="2" style="margin:5px;float:left;"${allSelected ? ' checked' : ''} />`,
).find('.collapsed:visible a.expand:contains("[+]")').click().end().find('.userattrs').end().find(
'.userattrs',
).filter('.comment').find('.flat-list.buttons:has( a:contains("parent"))').each(function () {
$(this).prepend(
`<li><a class="context" href="${
$(this).find('.first .bylink').attr('href')
}?context=2">context</a></li>`,
);
});
if (expandosOpen) {
$(things).find('.expando-button.collapsed').click();
}
if (!viewingspam) {
setThreshold(things);
}
if (linkToQueues && QUEUE_URL) {
$(things).each(replaceSubLinks);
}
removeUnmoddable();
}
// Remove rate limit for expandos,removing,approving
const rate_limit = window.rate_limit;
window.rate_limit = function (action) {
if (action === 'expando' || action === 'remove' || action === 'approve') {
return !1;
}
return rate_limit(action);
};
// sort sidebars
if (TBCore.isModFakereddit) {
$('.sidecontentbox:has(.subscription-box) > .title').append(
'&nbsp;<a href="javascript:;" class="tb-sort-subs">sort by items</a>',
);
}
$body.on('click', '.tb-sort-subs', () => {
let prefix = '';
let page = '';
if (TBCore.isUnmoderatedPage) {
self.log('sorting unmod');
prefix = 'umq-';
page = 'unmoderated';
} else if (TBCore.isModQueuePage) {
self.log('sorting mod queue');
prefix = 'mq-';
page = 'modqueue';
} else {
return;
}
self.log('sorting queue sidebar');
$('.tb-subreddit-item-count').remove();
const $sortButton = $('.tb-sort-subs');
$sortButton.html('sorting...');
$sortButton.css({'padding-left': '17px', 'padding-right': '16px'});
const now = TBHelpers.getTime();
// delay = 0,
const modSubs = [];
TBui.longLoadNonPersistent(true, 'Getting subreddit items...', TBui.FEEDBACK_NEUTRAL);
TBCore.forEachChunked(
$('.subscription-box a.title'),
20,
100,
elem => {
const $elem = $(elem);
const sr = $elem.text();
TBStorage.getCache('QueueTools', `${prefix + TBApi.getCurrentUser()}-${sr}`, '[0,0]').then(
cacheData => {
const data = JSON.parse(cacheData);
modSubs.push(sr);
TBui.textFeedback(
`Getting items for: ${sr}`,
TBui.FEEDBACK_POSITIVE,
null,
TBui.DISPLAY_BOTTOM,
);
// Update count and re-cache data if more than an hour old.
$elem.parent().append(
`<a href="${TBCore.link(`/r/${sr}/about/${page}`)}" count="${
data[0]
}" class="tb-subreddit-item-count">${data[0]}</a>`,
);
if (now > data[1]) {
updateModqueueCount(sr);
}
function updateModqueueCount (sr) {
TBApi.getJSON(`/r/${sr}/about/${page}.json?limit=100`).then(d => {
TBStorage.purifyObject(d);
const items = d.data.children.length;
self.log(` subreddit: ${sr} items: ${items}`);
TBStorage.setCache(
'QueueTools',
`${prefix + TBApi.getCurrentUser()}-${sr}`,
`[${items},${new Date().valueOf()}]`,
);
$(`.subscription-box a[href$="/r/${sr}/about/${page}"]`).text(
d.data.children.length,
).attr('count', d.data.children.length);
});
}
},
);
},
() => {
window.setTimeout(sortSubreddits, 2000); // wait for final callbacks
TBui.longLoadNonPersistent(false, 'Sorting sidebar...', TBui.FEEDBACK_NEUTRAL);
$sortButton.html('sort by items');
$sortButton.css({'padding-left': '', 'padding-right': ''});
},
);
function sortSubreddits () {
const subs = $('.subscription-box li').sort((a, b) =>
b.lastChild.textContent - a.lastChild.textContent
|| +(a.firstChild.nextSibling.textContent.toLowerCase()
> b.firstChild.nextSibling.textContent.toLowerCase())
|| -1
);
$('.subscription-box').empty().append(subs);
}
});
// This method is evil and breaks shit if it's called too early.
function sortThings (order, asc) {