Skip to content

Instantly share code, notes, and snippets.

@boilsquid
Last active November 20, 2023 11:27
Show Gist options
  • Save boilsquid/35687f0fc9c858f050d0b0f2dcad4bb4 to your computer and use it in GitHub Desktop.
Save boilsquid/35687f0fc9c858f050d0b0f2dcad4bb4 to your computer and use it in GitHub Desktop.
form_blocker.js
let isActive = true;
function waitForForm() {
const forms = document.querySelectorAll('form[id^="hsForm_"]');
if (forms[0]) {
// Execute your code once the form is found
const evervault = new Evervault('team_197bf4c38e3c', 'app_8ad48da07b77');
isActive = false;
const existingTextarea = document.querySelectorAll('textarea[id^="message-"]');
existingTextarea[0].removeAttribute('name');
const hiddenTextarea = document.createElement('textarea');
// Set attributes for the textarea (type, name, value)
hiddenTextarea.setAttribute('type', 'hidden');
hiddenTextarea.setAttribute('name', 'message');
hiddenTextarea.setAttribute('id', 'newHiddenField');
hiddenTextarea.style.visibility = 'hidden';
// Append the textarea to the form
forms[0].appendChild(hiddenTextarea);
forms[0].addEventListener('input', async function(event) {
console.log("Input changed", event.target.value);
const encryptedValue = await evervault.encrypt(event.target.value);
console.log("ENC_Value", encryptedValue);
hiddenTextarea.value = encryptedValue;
});
} else {
// If the form is not found, check again after a short delay
if (isActive) {
setTimeout(waitForForm, 100); // Check again after 100 milliseconds
}
}
}
waitForForm();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment