Skip to content
  • Categories
  • Recent
  • Groups
  • Users
  • Tags
  • Popular
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Lumen)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Categories
  3. Web Development
  4. How the new countdown timer works

How the new countdown timer works

Scheduled Pinned Locked Moved Web Development
20 Posts 5 Posters 916 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • VGMooseV Offline
    VGMooseV Offline
    VGMoose
    Admin
    wrote on last edited by VGMoose
    #1

    Here is the code for the countdown timer that displays on this site on Switch consoles!

    It uses the localStorage property of the browser to store the start time and date when the page is first visited. This occurs right after the DNS connects, when using browseDNS. Then it calculates the difference between the current time and the start time, subtracts that from 20 minutes, then displays it.

    function startTimer() {
        // check if a start time has been previously noted
        if (window.localStorage.getItem('startTime') == null) {
            // Local storage isn't persisted between sessions, so if we don't have
            // a start time, we're likely in a new session. Set the start time to now.
            window.localStorage.setItem('startTime', new Date().getTime());
        }
        // grab that start time
        var startTime = window.localStorage.getItem('startTime');
    
        // and the current time
        var presentTime = new Date().getTime()
    
        // calculate the difference between the two, and that's how long our session has been
        var diff = presentTime - startTime;
    
        // 20 minutes is 1200000 milliseconds (20 * 60 * 1000)
        var maxSessionLength = 1200000;
    
        // subtract the time difference from the max session length to get the remaining time
        var timeRemaining = maxSessionLength - diff;
    
        // if the remaining time is negative, just set it to 0
        if (timeRemaining < 0) {
            timeRemaining = 0;
        }
    
        // convert the remaining time to minutes and seconds
        var minutes = Math.floor((timeRemaining % (1000 * 60 * 60)) / (1000 * 60));
        var seconds = Math.floor((timeRemaining % (1000 * 60)) / 1000);
    
        // update the display span with the remaining time, and pad the seconds with a 0 if needed
        document.getElementById("timer").innerHTML = minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
    }
    
    // run the timer logic once, and then repeat every second (1000 ms)
    startTimer();
    setInterval(startTimer, 1000);
    

    This function runs every 1000ms (that's what setInterval does). When it hits 0, nothing actually happens, but after the browser does time out, the localStorage info is wiped, and the countdown will start fresh on the next launch.

    Since it uses the wall time, this will persist across other sites on the Internet upon returning to browsedns. However, this also means it will become inaccurate when sleeping the console, leaving, and returning, which does not tick down Nintendo's counter.

    Sign the petition! Help us figure out the browser timeout.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      I think this is a great feature to have. Itll help whenever i'm typing a long post so then ik if im ablut to get kicked (bc im sure all of us switch users have had experiences where we were typing a long post and then we got kicked)

      Thank you for the feature! :)

      1 Reply Last reply
      0
      • VGMooseV Offline
        VGMooseV Offline
        VGMoose
        Admin
        wrote on last edited by
        #3

        Thanks! We want to have the main landing page a bit more useful too besides Google/URL bars, kind of like mini-bookmarks like on Switchbru, but we've been slow at getting there

        Sign the petition! Help us figure out the browser timeout.

        lollapaloozaL 1 Reply Last reply
        0
        • VGMooseV VGMoose

          Thanks! We want to have the main landing page a bit more useful too besides Google/URL bars, kind of like mini-bookmarks like on Switchbru, but we've been slow at getting there

          lollapaloozaL Offline
          lollapaloozaL Offline
          lollapalooza
          Global Mod
          wrote on last edited by
          #4

          @VGMoose maybe like another burger menu?

          \'-'/
          free-palestine.carrd.co
          veteran member and moderator
          Ash Ketchum・1997-2023

          1 Reply Last reply
          0
          • pwsincdP Offline
            pwsincdP Offline
            pwsincd
            Admin
            wrote on last edited by
            #5

            ?

            "Don’t waste your words I don’t need anything from you / I don’t care where you’ve been or what you plan to do." - Ian Brown

            lollapaloozaL 1 Reply Last reply
            0
            • pwsincdP pwsincd

              ?

              lollapaloozaL Offline
              lollapaloozaL Offline
              lollapalooza
              Global Mod
              wrote on last edited by
              #6

              @pwsincd those menus with the 3 horizontal lines
              i thought that was a common term

              \'-'/
              free-palestine.carrd.co
              veteran member and moderator
              Ash Ketchum・1997-2023

              1 Reply Last reply
              0
              • pwsincdP Offline
                pwsincdP Offline
                pwsincd
                Admin
                wrote on last edited by
                #7

                lol i mean ? to the another burger menu .. meaning what do u mean

                "Don’t waste your words I don’t need anything from you / I don’t care where you’ve been or what you plan to do." - Ian Brown

                lollapaloozaL 1 Reply Last reply
                0
                • pwsincdP pwsincd

                  lol i mean ? to the another burger menu .. meaning what do u mean

                  lollapaloozaL Offline
                  lollapaloozaL Offline
                  lollapalooza
                  Global Mod
                  wrote on last edited by lollapalooza
                  #8

                  @pwsincd im pretty sure on mobile theres one in the left corner of the screen.
                  i visit mostly on switch or pc so i could be remembering wrongly

                  \'-'/
                  free-palestine.carrd.co
                  veteran member and moderator
                  Ash Ketchum・1997-2023

                  1 Reply Last reply
                  0
                  • pwsincdP Offline
                    pwsincdP Offline
                    pwsincd
                    Admin
                    wrote on last edited by
                    #9

                    i am still missing the pioint , i mean whats in this burger menu ?

                    "Don’t waste your words I don’t need anything from you / I don’t care where you’ve been or what you plan to do." - Ian Brown

                    lollapaloozaL 1 Reply Last reply
                    0
                    • pwsincdP pwsincd

                      i am still missing the pioint , i mean whats in this burger menu ?

                      lollapaloozaL Offline
                      lollapaloozaL Offline
                      lollapalooza
                      Global Mod
                      wrote on last edited by
                      #10

                      @pwsincd bookmarks like the switchbru ones that are easy to access without dampening the forum-y vibe

                      \'-'/
                      free-palestine.carrd.co
                      veteran member and moderator
                      Ash Ketchum・1997-2023

                      1 Reply Last reply
                      0
                      • VGMooseV Offline
                        VGMooseV Offline
                        VGMoose
                        Admin
                        wrote on last edited by
                        #11

                        kind of subtle but we do have this "Links" drop down: Screenshot 2022-12-30 at 4.58.46 PM.png, no way to customize the content inside though

                        Sign the petition! Help us figure out the browser timeout.

                        lollapaloozaL 1 Reply Last reply
                        0
                        • pwsincdP Offline
                          pwsincdP Offline
                          pwsincd
                          Admin
                          wrote on last edited by
                          #12

                          yeah we can add links galore ... put a list together

                          "Don’t waste your words I don’t need anything from you / I don’t care where you’ve been or what you plan to do." - Ian Brown

                          1 Reply Last reply
                          0
                          • VGMooseV VGMoose

                            kind of subtle but we do have this "Links" drop down: Screenshot 2022-12-30 at 4.58.46 PM.png, no way to customize the content inside though

                            lollapaloozaL Offline
                            lollapaloozaL Offline
                            lollapalooza
                            Global Mod
                            wrote on last edited by
                            #13

                            @VGMoose i used that bar to join the 4TU discord then never again

                            \'-'/
                            free-palestine.carrd.co
                            veteran member and moderator
                            Ash Ketchum・1997-2023

                            1 Reply Last reply
                            0
                            • DottaD Offline
                              DottaD Offline
                              Dotta
                              cool ppl!😎 chat-perms artist's.. uk ppl Switchbru ∀ Chainsaw Man ∀
                              wrote on last edited by
                              #14

                              I love the addition but it would be cool to see it on switchbru

                              Omori is a very cool game

                              1 Reply Last reply
                              2
                              • ? Offline
                                ? Offline
                                A Former User
                                wrote on last edited by
                                #15

                                Just noticed that switchbru has a timer now, that's cool!

                                1 Reply Last reply
                                0
                                • VGMooseV Offline
                                  VGMooseV Offline
                                  VGMoose
                                  Admin
                                  wrote on last edited by
                                  #16

                                  Yes! I just added that. Let me know how they both go, I've already noticed if you visit both sites you'll mess up one of the two timers (since they don't really keep track, just each independently count down from 20 min).

                                  Technically we could make it smarter and try to guess about the actual session, using this info. This would be a server side endpoint that counts how many of those "every second" requests have been made so far, and when it hits 600, it will close.

                                  Sign the petition! Help us figure out the browser timeout.

                                  lollapaloozaL 1 Reply Last reply
                                  0
                                  • VGMooseV VGMoose

                                    Yes! I just added that. Let me know how they both go, I've already noticed if you visit both sites you'll mess up one of the two timers (since they don't really keep track, just each independently count down from 20 min).

                                    Technically we could make it smarter and try to guess about the actual session, using this info. This would be a server side endpoint that counts how many of those "every second" requests have been made so far, and when it hits 600, it will close.

                                    lollapaloozaL Offline
                                    lollapaloozaL Offline
                                    lollapalooza
                                    Global Mod
                                    wrote on last edited by
                                    #17

                                    @VGMoose as a switchbru user, thank you so much.

                                    \'-'/
                                    free-palestine.carrd.co
                                    veteran member and moderator
                                    Ash Ketchum・1997-2023

                                    1 Reply Last reply
                                    0
                                    • VGMooseV Offline
                                      VGMooseV Offline
                                      VGMoose
                                      Admin
                                      wrote on last edited by
                                      #18

                                      Already got some feedback from the Switchbru user survey:

                                      Why is there a 20 minute timer on the homepage? Is it when it automatically kicks me out when it hits zero?

                                      I mean, the answer is yes, but this is explained on the landing page too. Changed the wording a little to make it more clear.

                                      Sign the petition! Help us figure out the browser timeout.

                                      1 Reply Last reply
                                      0
                                      • DottaD Offline
                                        DottaD Offline
                                        Dotta
                                        cool ppl!😎 chat-perms artist's.. uk ppl Switchbru ∀ Chainsaw Man ∀
                                        wrote on last edited by
                                        #19

                                        Not to be a pain, of course the admins have done a great job with the timer but would it be possible to have it appear in one corner sorta like FPS in games?
                                        A bit like this:

                                        Screenshot (15).jpg

                                        Omori is a very cool game

                                        1 Reply Last reply
                                        0
                                        • VGMooseV Offline
                                          VGMooseV Offline
                                          VGMoose
                                          Admin
                                          wrote on last edited by
                                          #20

                                          Do you mean over other websites? It's not possible unfortunately. Depending on the site, it may be possible to display it within an iframe, but not all sites support this.

                                          Sign the petition! Help us figure out the browser timeout.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Groups
                                          • Users
                                          • Tags
                                          • Popular