1
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
16
|
3 local ipairs = Luan.ipairs or error()
|
1
|
4 local Time = require "luan:Time.luan"
|
12
|
5 local Parsers = require "luan:Parsers.luan"
|
|
6 local json_string = Parsers.json_string or error()
|
4
|
7 local Http = require "luan:http/Http.luan"
|
13
|
8 local Utils = require "site:/lib/Utils.luan"
|
|
9 local get_user = Utils.get_user or error()
|
1
|
10
|
|
11
|
|
12 local Shared = {}
|
|
13
|
|
14 local started = Time.now()
|
|
15
|
|
16 function Shared.head()
|
|
17 %>
|
|
18 <meta name="viewport" content="width=device-width, initial-scale=1">
|
|
19 <style>
|
|
20 @import "/site.css?s=<%=started%>";
|
|
21 </style>
|
4
|
22 <script src="/site.js?s=<%=started%>"></script>
|
1
|
23 <%
|
|
24 end
|
|
25
|
|
26 function Shared.header()
|
|
27 %>
|
|
28 <div header>
|
2
|
29 <h1><a href="/">Disearch</a></h1>
|
4
|
30 <% if get_user() == nil then %>
|
5
|
31 <a href="login1.red">login</a>
|
4
|
32 <% else %>
|
9
|
33 <span right pulldown>
|
|
34 <script>document.write(`<img src="https://cdn.discordapp.com/avatars/${localStorage.user_id}/${localStorage.user_avatar}.png" onclick="clickMenu(this)">`)</script>
|
|
35 <div pulldown_menu>
|
|
36 <span username><script>document.write(localStorage.user_name)</script></span>
|
16
|
37 <a href="/bump.html">Bump Servers</a>
|
11
|
38 <a href="/servers.html">Your Servers</a>
|
9
|
39 <a href="javascript:logout()">Log out</a>
|
|
40 </div>
|
|
41 </span>
|
4
|
42 <% end %>
|
1
|
43 </div>
|
|
44 <hr>
|
|
45 <%
|
|
46 end
|
|
47
|
|
48 function Shared.footer()
|
|
49 %>
|
|
50 <hr>
|
|
51 <div footer>
|
|
52 something or other in the footer
|
|
53 </div>
|
|
54 <%
|
|
55 end
|
|
56
|
14
|
57 local function base_url()
|
6
|
58 local request = Http.request
|
14
|
59 return request.scheme.."://"..request.headers["Host"]
|
|
60 end
|
|
61 Shared.base_url = base_url
|
|
62
|
|
63 function Shared.discord_redirect_uri()
|
|
64 return base_url().."/login2.html"
|
6
|
65 end
|
|
66
|
12
|
67 function Shared.js_error(field,message)
|
|
68 %>
|
|
69 showError( context.form, '<%=field%>', <%=json_string(message)%> );
|
|
70 <%
|
|
71 end
|
|
72
|
16
|
73 local times = {
|
|
74 {
|
|
75 time = 1000*60*60*24*365
|
|
76 unit = "year"
|
|
77 }
|
|
78 {
|
|
79 time = 1000*60*60*24*7
|
|
80 unit = "week"
|
|
81 }
|
|
82 {
|
|
83 time = 1000*60*60*24
|
|
84 unit = "day"
|
|
85 }
|
|
86 {
|
|
87 time = 1000*60*60
|
|
88 unit = "hour"
|
|
89 }
|
|
90 {
|
|
91 time = 1000*60
|
|
92 unit = "minute"
|
|
93 }
|
|
94 }
|
|
95
|
|
96 function Shared.ago(time)
|
|
97 for _, t in ipairs(times) do
|
|
98 local n = time // t.time
|
|
99 if n > 0 then
|
|
100 %><%=n%> <%=t.unit%><%
|
|
101 if n > 1 then
|
|
102 %>s<%
|
|
103 end
|
|
104 %> ago<%
|
|
105 return
|
|
106 end
|
|
107 end
|
|
108 %>just now<%
|
|
109 end
|
|
110
|
1
|
111 return Shared
|