-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
63 lines (51 loc) · 2.62 KB
/
script.js
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
52
53
54
55
56
57
58
59
60
61
62
63
// Set initial profile picture based on the current theme
function setProfilePicture() {
const profilePicture = document.querySelector('.profile-picture');
const theme = document.body.getAttribute('data-theme');
const imageUrl = theme === 'dark' ? 'ar-io-logo-light.png' : 'ar-io-logo-dark.png';
// Apply the background image to the profile-picture element
profilePicture.style.backgroundImage = `url(${imageUrl})`;
}
// Apply profile picture on load and on theme toggle
window.onload = function() {
const toggleSwitch = document.getElementById('mode-toggle');
const currentTheme = localStorage.getItem('theme') || 'light';
// Set the initial theme from localStorage
document.body.setAttribute('data-theme', currentTheme);
toggleSwitch.checked = currentTheme === 'dark';
// Set the initial profile picture
setProfilePicture();
// Add event listener for theme toggle
toggleSwitch.addEventListener('change', function() {
const theme = this.checked ? 'dark' : 'light';
document.body.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
setProfilePicture();
});
};
document.addEventListener("DOMContentLoaded", function() {
// Find all elements with the data-subdomain attribute
const links = document.querySelectorAll('[data-subdomain]');
// Get the current host (could be sandboxed, ARNS, or regular)
const currentHost = window.location.host;
// Function to extract the root domain while preserving deeper subdomains (e.g., "another-level-deep.frostor.xyz")
function getRootDomain(host) {
const parts = host.split('.');
if (parts.length > 3) {
return parts.slice(1).join('.'); // Preserve all levels except the first subdomain part
} else {
return parts.slice(-2).join('.'); // Return the last two parts for standard domains
}
}
// Get the root domain of the current host (this works for both sandboxed and regular domains)
const rootDomain = getRootDomain(currentHost);
// Loop through each link and dynamically set the href
links.forEach(link => {
const subdomain = link.getAttribute('data-subdomain'); // Get the desired subdomain (e.g., "ardrive")
const path = link.getAttribute('data-path') || ''; // Get the optional path, default to an empty string if not provided
// Construct the dynamic URL
const dynamicURL = `https://${subdomain}.${rootDomain}${path ? '/' + path : ''}`; // Add the path only if it exists
// Set the href attribute dynamically
link.setAttribute('href', dynamicURL);
});
});