You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.4 KiB

  1. /*
  2. Anti-spam plugin
  3. No spam in comments. No captcha.
  4. wordpress.org/plugins/anti-spam/
  5. */
  6. "use strict";
  7. (function() {
  8. function anti_spam_init() {
  9. var i,
  10. len,
  11. elements,
  12. answer = '',
  13. current_year = new Date().getFullYear(),
  14. dynamic_control;
  15. elements = document.querySelectorAll('.antispam-group');
  16. len = elements.length;
  17. for (i = 0; i < len; i++) { // hide inputs from users
  18. elements[i].style.display = 'none';
  19. }
  20. elements = document.querySelectorAll('.antispam-control-a');
  21. if ((elements) && (elements.length > 0)) { // get the answer
  22. answer = elements[0].value;
  23. }
  24. elements = document.querySelectorAll('.antispam-control-q');
  25. len = elements.length;
  26. for (i = 0; i < len; i++) { // set answer into other input instead of user
  27. elements[i].value = answer;
  28. }
  29. // clear value of the empty input because some themes are adding some value for all inputs
  30. elements = document.querySelectorAll('.antispam-control-e');
  31. len = elements.length;
  32. for (i = 0; i < len; i++) {
  33. elements[i].value = '';
  34. }
  35. //dynamic_control = '<input type="text" name="antspm-d" class="antispam-control antispam-control-d" value="' + current_year + '" />';
  36. dynamic_control = document.createElement('input');
  37. dynamic_control.setAttribute('type', 'hidden');
  38. dynamic_control.setAttribute('name', 'antspm-d');
  39. dynamic_control.setAttribute('class', 'antispam-control antispam-control-d');
  40. dynamic_control.setAttribute('value', current_year);
  41. // add input for every comment form if there are more than 1 form with IDs: comments, respond or commentform
  42. elements = document.querySelectorAll('form');
  43. len = elements.length;
  44. for (i = 0; i < len; i++) {
  45. if ( (elements[i].id === 'comments') || (elements[i].id === 'respond') || (elements[i].id === 'commentform') ) {
  46. var class_index = elements[i].className.indexOf('anti-spam-form-processed');
  47. if ( class_index == -1 ) { // form is not yet js processed
  48. //elements[i].innerHTML += dynamic_control; // not working
  49. elements[i].appendChild(dynamic_control);
  50. elements[i].className = elements[i].className + ' anti-spam-form-processed';
  51. }
  52. }
  53. }
  54. }
  55. if (document.addEventListener) {
  56. document.addEventListener('DOMContentLoaded', anti_spam_init, false);
  57. }
  58. // set 1 second timeout for having form loaded and adding support for browsers which does not support 'DOMContentLoaded' listener
  59. setTimeout(function () {
  60. anti_spam_init();
  61. }, 1000);
  62. })();