first commit with existing project files

This commit is contained in:
Vincent Guillet
2025-07-12 11:10:38 +02:00
commit 3f5b52661a
5 changed files with 462 additions and 0 deletions

51
partie2-seo.js Normal file
View File

@@ -0,0 +1,51 @@
let text = "";
let keyword = "";
const button = document.getElementById('analyse');
function wordFrequency(texte, keyword) {
const occurrencies = [];
const words = text.trim().split(/[^a-zA-Z]/);
words.forEach(word => {
if (word === keyword) {
occurrencies.push(word);
}
});
return occurrencies.length;
}
function infosHTML(htmlText) {
const infos = {};
const parser = new DOMParser();
const newDoc = parser.parseFromString(htmlText, "text/html");
infos.title = newDoc.getElementsByTagName("title")[0].textContent;
infos.description = newDoc.querySelector("meta[name='description']").content;
return infos;
}
button.addEventListener('click', (e) => {
e.preventDefault();
text = document.getElementById('zone-html').value;
keyword = document.getElementById('keyword').value;
const pageTitle = document.getElementById('page-title');
const pageDescription = document.getElementById('page-meta-description');
pageTitle.style.fontWeight = "normal";
pageTitle.innerText = infosHTML(text).title;
pageDescription.style.fontWeight = "normal";
pageDescription.innerText = infosHTML(text).description;
const keywordNumber = document.getElementById('keyword-number');
keywordNumber.innerText = `Nombre d'occurrences de "${keyword}" : ${wordFrequency(text, keyword)}`;
});