-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdynamic-author.js
More file actions
38 lines (34 loc) · 1.26 KB
/
Copy pathdynamic-author.js
File metadata and controls
38 lines (34 loc) · 1.26 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
document.addEventListener('DOMContentLoaded', () => {
const profileUrl = 'https://your.mastodon.profile';
const authorLinks = document.querySelectorAll('.author-link'); // Select all elements with the class 'author-link'
async function updateAuthor() {
try {
const response = await fetch(profileUrl, {
method: 'GET',
headers: {
'Content-Type': 'text/html'
}
});
if (response.ok) {
const text = await response.text();
const parser = new DOMParser();
const doc = parser.parseFromString(text, 'text/html');
const metaProfileUsername = doc.querySelector('meta[property="profile:username"]');
const profileUsername = metaProfileUsername ? metaProfileUsername.content : null;
if (profileUsername) {
authorLinks.forEach(authorLink => {
authorLink.textContent = profileUsername;
});
console.log('Author updated to:', profileUsername);
} else {
console.error('No profile:username meta tag found in the profile page');
}
} else {
console.error('Failed to fetch the profile page');
}
} catch (error) {
console.error('Error fetching the profile page:', error);
}
}
updateAuthor();
});