Mercurial Hosting > disearch
diff src/lib/Shared.luan @ 16:552d6f944acb
add bump
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 01 Nov 2023 17:34:15 -0600 |
parents | 80105b716a62 |
children | b386303be994 |
line wrap: on
line diff
--- a/src/lib/Shared.luan Wed Nov 01 00:12:08 2023 -0600 +++ b/src/lib/Shared.luan Wed Nov 01 17:34:15 2023 -0600 @@ -1,5 +1,6 @@ local Luan = require "luan:Luan.luan" local error = Luan.error +local ipairs = Luan.ipairs or error() local Time = require "luan:Time.luan" local Parsers = require "luan:Parsers.luan" local json_string = Parsers.json_string or error() @@ -33,6 +34,7 @@ <script>document.write(`<img src="https://cdn.discordapp.com/avatars/${localStorage.user_id}/${localStorage.user_avatar}.png" onclick="clickMenu(this)">`)</script> <div pulldown_menu> <span username><script>document.write(localStorage.user_name)</script></span> + <a href="/bump.html">Bump Servers</a> <a href="/servers.html">Your Servers</a> <a href="javascript:logout()">Log out</a> </div> @@ -68,4 +70,42 @@ <% end +local times = { + { + time = 1000*60*60*24*365 + unit = "year" + } + { + time = 1000*60*60*24*7 + unit = "week" + } + { + time = 1000*60*60*24 + unit = "day" + } + { + time = 1000*60*60 + unit = "hour" + } + { + time = 1000*60 + unit = "minute" + } +} + +function Shared.ago(time) + for _, t in ipairs(times) do + local n = time // t.time + if n > 0 then + %><%=n%> <%=t.unit%><% + if n > 1 then + %>s<% + end + %> ago<% + return + end + end + %>just now<% +end + return Shared