-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex.html
137 lines (131 loc) · 4.65 KB
/
Index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<title>Outline Access Key Generator</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
font-family: Arial, sans-serif;
background-color: #fafafa;
padding: 20px;
}
</style>
</head>
<body>
<my-app></my-app>
<script type="module">
// import { LitElement, html, css } from 'https://unpkg.com/lit-element/lit-element.js?module';
import {LitElement, html, css} from 'https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js';
class MyApp extends LitElement {
static properties = {
email: {type: String},
accessKey: {type: String},
bytes30d: {type: Number},
_agreesToTOS: {type: Boolean, state: true},
_copied: {type: Boolean, state: true},
};
static styles = css`
h1, h2 {
color: #333;
overflow-wrap: break-word;
}
p {
color: #666;
}
input[type="checkbox"] {
margin-right: 10px;
}
button {
background-color: #4CAF50;
color: white;
border: none;
padding: 10px 20px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 5px 2px;
cursor: pointer;
border-radius: 4px;
}
button:disabled {
background-color: #cccccc;
}
.container {
background-color: white;
word-break: break-word;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 8px;
padding: 5px;
width: fit-content;
}
.row {
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.block {
display: block;
}
.pad {
padding: 15px;
max-width: 400px;
}
.copied {
margin: 10px;
}
.qr {
max-height: 200px;
max-width: 200px;
}
`;
render() {
return html`
<h1>My Free Outline Server</h1>
<p>Welcome!</p>
<p>Each key can only be used in one device, since they get regenerated on connection.
Please create one key for each of your devices. If you would like to share access,
please send your friends to <code>https://my.freeoutlineserver.net</code>.</p>
${this.accessKey ?
html`
<h2>Your Access Key</h2>
<div class="container row"
><div class="pad">
<code class='block'><a target="_blank" href=${this.accessKey}>${this.accessKey}</a></code>
<br>
<button @click="${this.copyAccessKey}">Copy Access Key</button><span class="copied" ?hidden=${!this._copied}>Copied!</span>
</div
><img class="qr" src="https://chart.googleapis.com/chart?cht=qr&chs=200x200&chl=${encodeURIComponent(this.accessKey)}" alt="QR code">
</div>`
:
html`<p><input type="checkbox" @change="${(e) => this._agreesToTOS = e.target.checked}" .checked="${this._agreesToTOS}"></input>I agree to not abuse the server with illegal activity or unfair bandwidth usage</p>
<button ?disabled="${!this._agreesToTOS}" @click="${this.generateKey}">Create Access Key</button>`
}
`;
}
copyAccessKey() {
navigator.clipboard.writeText(this.accessKey).then(() => this._copied = true);
}
generateKey() {
google.script.run.withSuccessHandler((key) => {this.accessKey = key}).createDeviceKey();
}
}
customElements.define('my-app', MyApp);
async function writeToClipboard(text) {
return navigator.clipboard.writeText(text)
}
function formatBytes(num) {
if (num < 1024) {
return num + ' B';
} else if (num < 1024 * 1024) {
return (num / 1024).toFixed(1) + ' KB';
} else if (num < 1024 * 1024 * 1024) {
return (num / 1024 / 1024).toFixed(1) + ' MB';
} else {
return (num / 1024 / 1024 / 1024).toFixed(1) + ' GB';
}
}
</script>
</body>
</html>