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
|
import { $ } from './utils/dom';
const badWords = [
'artist', 'takedown', 'owner', 'delete', 'remove', 'creator', 'take-down', 'removed', 'stole', 'stolen', 'steal'
];
const badPairs = [
'take down'
];
const promptTexts = [
"READ THIS:\n" +
"Are you reporting this image because you want it taken down? TOO BAD. We do not do that here. Close the tab and leave.\n" +
"Is this a mistake, and you still want to submit this report?\n" +
"Press OK to submit report, press cancel to cancel.",
/* ----- */
"Are you really sure this is not a takedown request and you wish to submit this report? You will be banned if this is a takedown request.\n" +
"Press OK to submit report, press cancel to cancel."
]
function makeWordPairs(words) {
const wordPairs = [];
for (let i = 0; i < words.length - 1; i++) {
wordPairs.push(words[i] + ' ' + words[i + 1]);
}
return wordPairs;
}
function calculateBadWordScore(reportReason, value) {
const valueWords = value.toLowerCase().split(/\s/);
const wordPairs = makeWordPairs(valueWords);
let score = 0;
if (reportReason === 'Other') {
score++;
}
for (const word of valueWords) {
if (badWords.indexOf(word) !== -1) {
score++;
}
}
for (const pair of wordPairs) {
if (badPairs.indexOf(pair) !== -1) {
score++;
}
}
return score;
}
const onReportSubmitted = function(evt) {
const reportForm = evt.target;
const ruleField = $('#category', reportForm);
const additionalField = $('#report_reason', reportForm);
if (calculateBadWordScore(ruleField.value, additionalField.value) >= 2) {
for (const message of promptTexts) {
if (!confirm(message)) {
evt.preventDefault();
break;
}
}
}
};
const setupReportWarnings = function() {
const reportForm = $('.js-report-form');
if (!reportForm) {
return;
}
reportForm.addEventListener('submit', onReportSubmitted);
};
export { setupReportWarnings };
|