您已離線。這是該頁面的唯讀版本。
document.addEventListener('DOMContentLoaded', function() {
const userId = "";
const defaultIcon = "";
if (userId && userId.trim() !== "")
{
fetch(`/_api/contacts(${userId})?$select=entityimage_url`, {
method: 'GET',
headers: {
'Accept': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.entityimage_url) {
displayUserPhoto(`
`);
} else {
displayUserPhoto(defaultIcon);
}
})
.catch(error => {
console.error('Error fetching user photo:', error);
displayUserPhoto(defaultIcon);
});
}
function displayUserPhoto(photoHtml) {
const usernameElement = document.querySelector('.nav-link .username');
if (usernameElement) {
usernameElement.insertAdjacentHTML('beforebegin', photoHtml);
}
}
});