Add inject-scroll-on-load.js
This commit is contained in:
59
inject-scroll-on-load.js
Normal file
59
inject-scroll-on-load.js
Normal file
@@ -0,0 +1,59 @@
|
||||
// Auto-scroll injection script - runs when page loads
|
||||
(function() {
|
||||
console.log('Auto-scroll injection script loaded');
|
||||
|
||||
function injectAutoScroll() {
|
||||
const script = document.createElement('script');
|
||||
script.textContent = `
|
||||
(function() {
|
||||
console.log('Auto-scroll script starting...');
|
||||
let currentIndex = 0;
|
||||
const scrollInterval = 5000;
|
||||
let cards = [];
|
||||
|
||||
function initScroll() {
|
||||
cards = Array.from(document.querySelectorAll('ha-card')).filter(card => {
|
||||
return card.offsetParent !== null; // Only visible cards
|
||||
});
|
||||
|
||||
if (cards.length === 0) {
|
||||
setTimeout(initScroll, 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('Found ' + cards.length + ' cards');
|
||||
|
||||
// Make cards full height
|
||||
cards.forEach(card => {
|
||||
card.style.minHeight = window.innerHeight + 'px';
|
||||
});
|
||||
|
||||
function nextCard() {
|
||||
if (cards.length === 0) return;
|
||||
currentIndex = (currentIndex + 1) % cards.length;
|
||||
cards[currentIndex].scrollIntoView({
|
||||
behavior: 'smooth',
|
||||
block: 'start'
|
||||
});
|
||||
console.log('Scrolled to card ' + (currentIndex + 1));
|
||||
}
|
||||
|
||||
// Start scrolling
|
||||
setInterval(nextCard, scrollInterval);
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
// Wait for page to load
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initScroll);
|
||||
} else {
|
||||
setTimeout(initScroll, 2000);
|
||||
}
|
||||
})();
|
||||
`;
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
|
||||
// Inject after a short delay to ensure page is loaded
|
||||
setTimeout(injectAutoScroll, 3000);
|
||||
})();
|
||||
Reference in New Issue
Block a user