-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
51 lines (45 loc) · 1.72 KB
/
script.js
File metadata and controls
51 lines (45 loc) · 1.72 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
fetch('blender-open-data.json')
.then(response => response.json())
.then(data => {
const searchInput = document.getElementById('searchInput');
const searchResults = document.getElementById('searchResults');
const copyNotification = document.getElementById('copyNotification');
searchInput.addEventListener('input', () => {
const searchTerm = searchInput.value.toLowerCase();
const filteredData = Object.keys(data).filter(key => key.toLowerCase().includes(searchTerm));
displayResults(filteredData);
});
function displayResults(results) {
searchResults.innerHTML = '';
if (results.length === 0) {
searchResults.innerHTML = 'No hay resultados. Completa el benchmark de <a href="https://opendata.blender.org/">https://opendata.blender.org/</a>';
} else {
results.forEach(result => {
const resultItem = document.createElement('p');
resultItem.innerHTML = result + ": " + data[result];
resultItem.addEventListener('click', () => {
copyToClipboard(resultItem.innerText);
showCopyNotification();
});
searchResults.appendChild(resultItem);
});
}
}
function copyToClipboard(text) {
const textarea = document.createElement('textarea');
textarea.value = text;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
}
function showCopyNotification() {
copyNotification.style.display = 'block';
setTimeout(() => {
copyNotification.style.display = 'none';
}, 2000);
}
})
.catch(error => {
console.log('Error al cargar el JSON:', error);
});