Last active
July 27, 2023 09:48
-
-
Save azu/f6ca3e8d7fdebc729ecf41dccc48c430 to your computer and use it in GitHub Desktop.
Bluesky: auto refresh
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
// ==UserScript== | |
// @name Bluesky: auto refresh | |
// @namespace https://efcl.info | |
// @match https://bsky.app/* | |
// @grant none | |
// @version 1.0 | |
// @author azu | |
// @description Auto Refresh when notifications is shown | |
// ==/UserScript== | |
const origSetInterval = window.setInterval; | |
// refresh 15sec === refresh fn | |
const isBskyRefresh = (fn, ms) => { | |
const source = fn.toString(); | |
return source.includes(".updateSessionState()") && ms === 15e3; | |
}; | |
const addRefreshCallForPageVisible = (refreshFn) => { | |
document.addEventListener("visibilitychange", () => { | |
if (!document.hidden) { | |
try { | |
refreshFn(); | |
document.querySelector('[aria-label="Load new posts"]')?.click(); | |
} catch(error){ | |
console.error("[GM] refresh function call is falled", { | |
error | |
}) | |
} finally { | |
console.log("[GM] call auto refresh") | |
} | |
} | |
}); | |
}; | |
window.setInterval = (fn, ms) => { | |
if(isBskyRefresh(fn,ms)){ | |
addRefreshCallForPageVisible(fn); // when page is shown, call refresh function | |
} | |
origSetInterval.call(this, fn, ms); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment