-
Notifications
You must be signed in to change notification settings - Fork 2
/
SuperShotgun.user.js
348 lines (302 loc) · 14.1 KB
/
SuperShotgun.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
// ==UserScript==
// @name Super Shotgun
// @description Facilitates immediate, hassle-free removal of inappropriate questions by a moderator.
// @author Cody Gray
// @version 1.2
// @homepageURL https://github.com/codygray/so-userscripts
// @updateURL https://github.com/codygray/so-userscripts/raw/master/SuperShotgun.user.js
// @downloadURL https://github.com/codygray/so-userscripts/raw/master/SuperShotgun.user.js
// @supportURL https://github.com/codygray/so-userscripts/issues
// @icon https://raw.githubusercontent.com/codygray/so-userscripts/master/SuperShotgun.png
// @icon64 https://raw.githubusercontent.com/codygray/so-userscripts/master/SuperShotgun64.png
//
// @match *://*.stackoverflow.com/questions/*
// @match *://*.stackexchange.com/questions/*
// @match *://*.stackapps.com/questions/*
// @match *://*.superuser.com/questions/*
// @match *://*.serverfault.com/questions/*
// @match *://*.askubuntu.com/questions/*
// @match *://*.mathoverflow.net/questions/*
//
// @run-at document-end
// ==/UserScript==
/* eslint-disable no-multi-spaces */
/* global $:readonly */ // SO/SE sites always provides jQuery, free-of-charge
/* global StackExchange:readonly */ // this global object always exists on SO/SE domains
(function() {
'use strict';
const IS_CHILD_META = (typeof StackExchange.options.site.parentUrl !== 'undefined');
const IS_SO = location.hostname === 'stackoverflow.com';
const IS_MSO = location.hostname === 'meta.stackoverflow.com';
const IS_MSE = location.hostname === 'meta.stackexchange.com';
const IS_MOD = StackExchange.options.user.isModerator;
const FKEY = StackExchange.options.user.fkey;
if ((typeof StackExchange === 'undefined') || !FKEY) { return; }
function reloadPage()
{
location.reload();
return true;
}
function reloadWhenComplete()
{
// Triggers when all ajax requests have completed
$(document).ajaxStop(function()
{
// Stop subsequent calls
$(this).off("ajaxStop");
reloadPage();
});
}
async function reloadPost(postID)
{
if (postID && StackExchange?.realtime?.reloadPosts)
{
const result = await StackExchange.realtime.reloadPosts(postID);
if (result)
{
return true;
}
}
return reloadPage();
}
async function voteOnPost(postID, voteID)
{
if (!postID)
{
throw new Error('The required "postID" parameter is missing.');
}
if (!voteID)
{
throw new Error('The required "voteID" parameter is missing.');
}
await Promise.resolve($.post({
url: `${location.origin}/posts/${postID}/vote/${voteID}`,
data:
{
fkey: FKEY,
},
}));
return true;
}
async function downvotePost(postID) { return voteOnPost(postID, 3); }
async function deletePost(postID) { return voteOnPost(postID, 10); }
async function undeletePost(postID) { return voteOnPost(postID, 11); }
// The 'closeReason' parameter must be one of:
// - 'Duplicate'
// - 'NeedsDetailsOrClarity'
// - 'NeedMoreFocus'
// - 'OpinionBased'
// - 'SiteSpecific'
// If the 'closeReason' parameter is 'SiteSpecific', then the 'siteSpecificReason' parameter
// must be a numeric ID corresponding to one of the site-specific reasons.
async function closeQuestion(questionID,
closeReason,
siteSpecificReason = null,
siteSpecificOtherText = null,
duplicateID = null)
{
if (!questionID)
{
throw new Error('The required "questionID" parameter is missing.');
}
if (!closeReason)
{
throw new Error('The required "closeReason" parameter is missing.');
}
if (closeReason === 'OffTopic')
{
// OffTopic has been replaced with SiteSpecific.
closeReason = 'SiteSpecific';
}
if ((closeReason === 'SiteSpecific') && !siteSpecificReason)
{
throw new Error('The required "siteSpecificReason" parameter is missing.');
}
if ((closeReason === 'Duplicate') && !duplicateID)
{
throw new Error('The required "duplicateID" parameter is missing.');
}
console.trace(`Closing question #${questionID} as ${closeReason}, reason ${siteSpecificReason} (${siteSpecificOtherText}).`);
await Promise.resolve($.post({
url: `${location.origin}/flags/questions/${questionID}/close/add`,
data:
{
fkey: FKEY,
closeReasonId: closeReason,
duplicateOfQuestionId: (closeReason === 'Duplicate' ) ? duplicateID : null,
siteSpecificCloseReasonId: (closeReason === 'SiteSpecific') ? siteSpecificReason : null,
siteSpecificOtherText: (closeReason === 'SiteSpecific') ? siteSpecificOtherText : null,
originalSiteSpecificOtherText: 'I\u2019m voting to close this question because ',
},
}));
return true;
}
async function closeQuestionAsDuplicate(questionID, duplicateID)
{
return closeQuestion(questionID, 'Duplicate', null, null, duplicateID);
}
async function closeQuestionAsUnclear(questionID)
{
return closeQuestion(questionID, 'NeedsDetailsOrClarity', null, null, null);
}
async function closeQuestionAsUnfocused(questionID)
{
return closeQuestion(questionID, 'NeedMoreFocus', null, null, null);
}
async function closeQuestionAsOpinionBased(questionID)
{
return closeQuestion(questionID, 'OpinionBased', null, null, null);
}
async function closeQuestionAsOffTopic(questionID, reasonID, reasonText = '')
{
return closeQuestion(questionID, 'SiteSpecific', reasonID, reasonText, null);
}
async function nukeQuestion(questionID,
closeReason,
siteSpecificReason = null,
siteSpecificOtherText = null)
{
do
{
try
{
await closeQuestion(questionID,
closeReason,
siteSpecificReason,
siteSpecificOtherText,
null);
await downvotePost(questionID);
await deletePost(questionID);
await reloadPage();
return true;
}
catch (e)
{
reloadPage();
console.error(e);
}
}
while (window.confirm('Something is wrong with your shotgun, Duke. Check the console to see more details.'
+ '\n\nDo you want to retry?'));
return false;
}
function insertNukeButtons()
{
const qh = $('#question-header + .d-flex').first();
if (qh.length > 0)
{
const q = $('.question');
const qid = q.data('questionid');
const isDeleted = q.hasClass('deleted-answer');
qh.find('.flex--item:last-child').addClass('mr16');
function makeNukeBtn(caption, tooltip, reason, reasonID = null, reasonText = null)
{
return `<a class="nuke-button ws-nowrap s-btn s-btn__danger s-btn__outlined"
href="javascript:void(0);"
title="${tooltip}"
data-reason="${reason}"
${reasonID ? `data-reasonid="${reasonID}"` : ''}
${reasonText ? `data-reasontext="${reasonText}"` : ''}
${isDeleted ? 'disabled="disabled"' : ''}
>${caption}</a>`;
}
let nukeActionsHtml = '<div class="flex--item ws-nowrap mb8" id="nuke-actions">';
nukeActionsHtml += '<span class="fc-light mr2">Nuke As: </span>';
if (IS_SO)
{
nukeActionsHtml += makeNukeBtn('Not Prog',
'Not about programming, software-development tools, or a specific algorithm',
'SiteSpecific',
'18');
nukeActionsHtml += makeNukeBtn('App Stores',
'Asking for customer support with third-party services, such as app stores',
'SiteSpecific',
'3',
'Questions asking for [customer support with third-party services](https://meta.stackoverflow.com/questions/255745 "Why can\'t I ask customer service-related questions on Stack Overflow?"), including [developer-centric questions about App Stores](https://meta.stackoverflow.com/q/272165 "Are developer-centric questions about application stores on topic?") are off-topic for Stack Overflow. Instead, please direct your questions to the relevant company/organization\'s technical support team.');
nukeActionsHtml += makeNukeBtn('Recommend',
'Soliciting recommendations for off-site resources',
'SiteSpecific',
'16');
nukeActionsHtml += makeNukeBtn('Typo/No Repro',
'Problem was caused a typo and/or is not reproducible',
'SiteSpecific',
'11');
}
if (IS_MSO)
{
nukeActionsHtml += makeNukeBtn('Not Meta',
'Not about Stack Overflow or the Stack Exchange network',
'SiteSpecific',
'6');
nukeActionsHtml += makeNukeBtn('Not Constructive',
'Does not appear to seek input and discussion from the community',
'SiteSpecific',
'4');
nukeActionsHtml += makeNukeBtn('No Repro',
'Rendered obsolete by changes to the system or circumstances',
'SiteSpecific',
'5');
}
if (IS_MSE)
{
nukeActionsHtml += makeNukeBtn('Not SE',
'Not about the software that powers the Stack Exchange network',
'SiteSpecific',
'8');
nukeActionsHtml += makeNukeBtn('Site-Specific',
'Relates to only one specific Stack Exchange site',
'SiteSpecific',
'11');
nukeActionsHtml += makeNukeBtn('Not Constructive',
'Does not appear to seek input and discussion from the community',
'SiteSpecific',
'5');
nukeActionsHtml += makeNukeBtn('No Repro',
'Rendered obsolete by changes to the system or circumstances',
'SiteSpecific',
'6');
}
nukeActionsHtml += makeNukeBtn('Unclear',
'Unclear or requires additional details',
'NeedsDetailsOrClarity');
nukeActionsHtml += makeNukeBtn('Too Broad',
'Not a specific problem with enough detail to identify an adequate answer',
'NeedMoreFocus');
nukeActionsHtml += makeNukeBtn('Opinion',
'Primarily opinion-based',
'OpinionBased');
nukeActionsHtml += makeNukeBtn('Not English',
'Not written in English',
'SiteSpecific',
IS_SO ? '19' : '3',
IS_SO ? null : `This question is not written in English, and therefore does not meet the minimum requirements for ${StackExchange?.options?.site?.name ?? 'this site'}. All posts on this site are [required to be in English](https://meta.stackexchange.com/questions/13676/).`);
nukeActionsHtml += '</div>';
const nukeActions = $(nukeActionsHtml);
nukeActions.appendTo(qh)
.one('click', 'a[data-reason]', function()
{
nukeActions.find('.nuke-button').attr('disabled', true);
nukeQuestion(qid,
this.dataset.reason,
this.dataset.reasonid,
this.dataset.reasontext);
});
}
}
function appendStyles()
{
$('body').append(`
<style>
#nuke-actions .nuke-button
{
display: inline;
margin: 0 0.5em 0 0;
padding: 0.2em 0.5em;
font-size: 90%;
}
</style>
`);
}
appendStyles();
insertNukeButtons();
})();