Skip to content

Commit

Permalink
Add warning when posting code to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
int-y1 committed May 28, 2024
1 parent 5946470 commit c1a3115
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions templates/comments/media-js.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@
$comment.find('.comment-body').show();
$comment.find('.bad-comment-body').hide();
};

var code_regex = [/input\(/, /#include/, /void\s+main/, /fn\s+main/, /func\s+main/];
$(document).on('click', 'form.comment-submit-form .button[type=submit]', function (e) {
var text = $(this).parents('form').find('#id_body').val();
if (code_regex.some(function (regex) {return regex.test(text);})) {
if (!confirm({{ _('Looks like you\'re trying to post a source code!\n\nThe comment section is not for posting source code.\nIf you want to submit your solution, please use the "Submit solution" button.\n\nAre you sure you want to post this?')|htmltojs }})) {
e.preventDefault();
}
}
});
});
</script>
{% endcompress %}

0 comments on commit c1a3115

Please sign in to comment.