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 };