Solving the problem of resetting heavy logic to one of many open tabs

    Not so long ago, I began to develop the DuelJS library, which provided a convenient interface for determining the status of the Master (active) or Slave (inactive) tab. However, later I began to receive suggestions for optimizing connections on web sockets. DuelJS approach: if the tab is active -> keep the connection, if inactive -> put - is not productive. The TabNinja extension comes to the rescue.

    New logic

    You can easily understand the old logic by looking at the screenshot below:

    TabNinja offers a new logic on top of the old one:

    The tab with the logic (also called superMaster) is always the same and always is. It changes only in one case - when you close this tab itself. In this case, the superMaster status automatically switches to another, oldest tab from the remaining tabs. The problem of excess connections is resolved.

    TabNinja essentially has one simple function:
    window.isSuperMaster(); // при использовании вместе с duel не путайте с window.isMaster()

    You can also use TabNinja without DuelJS, in which case you should use the file from the repository with the corresponding mark (tabninja.without_duel.min.js)

    Workflow Overview

    The TabNinja algorithm is quite simple and is based on localStorage + sessionStorage.
    1. If localStorage is unavailable, all tabs will be superMaster
    2. The current tab refers to the accident control variable in sessionStorage
    3. If there is no variable, the variable is set and the stack of active tabs is deleted
    4. The current tab refers to the stack of active tabs through localStorage
    5. If the stack of active tabs is empty - create a stack and put yourself there
    6. If someone is already on the stack of active tabs, then the main one is the first on the stack
    7. When closing a tab: pull it out of the stack

    useful links

    - DuelJS demo without TabNinja
    - DuelJS demo with TabNinja
    - TabNinja demo without DuelJS
    - TabNinja repository on GitHub
    - DuelJS repository on GitHub
    - Brief overview of DuelJS on readthedocs
    - DuelJS documentation on readthedocs
    - Topic picture taken from peopletinjt

    Submit your ideas for improving the DuelJS library here or in issues, thanks.
    I almost forgot: carefully look at the list of tested browsers in

    PS: Now I'm working on improving TabNinja's performance in Internet Explorer 11 - sometimes inappropriate behavior occurs that destroys tabNinja.

    Also popular now: