Changed around line 1
+ const subjectInput = document.getElementById('subjectInput');
+ const testButton = document.getElementById('testButton');
+ const scoreValue = document.getElementById('scoreValue');
+ const lengthFeedback = document.getElementById('lengthFeedback');
+ const powerWordsFeedback = document.getElementById('powerWordsFeedback');
+ const spamFeedback = document.getElementById('spamFeedback');
+ const newDraftButton = document.getElementById('newDraft');
+ const saveDraftButton = document.getElementById('saveDraft');
+ const draftList = document.getElementById('draftList');
+
+ const powerWords = ['free', 'new', 'proven', 'secret', 'instant', 'guaranteed'];
+ const spamWords = ['buy', 'cheap', 'discount', 'limited', 'offer', 'win'];
+
+ let drafts = JSON.parse(localStorage.getItem('drafts')) || [];
+
+ function analyzeSubjectLine(subject) {
+ let score = 0;
+ let feedback = [];
+
+ // Length check
+ if (subject.length >= 30 && subject.length <= 50) {
+ score += 40;
+ feedback.push({type: 'length', message: 'Good length! (30-50 characters)'});
+ } else {
+ feedback.push({type: 'length', message: 'Aim for 30-50 characters'});
+ }
+
+ // Power words check
+ const foundPowerWords = powerWords.filter(word => subject.toLowerCase().includes(word));
+ if (foundPowerWords.length > 0) {
+ score += 30;
+ feedback.push({type: 'powerWords', message: `Great use of power words: ${foundPowerWords.join(', ')}`});
+ } else {
+ feedback.push({type: 'powerWords', message: 'Consider adding power words'});
+ }
+
+ // Spam words check
+ const foundSpamWords = spamWords.filter(word => subject.toLowerCase().includes(word));
+ if (foundSpamWords.length === 0) {
+ score += 30;
+ feedback.push({type: 'spam', message: 'No spam trigger words detected'});
+ } else {
+ feedback.push({type: 'spam', message: `Potential spam trigger words: ${foundSpamWords.join(', ')}`});
+ }
+
+ return {score, feedback};
+ }
+
+ function displayResults(score, feedback) {
+ scoreValue.textContent = `${score}/100`;
+ scoreValue.style.color = score >= 70 ? 'var(--success-color)' : score >= 40 ? 'var(--warning-color)' : 'var(--error-color)';
+
+ feedback.forEach(item => {
+ if (item.type === 'length') {
+ lengthFeedback.textContent = item.message;
+ } else if (item.type === 'powerWords') {
+ powerWordsFeedback.textContent = item.message;
+ } else if (item.type === 'spam') {
+ spamFeedback.textContent = item.message;
+ }
+ });
+ }
+
+ function saveDraft() {
+ const subject = subjectInput.value.trim();
+ if (subject) {
+ drafts.push(subject);
+ localStorage.setItem('drafts', JSON.stringify(drafts));
+ renderDrafts();
+ subjectInput.value = '';
+ }
+ }
+
+ function renderDrafts() {
+ draftList.innerHTML = '';
+ drafts.forEach((draft, index) => {
+ const li = document.createElement('li');
+ li.textContent = draft;
+
+ const deleteButton = document.createElement('button');
+ deleteButton.textContent = 'Delete';
+ deleteButton.addEventListener('click', () => {
+ drafts.splice(index, 1);
+ localStorage.setItem('drafts', JSON.stringify(drafts));
+ renderDrafts();
+ });
+
+ li.appendChild(deleteButton);
+ draftList.appendChild(li);
+ });
+ }
+
+ testButton.addEventListener('click', () => {
+ const subject = subjectInput.value.trim();
+ if (subject) {
+ const {score, feedback} = analyzeSubjectLine(subject);
+ displayResults(score, feedback);
+ }
+ });
+
+ newDraftButton.addEventListener('click', () => {
+ subjectInput.value = '';
+ scoreValue.textContent = '0/100';
+ lengthFeedback.textContent = '';
+ powerWordsFeedback.textContent = '';
+ spamFeedback.textContent = '';
+ });
+
+ saveDraftButton.addEventListener('click', saveDraft);
+
+ renderDrafts();