| 6 | |
| 7 | // Function to add items to the DOM |
| 8 | function addItems(items) { |
| 9 | const itemList = document.getElementById('community-project-container'); |
| 10 | itemList.innerText = ""; |
| 11 | items.forEach(item => { |
| 12 | console.log(item) |
| 13 | const onclick_project = "window.open('https://scratch.mit.edu/projects/"+item.project_id.toString()+"/', '_blank');" |
| 14 | const onclick_author = "window.open('https://scratch.mit.edu/users/"+item.author.toString()+"/', '_blank');" |
| 15 | const new_element = '<div style="cursor: pointer" onclick="'+onclick_project+'" class="project"><img src="'+item.thumbnail_url+'" alt="Project Thumbnail" class="project-thumbnail"><h3 style="cursor: pointer; margin: 7px;" onclick="'+onclick_project+'" class="project-name">'+item.title+'</h3><p style="cursor: pointer;" class="project-author" onclick="'+onclick_author+'">by '+item.author+'</p></div>' |
| 16 | itemList.innerHTML += new_element; |
| 17 | }); |
| 18 | } |
| 19 | |
| 20 | // Fetch data when the page loads |
| 21 | window.onload = fetchData; |