-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathscript.js
More file actions
127 lines (103 loc) · 5.39 KB
/
script.js
File metadata and controls
127 lines (103 loc) · 5.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Set current year in footer
document.getElementById('current-year').textContent = new Date().getFullYear();
// Character counter for input
const inputText = document.getElementById('ai-input');
const charCount = document.getElementById('char-count');
inputText.addEventListener('input', () => {
const count = inputText.value.length;
charCount.textContent = `${count}/5000 characters`;
if (count > 5000) {
charCount.classList.add('error');
} else {
charCount.classList.remove('error');
}
});
// Humanize button functionality
const humanizeBtn = document.getElementById('humanize-btn');
const outputText = document.getElementById('human-output');
const spinner = document.getElementById('spinner');
const copyBtn = document.getElementById('copy-btn');
const notification = document.getElementById('notification');
humanizeBtn.addEventListener('click', async () => {
const text = inputText.value.trim();
if (!text) {
showNotification('Please enter some text to humanize', 'error');
return;
}
if (text.length > 5000) {
showNotification('Text exceeds 5000 character limit', 'error');
return;
}
try {
// Show loading spinner
humanizeBtn.disabled = true;
spinner.style.display = 'block';
humanizeBtn.querySelector('span').textContent = 'Processing...';
// Create the prompt
const prompt = `Revise the following text to sound more human and natural, minimizing patterns typically associated with AI-generated writing. Use a mix of short and long sentences, and vary sentence structures to avoid mechanical rhythm. Eliminate repetitive phrases or overused expressions, ensuring lexical diversity across the entire text. Avoid overly formal or technical language unless contextually required, and reduce excessive passive voice constructions. Keep paragraph lengths varied and coherent. Break down noun-heavy phrases and reduce nominalization where possible. Alternate discourse markers and transition signals naturally. Maintain semantic clarity while allowing occasional conversational tone to make the writing feel authentic. Here's the text: \`${text}\`
`;
// Encode the prompt for URL
const encodedPrompt = encodeURIComponent(prompt);
// Make API request
const response = await fetch(`https://text.pollinations.ai/${encodedPrompt}`);
const result = await response.text();
// Display the result
outputText.value = result;
// Hide spinner
spinner.style.display = 'none';
humanizeBtn.querySelector('span').textContent = 'Humanize Text';
humanizeBtn.disabled = false;
} catch (error) {
console.error('Error:', error);
outputText.value = 'Error: Could not humanize the text. Please try again.';
// Hide spinner
spinner.style.display = 'none';
humanizeBtn.querySelector('span').textContent = 'Humanize Text';
humanizeBtn.disabled = false;
showNotification('Error processing your request', 'error');
}
});
// Copy button functionality
copyBtn.addEventListener('click', () => {
if (outputText.value.trim()) {
outputText.select();
document.execCommand('copy');
showNotification('Text copied to clipboard!', 'success');
} else {
showNotification('No text to copy', 'error');
}
});
// Notification function
function showNotification(message, type = 'success') {
const notif = document.getElementById('notification');
const icon = notif.querySelector('i');
const text = notif.querySelector('span');
text.textContent = message;
// Set icon and background based on type
if (type === 'success') {
icon.className = 'fas fa-check-circle';
notif.style.background = '#4cc9f0';
} else {
icon.className = 'fas fa-exclamation-circle';
notif.style.background = '#e63946';
}
// Show notification
notif.classList.add('show');
// Hide after 3 seconds
setTimeout(() => {
notif.classList.remove('show');
}, 3000);
}
// Initialize ScrollReveal animations
ScrollReveal().reveal('.card', {
delay: 200,
distance: '20px',
origin: 'bottom',
interval: 100
});
ScrollReveal().reveal('.feature-card', {
delay: 300,
distance: '20px',
origin: 'bottom',
interval: 100
});