Skip to content

Instantly share code, notes, and snippets.

@azu
Last active July 27, 2023 09:48

Revisions

  1. azu revised this gist Jul 27, 2023. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions Bluesky: auto refresh.user.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    // ==UserScript==
    // @name Bluesky: auto refresh
    // @namespace https://efcl.info
    // @match https://bsky.app/notifications
    // @match https://bsky.app/*
    // @grant none
    // @version 1.0
    // @author azu
    @@ -19,6 +19,7 @@ const addRefreshCallForPageVisible = (refreshFn) => {
    if (!document.hidden) {
    try {
    refreshFn();
    document.querySelector('[aria-label="Load new posts"]')?.click();
    } catch(error){
    console.error("[GM] refresh function call is falled", {
    error
    @@ -28,7 +29,7 @@ const addRefreshCallForPageVisible = (refreshFn) => {
    }
    }
    });
    }
    };
    window.setInterval = (fn, ms) => {
    if(isBskyRefresh(fn,ms)){
    addRefreshCallForPageVisible(fn); // when page is shown, call refresh function
  2. azu created this gist Jul 15, 2023.
    37 changes: 37 additions & 0 deletions Bluesky: auto refresh.user.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    // ==UserScript==
    // @name Bluesky: auto refresh
    // @namespace https://efcl.info
    // @match https://bsky.app/notifications
    // @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();
    } 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);
    };