-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #769 from naher94/development
Resources Surprise Me Tag Added
- Loading branch information
Showing
5 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
let hrefs; // Declare in the outer scope | ||
let randomHref; | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
const tagsContainer = document.querySelector('.tags-container'); | ||
|
||
// Populate hrefs when the page loads | ||
if (tagsContainer) { | ||
const links = tagsContainer.querySelectorAll('a'); | ||
hrefs = Array.from(links).map(link => link.href); | ||
} | ||
|
||
const linkElement = document.querySelector('.resource-surprise-me-button'); | ||
|
||
if (linkElement) { | ||
// Define the function to update the link | ||
const updateRandomLink = () => { | ||
const randomIndex = Math.floor(Math.random() * hrefs.length); | ||
randomHref = hrefs[randomIndex]; | ||
randomHref = randomHref.split('#')[1] ? `#${randomHref.split('#')[1]}` : ''; | ||
linkElement.href = randomHref; // Update the link's href | ||
}; | ||
|
||
// Run the function once on page load to populate the link | ||
updateRandomLink(); | ||
|
||
// Listen for click events on the link | ||
linkElement.addEventListener('click', (event) => { | ||
setTimeout(() => { | ||
updateRandomLink(); // Update the link after the delay | ||
}, 1000); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters