humanizerai / script.js
LoadingMyMind's picture
restart from zero, create me a code of an AI that helps you modify the texts for making them seem like if a real person has writen it
1e321e7 verified
Raw
History Blame Contribute Delete
3.1 kB
document.addEventListener('DOMContentLoaded', () => {
const inputText = document.getElementById('inputText');
const outputText = document.getElementById('outputText');
const humanizeBtn = document.getElementById('humanizeBtn');
const copyBtn = document.getElementById('copyBtn');
humanizeBtn.addEventListener('click', () => {
const text = inputText.value.trim();
if (!text) {
alert('Please enter some text to humanize!');
return;
}
// Simulate processing (in a real app, this would call an API)
humanizeBtn.disabled = true;
humanizeBtn.textContent = 'Processing...';
setTimeout(() => {
const humanized = humanizeText(text);
outputText.value = humanized;
humanizeBtn.disabled = false;
humanizeBtn.textContent = 'Humanize It!';
}, 1000);
});
copyBtn.addEventListener('click', () => {
if (!outputText.value) {
alert('No text to copy!');
return;
}
outputText.select();
document.execCommand('copy');
copyBtn.textContent = 'Copied!';
setTimeout(() => {
copyBtn.textContent = 'Copy Text';
}, 2000);
});
});
// Simple text transformation examples
function humanizeText(text) {
// Replace formal words with more casual ones
const replacements = {
"utilize": "use",
"commence": "start",
"terminate": "end",
"approximately": "about",
"subsequent": "next",
"prior to": "before",
"in order to": "to",
"with regard to": "about",
"on a regular basis": "regularly",
"at this point in time": "now"
};
// Add contractions
const contractions = {
"I am": "I'm",
"you are": "you're",
"we are": "we're",
"they are": "they're",
"cannot": "can't",
"do not": "don't",
"does not": "doesn't",
"will not": "won't",
"should not": "shouldn't"
};
// Apply replacements
let result = text;
for (const [formal, casual] of Object.entries(replacements)) {
result = result.replace(new RegExp(formal, 'gi'), casual);
}
// Apply contractions
for (const [full, contraction] of Object.entries(contractions)) {
result = result.replace(new RegExp(full, 'gi'), contraction);
}
// Add some randomness to make it feel more human
const randomHumanTouches = [
"You know,",
"Well,",
"Actually,",
"I mean,",
"Basically,",
"So,"
];
// Add random human touch to about 30% of sentences
const sentences = result.split('. ');
for (let i = 0; i < sentences.length; i++) {
if (Math.random() < 0.3 && sentences[i].length > 20) {
const randomIndex = Math.floor(Math.random() * randomHumanTouches.length);
sentences[i] = randomHumanTouches[randomIndex] + ' ' + sentences[i].toLowerCase();
}
}
result = sentences.join('. ');
return result;
}