-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodules_modbar.js.html
More file actions
723 lines (626 loc) · 35 KB
/
modules_modbar.js.html
File metadata and controls
723 lines (626 loc) · 35 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>modules/modbar.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#.groups">.groups</a></li><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#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#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#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#drawPosition">drawPosition</a></li><li><a href="global.html#escapeHTML">escapeHTML</a></li><li><a href="global.html#exportSettings">exportSettings</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#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#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#importSettings">importSettings</a></li><li><a href="global.html#isConfigValidVersion">isConfigValidVersion</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#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#searchProfile">searchProfile</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#syntaxHighlighterThemeSelect">syntaxHighlighterThemeSelect</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#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/modbar.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 TBModule, {Module} from '../tbmodule.jsx';
import * as TBui from '../tbui.js';
import {buildType} from '../util/buildenv.ts';
import {icons} from '../util/icons.ts';
import createLogger from '../util/logging.ts';
import {purify} from '../util/purify.js';
import {getSettingAsync, setSettingAsync} from '../util/settings.ts';
const log = createLogger('Modbar');
// Hold onto the modbarExists resolver so we can call it when the time is right
let resolveModbarExists = null;
/**
* A promise which resolves when the modbar is added to the page.
* @constant {Promise<void>}
*/
export const modbarExists = new Promise(resolve => {
resolveModbarExists = resolve;
});
export default new Module({
name: 'Modbar',
id: 'Modbar',
alwaysEnabled: true,
settings: [
{
id: 'compactHide',
description: 'Use compact mode for modbar',
type: 'boolean',
default: false,
advanced: true,
},
{
id: 'unmoderatedOn',
description: 'Show icon for unmoderated',
type: 'boolean',
default: true,
},
{
id: 'enableModSubs',
description: 'Show Moderated Subreddits in the modbar',
type: 'boolean',
default: true,
},
{
id: 'enableOldNewToggle',
description: 'Include a button in the modbar to swap between old and new Reddit',
type: 'boolean',
default: true,
},
{
id: 'shortcuts',
description: 'Shortcuts',
type: 'map',
default: {},
labels: ['name', 'url'],
hidden: false,
},
{
id: 'modbarHidden',
type: 'boolean',
default: false,
hidden: true,
},
{
id: 'lockScroll',
type: 'boolean',
default: false,
hidden: true,
},
{
id: 'customCSS',
type: 'code',
default: '',
hidden: true,
},
{
id: 'lastExport',
type: 'number',
default: 0,
hidden: true,
},
{
id: 'showExportReminder',
type: 'boolean',
default: true,
hidden: true,
},
{
id: 'subredditColorSalt',
type: 'text',
default: 'PJSalt',
hidden: true,
},
],
}, async function init ({
shortcuts,
compactHide,
unmoderatedOn,
enableModSubs,
enableOldNewToggle,
customCSS,
modbarHidden,
subredditColorSalt,
}) {
// Clean up old settings related to the now-removed dev console
// TODO: Remove this a couple versions from now when people have reasonably
// probably updated past this
setSettingAsync(this.id, 'consoleShowing', undefined);
const $body = $('body');
// Footer element below the page so toolbox never should be in the way.
// Doing it like this because it means we don't have to mess with reddit css
const $footerblock = $('<div id="tb-footer-block">').appendTo($body);
// Don't add the mod bar to embedded pages or if not logged in
if (TBCore.isEmbedded || !await TBApi.getCurrentUser()) {
return;
}
// This prevents some weird scrollbar behavior on new reddit iframe embeds.
window.addEventListener('TBNewPage', event => {
const pageType = event.detail.pageType;
if (pageType === 'oldModmail' || pageType === 'message') {
$footerblock.hide();
} else {
$footerblock.show();
const {url} = getDirectingTo();
$('#tb-old-new-reddit-toggle').attr('href', url);
}
});
//
// preload some generic variables
//
const debugMode = await getSettingAsync('Utils', 'debugMode', false);
const modSubreddits = await getSettingAsync('Notifier', 'modSubreddits', 'mod');
const unmoderatedSubreddits = await getSettingAsync('Notifier', 'unmoderatedSubreddits', 'mod');
const unreadMessageCount = await getSettingAsync('Notifier', 'unreadMessageCount', 0);
const modqueueCount = await getSettingAsync('Notifier', 'modqueueCount', 0);
const unmoderatedCount = await getSettingAsync('Notifier', 'unmoderatedCount', 0);
const modmailCount = await getSettingAsync('Notifier', 'modmailCount', 0);
const newModmailCount = await getSettingAsync('Notifier', 'newModmailCount', 0);
const notifierEnabled = await getSettingAsync('Notifier', 'enabled', true);
const modSubredditsFMod = await getSettingAsync('Notifier', 'modSubredditsFMod', false);
const unmoderatedSubredditsFMod = await getSettingAsync('Notifier', 'unmoderatedSubredditsFMod', false);
// Ready some details for new modmail linking
const modmailLink = await getSettingAsync('NewModMail', 'modmaillink', 'all_modmail');
const openMailTab = await getSettingAsync('NewModMail', 'openmailtab', false) && !TBCore.isNewModmail;
const newModmailBaseUrl = 'https://mod.reddit.com/mail/';
let newModmailUrl;
switch (modmailLink) {
case 'all_modmail':
newModmailUrl = `${newModmailBaseUrl}all`;
break;
case 'inbox':
newModmailUrl = `${newModmailBaseUrl}inbox`;
break;
case 'new':
newModmailUrl = `${newModmailBaseUrl}new`;
break;
case 'in_progress':
newModmailUrl = `${newModmailBaseUrl}inprogress`;
break;
case 'archived':
newModmailUrl = `${newModmailBaseUrl}archived`;
break;
case 'highlighted':
newModmailUrl = `${newModmailBaseUrl}highlighted`;
break;
case 'mod_discussions':
newModmailUrl = `${newModmailBaseUrl}mod`;
break;
case 'notifications':
newModmailUrl = `${newModmailBaseUrl}notifications`;
}
// Custom CSS for debug mode/testing
if (customCSS) {
$('head').append(`<style type="text/css">${customCSS}</style>`);
}
//
// UI elements
//
// style="display: none;"
// toolbar, this will display all counters, quick links and other settings for the toolbox
const modQueueUrl = TBCore.link(
modSubredditsFMod ? '/me/f/mod/about/modqueue/' : `/r/${modSubreddits}/about/modqueue`,
);
const $modBar = $(`
<div id="tb-bottombar">
<a class="tb-bottombar-hide tb-icons" href="javascript:void(0)">${icons.arrowLeft}</a>
<a class="tb-toolbar-new-settings tb-icons" href="javascript:void(0)" title="toolbox settings">${icons.settings}</a>
<label class="tb-first-run">&#060;-- Click for settings</label>
<span id="tb-bottombar-contentleft">
<span id="tb-toolbarshortcuts"></span>
</span>
<span id="tb-bottombar-contentright">
<span id="tb-toolbarcounters">
<a title="no mail" href="${
TBCore.link('/message/inbox/')
}" class="nohavemail tb-icons" id="tb-mail">${icons.userInbox}</a>
<a href="${TBCore.link('/message/inbox/')}" id="tb-mailCount"></a>
<a href="${newModmailUrl}" class="nohavemail access-required tb-icons" id="tb-new_modmail" ${
openMailTab ? 'target="_blank"' : ''
}>${icons.modmail}</a>
<a href="${newModmailUrl}" id="tb-new-modmailcount" ${openMailTab ? 'target="_blank"' : ''}></a>
<a title="modqueue" href="${modQueueUrl}" id="tb-modqueue" class="tb-icons">${icons.modqueue}</a>
<a href="${modQueueUrl}" id="tb-queueCount"></a>
</span>
</span>
<div id="tb-new-modmail-tooltip">
<table>
<tr id="tb-new-modmail-new">
<td class="tb-new-mm-category"><a href="https://mod.reddit.com/mail/new" id="tb-new-modmailcount" ${
openMailTab ? 'target="_blank"' : ''
}>New</a></td>
<td class="tb-new-mm-count"></td>
</tr>
<tr id="tb-new-modmail-inprogress">
<td class="tb-new-mm-category"><a href="https://mod.reddit.com/mail/inprogress" id="tb-new-modmailcount" ${
openMailTab ? 'target="_blank"' : ''
}>In Progress</a></td>
<td class="tb-new-mm-count"></td>
</tr>
<tr id="tb-new-modmail-banappeals">
<td class="tb-new-mm-category"><a href="https://mod.reddit.com/mail/appeals" id="tb-new-modmailcount" ${
openMailTab ? 'target="_blank"' : ''
}>Ban Appeals</a></td>
<td class="tb-new-mm-count"></td>
</tr>
<tr id="tb-new-modmail-joinrequests">
<td class="tb-new-mm-category"><a href="https://mod.reddit.com/mail/join_requests" id="tb-new-modmailcount" ${
openMailTab ? 'target="_blank"' : ''
}>Join Requests</a></td>
<td class="tb-new-mm-count"></td>
</tr>
<tr id="tb-new-modmail-highlighted">
<td class="tb-new-mm-category"><a href="https://mod.reddit.com/mail/highlighted" id="tb-new-modmailcount" ${
openMailTab ? 'target="_blank"' : ''
}>Highlighted</a></td>
<td class="tb-new-mm-count"></td>
</tr>
<tr id="tb-new-modmail-mod">
<td class="tb-new-mm-category"><a href="https://mod.reddit.com/mail/mod" id="tb-new-modmailcount" ${
openMailTab ? 'target="_blank"' : ''
}>Mod Discussions</a></td>
<td class="tb-new-mm-count"></td>
</tr>
<tr id="tb-new-modmail-notifications">
<td class="tb-new-mm-category"><a href="https://mod.reddit.com/mail/notifications" id="tb-new-modmailcount" ${
openMailTab ? 'target="_blank"' : ''
}>Notifications</a></td>
<td class="tb-new-mm-count"></td>
</tr>
</div>
</div>
`);
let hoverTimeout;
$modBar.find('#tb-new_modmail, #tb-new-modmailcount, #tb-new-modmail-tooltip').hover(() => {
clearTimeout(hoverTimeout);
$modBar.find('#tb-new-modmail-tooltip').show();
}, () => {
hoverTimeout = setTimeout(() => {
$modBar.find('#tb-new-modmail-tooltip').hide(100);
}, 1000);
});
// Add unmoderated icon if it is enabled.
if (unmoderatedOn) {
const unModQueueUrl = TBCore.link(
unmoderatedSubredditsFMod
? '/me/f/mod/about/unmoderated/'
: `/r/${unmoderatedSubreddits}/about/unmoderated`,
);
$modBar.find('#tb-toolbarcounters').append(`
<a title="unmoderated" href="${unModQueueUrl}" class="tb-icons" id="tb-unmoderated">${icons.unmoderated}</a>
<a href="${unModQueueUrl}" id="tb-unmoderatedCount"></a>
`);
}
const $modbarhid = $(`
<div id="tb-bottombar-hidden" class="${compactHide ? 'tb-bottombar-compact' : ''}">
<a class="tb-bottombar-unhide tb-icons" href="javascript:void(0)">${
compactHide ? icons.dotMenu : icons.arrowRight
}</a>
</div>
`);
$body.append($modBar);
$body.append($modbarhid);
const toggleMenuBar = hidden => {
if (hidden) {
$modBar.hide();
$modbarhid.show();
$body.toggleClass('tb-modbar-shown', false); // New modmail uses this style to add space to the bottom of the page
} else {
$modBar.show();
$modbarhid.hide();
$body.toggleClass('tb-modbar-shown', true);
}
this.set('modbarHidden', hidden);
};
// Always default to hidden in compact mode
if (compactHide) {
modbarHidden = true;
}
toggleMenuBar(modbarHidden);
// modbar was added to the DOM, let everyone know so they can add buttons and stuff
resolveModbarExists();
// moderated subreddits button.
if (enableModSubs) {
TBCore.getModSubs(true).then(async mySubsData => {
if (!mySubsData.length) {
return;
}
$body.find('#tb-bottombar-contentleft').prepend(
'<a href="javascript:void(0)" class="tb-modbar-button" id="tb-toolbar-mysubs" style="display: none">Moderated Subreddits</a> ',
);
let subList = '';
const configEnabled = await getSettingAsync('TBConfig', 'enabled', false);
const usernotesEnabled = await getSettingAsync('UserNotes', 'enabled', false);
log.debug('got mod subs');
log.debug(mySubsData.length);
$(mySubsData).each(function () {
const subColor = TBHelpers.stringToColor(this.subreddit + subredditColorSalt);
subList += `
<tr style="border-left: solid 3px ${subColor} !important;" data-subreddit="${this.subreddit}">
<td class="tb-my-subreddits-name"><a title="/r/${this.subreddit}" href="${
TBCore.link(`/r/${this.subreddit}`)
}" target="_blank">/r/${this.subreddit}</a></td>
<td class="tb-my-subreddits-subreddit">
<a title="/r/${this.subreddit} modqueue" target="_blank" href="${
TBCore.link(`/r/${this.subreddit}/about/modqueue`)
}" data-type="modqueue" data-subreddit="${this.subreddit}" class="tb-icons">${icons.modqueue}</a>
<a title="/r/${this.subreddit} unmoderated" target="_blank" href="${
TBCore.link(`/r/${this.subreddit}/about/unmoderated`)
}" data-type="unmoderated" data-subreddit="${this.subreddit}" class="tb-icons">${icons.unmoderated}</a>
<a title="/r/${this.subreddit} moderation log" target="_blank" href="${
TBCore.link(`/r/${this.subreddit}/about/log`)
}" data-type="modlog" data-subreddit="${this.subreddit}" class="tb-icons">${icons.modlog}</a>
<a title="/r/${this.subreddit} traffic stats" target="_blank" href="${
TBCore.link(`/r/${this.subreddit}/about/traffic`)
}" data-type="traffic" data-subreddit="${this.subreddit}" class="tb-icons">${icons.subTraffic}</a>
${
usernotesEnabled
? `<a title="/r/${this.subreddit} usernotes" href="javascript:;" class="tb-un-config-link tb-icons" data-subreddit="${this.subreddit}">${icons.usernote}</a>`
: ''
}
${
configEnabled
? `<a title="/r/${this.subreddit} config" href="javascript:;" class="tb-config-link tb-icons" data-subreddit="${this.subreddit}">${icons.tbSubConfig}</a>`
: ''
}
</td>
</tr>
`;
});
const modSubsPopupContent = `
<div id="tb-my-subreddits">
<input id="tb-livefilter-input" type="text" class="tb-input" placeholder="live search" value="">
<span class="tb-livefilter-count">${mySubsData.length}</span>
<br>
<table id="tb-my-subreddit-list">${subList}</table>
</div>
`;
$body.on('click', '#tb-toolbar-mysubs', () => {
const $existingPopup = $body.find('.subreddits-you-mod-popup');
if (!$existingPopup.length) {
TBui.popup({
title: 'Subreddits you moderate',
tabs: [
{
title: 'Subreddits you moderate',
id: 'sub-you-mod', // reddit has things with class .role, so it's easier to do this than target CSS
tooltip: 'Subreddits you moderate',
content: modSubsPopupContent,
footer: '',
},
],
cssClass: 'subreddits-you-mod-popup',
}).appendTo('body').css({
position: 'fixed',
bottom: '41px',
left: '20px',
});
// Focus the filter bar for convenience
$('#tb-livefilter-input').focus();
} else {
$existingPopup.remove();
}
$body.find('#tb-livefilter-input').keyup(function () {
const LiveSearchValue = $(this).val();
$body.find('#tb-my-subreddits table tr').each(function () {
const $this = $(this);
const subredditName = $this.attr('data-subreddit');
if (subredditName.toUpperCase().indexOf(LiveSearchValue.toUpperCase()) < 0) {
$this.hide();
} else {
$this.show();
}
$('.tb-livefilter-count').text($('#tb-my-subreddits table tr:visible').length);
});
});
});
// only show the button once it's populated.
$('#tb-toolbar-mysubs').show();
});
}
// Swap old/new reddit button
if (enableOldNewToggle && !TBCore.isNewModmail) {
const {url, directingTo} = getDirectingTo();
// Append the link
$('#tb-bottombar-contentleft').append(`
<a href="${url}" id="tb-old-new-reddit-toggle" class="tb-modbar-button" title="View this page in ${directingTo}">Open in ${directingTo}</a>
`);
}
TBCore.getLastVersion().then(lastVersion => {
if (lastVersion < TBCore.shortVersion) {
$('.tb-first-run').show().css('display', 'inline-block');
}
});
// Always add version label to modbar on non-stable versions
if (buildType !== 'stable') {
$('#tb-bottombar').find('#tb-toolbarcounters').before(
$(`
<button
id="tb-prerelease-link"
title="this is a ${buildType} build of toolbox. click to copy version information"
/>
<i class="tb-icons">${icons.prerelease}</i>
<span>${TBCore.toolboxVersion}</span>
</button>
`).on('click', () => {
navigator.clipboard.writeText(TBCore.toolboxVersion).then(() => {
TBui.textFeedback(
'Copied version information to clipboard',
TBui.TextFeedbackKind.POSITIVE,
undefined,
TBui.TextFeedbackLocation.BOTTOM,
);
}).catch(error => {
TBui.textFeedback(
`Failed to copy version info: ${error.message}`,
TBui.TextFeedbackKind.NEGATIVE,
undefined,
TBui.TextFeedbackLocation.BOTTOM,
);
});
}),
);
}
if (debugMode) {
// Reload button
$('#tb-bottombar').find('#tb-toolbarcounters').before(
`<a href="javascript:;" id="tb-reload-link" class="tb-icons" title="reload toolbox">${icons.tbReload}</a>`,
);
$body.on('click', '#tb-reload-link', () => {
log.debug('reloading chrome');
TBui.reloadToolbox();
});
}
// Append shortcuts
Object.entries(shortcuts).forEach(([index, value]) => {
// TODO: Separators here should probably use CSS rather than having nested elements and stuff
const $shortcut = $(
`<a class="tb-no-gustavobc" href="${TBHelpers.htmlEncode(unescape(value))}">${
TBHelpers.htmlEncode(unescape(index))
}</a>`,
);
$shortcut.appendTo('#tb-toolbarshortcuts');
});
// Show/hide menubar
$body.on('click', '.tb-bottombar-unhide, .tb-bottombar-hide', function () {
toggleMenuBar($(this).hasClass('tb-bottombar-hide'));
});
// Show counts on hover
let $modBarHidTooltip = $body.find('#tb-modbar-hide-tooltip');
$modbarhid.mouseenter(() => {
if (!notifierEnabled || compactHide) {
return;
}
const hoverContent = `
<table>
<tr>
<td>New Messages</td>
<td>${unreadMessageCount}</td>
</tr>
<tr >
<td>Mod Queue</td>
<td>${modqueueCount}</td>
</tr>
<tr >
<td>Unmoderated Queue</td>
<td>${unmoderatedCount}</td>
</tr>
<tr>
<td>Mod Mail</td>
<td >${modmailCount}</td>
</tr>
<tr>
<td>New Mod Mail</td>
<td >${newModmailCount}</td>
</tr>
</table>
`;
if (!$modBarHidTooltip.length) {
$modBarHidTooltip = $('<div id="tb-modbar-hide-tooltip"></div>').appendTo($body);
}
$modBarHidTooltip.html(purify(hoverContent));
$modBarHidTooltip.fadeIn(200);
}).mouseleave(() => {
$modBarHidTooltip.fadeOut(200);
});
// Open the settings
$body.on('click', '.tb-toolbar-new-settings', () => {
if ($('.tb-settings').length) {
return;
} // Don't show the window twice
TBModule.showSettings();
});
// check for passed settings.
function switchTab (module) {
const $this = $body.find(`[data-module="${module}"]`);
const $tb_help_mains = $('.tb-help-main');
// achievement support
if (module === 'about') {
TBCore.sendEvent(TBCore.events.TB_ABOUT_PAGE);
}
if (module === 'syntax') {
TBCore.sendEvent(TBCore.events.TB_SYNTAX_SETTINGS);
}
$('.tb-window-tabs a').removeClass('active');
$this.addClass('active');
$tb_help_mains.attr('currentpage', module);
// if we have module name, give that to the help button
if ($this.data('module')) {
$tb_help_mains.data('module', $this.data('module'));
}
$('.tb-personal-settings .tb-window .tb-window-tab').hide();
$(`.tb-personal-settings .tb-window .tb-window-tab.${module}`).show();
}
window.addEventListener('TBHashParams', event => {
let module = event.detail.tbsettings;
if (module) {
let setting = event.detail.setting;
log.debug(setting);
module = module.toLowerCase();
if (setting) {
setting = setting.toLowerCase();
const id = `#tb-${module}-${setting}`;
let highlightedCSS =
`${id} p {background-color: ${TBui.standardColors.softyellow}; display: block !important;}`;
// this next line is to deal with legacy settings
highlightedCSS +=
`${id}{background-color: ${TBui.standardColors.softyellow}; display: block !important;}`;
highlightedCSS += `.tb-setting-link-${setting} {display: inline !important;}`;
$('head').append(`<style type="text/css">${highlightedCSS}</style>`);
}
// Wait a sec for stuff to load.
setTimeout(async () => {
// prevent tbsetting URL hash from persisting on reload.
history.pushState('', document.title, window.location.pathname);
await TBModule.showSettings();
switchTab(module);
}, 500);
}
});
// change tabs
$body.on('click', '.tb-window-tabs a:not(.active)', function () {
const tab = $(this).attr('data-module');
switchTab(tab);
});
});
function getDirectingTo () {
let url = window.location.href.replace(/^http:/, 'https:');
let directingTo;
if (url.startsWith('https://old.')) {
url = url.replace('old.', 'www.');
directingTo = 'new Reddit';
} else if (url.startsWith('https://sh.')) {
url = url.replace('sh.', 'www.');
directingTo = 'old Reddit';
} else {
// Redirect to old Reddit on the redesign, new Reddit otherwise
url = url.replace(/https:\/\/.*?\.reddit/, TBCore.isOldReddit ? 'https://sh.reddit' : 'https://old.reddit');
directingTo = TBCore.isOldReddit ? 'new Reddit' : 'old Reddit';
}
return {url, directingTo};
}
</code></pre>
</article>
</section>
</div>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.2</a> on Wed Mar 04 2026 06:39:42 GMT+0000 (Coordinated Universal Time) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>
<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>
<script src="scripts/search.js" defer></script>
</body>
</html>