A firefox extension to autorefresh the feed every X seconds
1let refreshIntervalId;
2let currentInterval = 15000; // Default, will be updated by background script
3let userScrolledDown = false;
4let scrollThreshold = window.innerHeight * 0.05; // Threshold as 5% of the viewport height
5
6window.addEventListener('scroll', () => {
7 if (window.scrollY > scrollThreshold) {
8 userScrolledDown = true;
9 } else {
10 userScrolledDown = false;
11 }
12});
13
14function simulateHomeButtonClick() {
15 // Check if we are on the main Bluesky feed page
16 if (window.location.href === 'https://bsky.app/') {
17 // Find any element with aria-label="Home"
18 // This is more robust than looking for a specific tag like 'a'
19 const homeButton = document.querySelector('[aria-label="Home"]');
20
21 // Only click the "Home" button (to refresh) if the user has not scrolled down
22 if (!userScrolledDown) {
23 if (homeButton) {
24 // Check if the element is visible and clickable
25 const rect = homeButton.getBoundingClientRect();
26 const isVisible = rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth) && rect.width > 0 && rect.height > 0;
27
28 if (isVisible && typeof homeButton.click === 'function') {
29 homeButton.click();
30 console.log("Bluesky Auto Refresh: Simulated click on the 'Home' button (at top of timeline).");
31 userScrolledDown = false; // Reset scroll status after refresh
32 } else if (!isVisible) {
33 console.log("Bluesky Auto Refresh: 'Home' button found but not visible/clickable.");
34 } else {
35 console.log("Bluesky Auto Refresh: Found element with aria-label='Home', but it cannot be clicked.");
36 }
37 } else {
38 console.log("Bluesky Auto Refresh: 'Home' button with aria-label='Home' not found.");
39 }
40 } else {
41 console.log("Bluesky Auto Refresh: User has scrolled down, skipping refresh.");
42 }
43 }
44}
45
46function startInterval(interval) {
47 clearInterval(refreshIntervalId);
48 currentInterval = interval;
49 refreshIntervalId = setInterval(simulateHomeButtonClick, currentInterval);
50 console.log("Bluesky Auto Refresh: Interval set to " + currentInterval + "ms");
51}
52
53// Run once on page load with the default interval
54startInterval(currentInterval);
55
56// Listen for messages from the background script to update the interval
57browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
58 if (request.action === 'setInterval') {
59 startInterval(request.interval);
60 }
61});
62
63console.log("Bluesky Auto Refresh extension is running (interval controlled by background, refresh paused when scrolled down).");