Please remove jQuery dependency.
-
Please convert the javascript code to vanilla javascript.
jQuery is very bloated and affects the performance of the website.
Plain javascript version:var wpa_field_name, wpa_unique_id, wpa_add_test, wpa_hidden_field;
document.addEventListener("DOMContentLoaded", function () {
wpa_field_name = wpa_field_info.wpa_field_name;
wpa_unique_id = wpa_field_info.wpa_field_value;
wpa_add_test = wpa_field_info.wpa_add_test;
wpa_hidden_field = "<div id='altEmail_container' class='altEmail_container'><label for='alt_s'>Alternative:</label><input type='text' id='alt_s' name='alt_s' ></div><span class='wpa_hidden_field' style='display:none;height:0;width:0;'><label>WPA <input type='text' name='" + wpa_field_name + "' value='" + wpa_unique_id + "' /></label></span>";
wpa_add_honeypot_field();
if (typeof wpae_add_honeypot_field === 'function') {
wpae_add_honeypot_field();
}
if (wpa_add_test === 'yes') {
wpa_add_test_block();
}
});
function wpa_act_as_spam() {
var button = document.querySelector('span.wpa-button');
var actiontype = button.getAttribute('data-actiontype');
if (actiontype === 'remove') {
wpa_remove_honeypot_field();
button.setAttribute('data-actiontype', 'add');
button.innerHTML = 'Acting as Spam Bot';
} else {
wpa_add_honeypot_field();
button.setAttribute('data-actiontype', 'remove');
button.innerHTML = 'Act as Spam Bot';
}
}
function wpa_add_honeypot_field() {
var selectors = [
'form.wpcf7-form, .wpcf7 form',
'form.wpforms-form',
'.gform_wrapper form',
'.frm_forms form',
'.caldera-grid form',
'.wp-block-toolset-cred-form form',
'form.cred-user-form',
'form.cred-form',
'form.et_pb_contact_form',
'form.fb_form',
'form.elementor-form',
'form.form-contribution',
'form.cart',
'form#learn-press-checkout-form',
'form.wpa_form',
'.wpa_form form',
'form.spectra-pro-login-form',
'form#loginform',
'form#edd_login_form',
'form.uwp-login-form',
'.et_pb_login_form form',
'form.eael-login-form',
'form#commentform',
'form.ast-commentform',
'form#fl-comment-form',
'form.comment-form',
'.review-form form',
'form#edd-reviews-form',
'.bbp-topic-form form',
'.bbp-reply-form form'
];
document.querySelectorAll(selectors.join(', ')).forEach(function (form) {
form.insertAdjacentHTML('beforeend', wpa_hidden_field);
});
document.querySelectorAll('form.frm-fluent-form, .ff_conv_app').forEach(function (form) {
form.insertAdjacentHTML('beforeend', wpa_hidden_field);
});
if (typeof fluent_forms_global_var_1 !== 'undefined') {
fluent_forms_global_var_1.extra_inputs[wpa_field_name] = wpa_unique_id;
fluent_forms_global_var_1.extra_inputs['alt_s'] = '';
}
document.querySelectorAll('input.wpa_initiator').forEach(function (input) {
var form = input.closest('form');
if (form && form.querySelector('.wpa_hidden_field') === null) {
input.insertAdjacentHTML('afterend', wpa_hidden_field);
}
});
}
function wpa_add_test_block() {
var testBlock = "<div class='wpa-test-msg'><strong>WP Armour ( Only visible to site administrators. Not visible to other users. )</strong><br />This form has a honeypot trap enabled. If you want to act as spam bot for testing purposes, please click the button below.<br/><span class='wpa-button' onclick='wpa_act_as_spam()' data-actiontype='remove'>Act as Spam Bot</span></div>";
document.querySelectorAll('.wpa-test-msg').forEach(function (el) { el.remove(); });
document.querySelectorAll('span.wpa_hidden_field').forEach(function (el) {
el.insertAdjacentHTML('afterend', testBlock);
});
}
function wpa_remove_honeypot_field() {
document.querySelectorAll('.wpa_hidden_field, #altEmail_container, .altEmail_container').forEach(function (el) {
el.remove();
});
if (typeof fluent_forms_global_var_1 !== 'undefined') {
delete fluent_forms_global_var_1.extra_inputs[wpa_field_name];
delete fluent_forms_global_var_1.extra_inputs['alt_s'];
}
}
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.