-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodules_queue_overlay.js.html
391 lines (331 loc) · 22.7 KB
/
modules_queue_overlay.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>modules/queue_overlay.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#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#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#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#init">init</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/queue_overlay.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>import $ from 'jquery';
import * as TBCore from '../tbcore.js';
import {Module} from '../tbmodule.jsx';
import * as TBui from '../tbui.js';
import {icons} from '../util/icons.ts';
import {currentPlatform, RedditPlatform} from '../util/platform.ts';
import {purify} from '../util/purify.js';
import {getSettingAsync} from '../util/settings.ts';
export default new Module({
name: 'Queue Overlay',
id: 'queueOverlay',
enabledByDefault: true,
settings: [
{
id: 'overlayFromBarRedesign',
type: 'boolean',
default: true,
description:
'In redesign when clicking queue and unmoderated icons open the old reddit variants in an overlay.',
},
{
id: 'overlayFromBarOld',
type: 'boolean',
default: false,
oldReddit: true,
description: 'Open queue and unmoderated in overlay when clicking on them from the modbar.',
},
],
}, async ({overlayFromBarRedesign, overlayFromBarOld}) => {
const $body = $('body');
const modSubredditsFMod = await getSettingAsync('Notifier', 'modSubredditsFMod', false);
const modSubreddits = await getSettingAsync('Notifier', 'modSubreddits', 'mod');
const unmoderatedSubredditsFMod = await getSettingAsync('Notifier', 'unmoderatedSubredditsFMod', false);
const unmoderatedSubreddits = await getSettingAsync('Notifier', 'unmoderatedSubreddits', 'mod');
// Array used to keep track of loading iframes so that when the overlay gets closed we can properly stop all long load animations.
let activeLoading = [];
// For reports, spam and edited we don't have any settings in toolbox.
// We simply assume people want to see the same as modqueue as that is most used.
const baseUrls = {
modqueue: {
fmod: modSubredditsFMod,
subreddits: modSubreddits,
},
unmoderated: {
fmod: unmoderatedSubredditsFMod,
subreddits: unmoderatedSubreddits,
},
reports: {
fmod: modSubredditsFMod,
subreddits: modSubreddits,
},
spam: {
fmod: modSubredditsFMod,
subreddits: modSubreddits,
},
edited: {
fmod: modSubredditsFMod,
subreddits: modSubreddits,
},
};
if (TBCore.isModpage && TBCore.isEmbedded) {
$('head link[href*="//www.redditstatic.com/embedded."]').remove();
$body.addClass('tb-embedded-queues');
$body.find('.drop-choices a.choice').attr('target', '_self');
}
/**
* Figures out what listing path to use and adds the multireddit representation to the input field on the respective tab.
* @function figureOutMulti
* @param {jqueryObject} $tbQueueUrl input element which will hold the multireddit representation
* @param {string} type the listing type
* @returns {string} the listing path to be used in overlays
*/
function figureOutMulti ($tbQueueUrl, type, subreddit) {
let listUrl;
if (subreddit) {
listUrl = `/r/${subreddit}/about/${type}`;
$tbQueueUrl.val(subreddit);
} else if (baseUrls[type].fmod) {
listUrl = `/me/f/mod/about/${type}/`;
$tbQueueUrl.val('mod');
} else {
listUrl = `/r/${baseUrls[type].subreddits}/about/${type}/`;
$tbQueueUrl.val(baseUrls[type].subreddits);
}
return listUrl;
}
/**
* Reload the iframe belonging to a queue listing based on latest data.
* @function reloadIframe
* @param {jqueryObject} $reloadListing reload button on the listing tab.
* @param {jqueryObject} $tbQueueUrl input element which will hold the multireddit representation
* @param {jqueryObject} $iframe iframe element to be reloaded
* @param {string} type listing type
*/
function reloadIframe ($reloadListing, $tbQueueUrl, $iframe, type) {
$reloadListing.addClass('loading');
TBui.longLoadSpinner(true);
const multi = purify($tbQueueUrl.val());
let newUrl;
if (multi === 'mod' && baseUrls[type].fmod) {
newUrl = `/me/f/mod/about/${type}/`;
} else {
newUrl = `/r/${multi}/about/${type}/`;
}
$iframe.attr('src', `${TBCore.link(newUrl)}?embedded=true`);
}
/**
* Creates the queue overlay or adds data to it if it is already open.
* @function makeQueueOverlay
* @param {string} type listing type
* @param {object} options
* @param {string} options.subreddit optional, when not given the user's toolbox settings for the listing will be used.
* @param {boolean} options.overwrite when true will set the base over the overlay to the given subreddit and will reload the tab with this data.
*/
function makeQueueOverlay (type, {subreddit, overwrite}) {
let $overlay = $body.find('.tb-queue-overlay');
// There is no open overlay so we'll create a new one.
if (!$overlay.length) {
$overlay = TBui.overlay({
title: 'Toolbox queues',
tabs: [
{
title: 'modqueue',
tooltip: 'Moderation queue.',
content: `
<div class="tb-queue-options">
<input type="text" class="tb-input tb-queue-url">
<span class="tb-icons tb-queue-reload">${icons.refresh}</span>
</div>
`,
footer: '',
},
{
title: 'unmoderated',
tooltip: 'Unmoderated posts.',
content: `
<div class="tb-queue-options">
<input type="text" class="tb-input tb-queue-url">
<span class="tb-icons tb-queue-reload">${icons.refresh}</span>
</div>
`,
footer: '',
},
{
title: 'reports',
tooltip: 'reports.',
content: `
<div class="tb-queue-options">
<input type="text" class="tb-input tb-queue-url">
<span class="tb-icons tb-queue-reload">${icons.refresh}</span>
</div>
`,
footer: '',
},
{
title: 'spam',
tooltip: 'spam.',
content: `
<div class="tb-queue-options">
<input type="text" class="tb-input tb-queue-url">
<span class="tb-icons tb-queue-reload">${icons.refresh}</span>
</div>
`,
footer: '',
},
{
title: 'edited',
tooltip: 'edited.',
content: `
<div class="tb-queue-options">
<input type="text" class="tb-input tb-queue-url">
<span class="tb-icons tb-queue-reload">${icons.refresh}</span>
</div>
`,
footer: '',
},
],
tabOrientation: 'horizontal',
details: {
subreddit,
},
})
.addClass('tb-queue-overlay')
.appendTo('body');
$body.css('overflow', 'hidden');
// Handle overlay closing.
$body.on('click', '.tb-queue-overlay .tb-window-header .close', () => {
activeLoading.forEach(() => {
TBui.longLoadSpinner(false);
});
activeLoading = [];
$('.tb-queue-overlay').remove();
$body.css('overflow', 'auto');
});
}
// Overwrite is given from triggers outside of the overlay and overwrites the "base" queue.
if (overwrite) {
$overlay.attr('data-subreddit', subreddit);
}
// There is already an active tab but overwritten is given. In this case we reload the tabs contents with the overwrite data.
if (overwrite && $overlay.find(`.tb-window-tab.${type} iframe.tb-queue-iframe`).length) {
const $tabContent = $overlay.find(`.tb-window-tab.${type} .tb-window-content`);
const $tbQueueUrl = $tabContent.find('.tb-queue-url');
const $reloadListing = $tabContent.find('.tb-queue-reload');
const $iframe = $tabContent.find('iframe.tb-queue-iframe');
const listUrl = figureOutMulti($tbQueueUrl, type, subreddit);
$reloadListing.addClass('loading');
TBui.longLoadSpinner(true);
$iframe.attr('src', `${TBCore.link(listUrl)}?embedded=true`);
}
// No listing is open in the tab yet. Create needed elements and load iframe.
if (!$overlay.find(`.tb-window-tab.${type} iframe.tb-queue-iframe`).length) {
TBui.longLoadSpinner(true);
activeLoading.push('active');
const $tabContent = $overlay.find(`.tb-window-tab.${type} .tb-window-content`);
const $tbQueueUrl = $tabContent.find('.tb-queue-url');
const $reloadListing = $tabContent.find('.tb-queue-reload');
const listUrl = figureOutMulti($tbQueueUrl, type, subreddit);
const $iframe = $(`<iframe src="${TBCore.link(listUrl)}?embedded=true" class="tb-queue-iframe"></iframe>`)
.appendTo($tabContent);
// Handle reloading from the reload button.
$reloadListing.on('click', () => {
if (!$reloadListing.hasClass('loading')) {
reloadIframe($reloadListing, $tbQueueUrl, $iframe, type);
}
});
// Handle reloading when enter is hit in the multi input field.
$tbQueueUrl.on('keyup', event => {
if (event.keyCode === 13 && !$reloadListing.hasClass('loading')) {
reloadIframe($reloadListing, $tbQueueUrl, $iframe, type);
}
});
// Loading is done, remove loading indicators.
$iframe.on('load', () => {
TBui.longLoadSpinner(false);
activeLoading.pop();
$reloadListing.removeClass('loading');
});
}
// Switch to tab
TBui.switchOverlayTab('tb-queue-overlay', type);
}
// A tab button is clicked, get details ready and load listing.
$body.on('click', '.tb-queue-overlay .tb-window-tabs a', function () {
const $this = $(this);
const type = $this.attr('data-module');
const subreddit = $this.closest('.tb-queue-overlay').attr('data-subreddit');
makeQueueOverlay(type, {subreddit});
});
if (
(currentPlatform === RedditPlatform.OLD && overlayFromBarOld)
|| (currentPlatform === RedditPlatform.SHREDDIT && overlayFromBarRedesign)
) {
$body.on('click', '#tb-modqueue, #tb-queueCount', event => {
if (event.ctrlKey || event.metaKey) {
return;
}
event.preventDefault();
makeQueueOverlay('modqueue', {
overwrite: true,
});
});
$body.on('click', '#tb-unmoderated, #tb-unmoderatedCount', event => {
if (event.ctrlKey || event.metaKey) {
return;
}
event.preventDefault();
makeQueueOverlay('unmoderated', {
overwrite: true,
});
});
$body.on(
'click',
'.tb-my-subreddits-subreddit a[data-type="unmoderated"], .tb-my-subreddits-subreddit a[data-type="modqueue"]',
event => {
if (event.ctrlKey || event.metaKey) {
return;
}
event.preventDefault();
const $this = $(event.target);
makeQueueOverlay($this.attr('data-type'), {
subreddit: $this.attr('data-subreddit'),
overwrite: true,
});
},
);
}
});
</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 Mon Feb 03 2025 07:30:25 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>