-
Notifications
You must be signed in to change notification settings - Fork 1
/
paste.html
209 lines (175 loc) · 5.49 KB
/
paste.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<!DOCTYPE html>
<html>
<head>
<title>Discord CDN Preview Wrapper</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<style>
.me {
height: 90vh;
overflow: hidden;
}
body {
margin: 0;
padding: 0;
}
/* Dark mode */
@media (prefers-color-scheme: dark) {
body {
background-color: black;
color: white;
}
}
/* Light mode */
@media (prefers-color-scheme: light) {
body {
background-color: white;
color: black;
}
}
</style>
<link href="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/css/fontawesome.min.css"
rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/js/fontawesome.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@fortawesome/[email protected]/js/solid.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/min/vs/loader.js"></script>
</head>
<body>
<h1 id="filename">Previewer</h1>
<div style="display: none" id="contents">
<div class="toggles">
<input type="checkbox" id="toggleDarkTheme" onclick="toggleTheme(this)">
<label for="toggleDarkTheme">Use Dark Theme</label>
<input type="checkbox" id="toggleLineWrap" onclick="toggleLineWrap(this)">
<label for="toggleLineWrap">Wrap lines</label>
<input type="checkbox" id="toggleRenderer" onclick="toggleRenderer(this)">
<label for="toggleRenderer">Use Basic Render</label>
</div>
<br>
<div class="me" id="container"></div>
<div class="me" id="basicrender">
<label for="basicrenderbox"></label><textarea style="width: 90%;height: 90%" readonly
id="basicrenderbox"></textarea>
</div>
</div>
<div id="spinner">
<i class="fa-solid fa-spinner fa-2xl fa-spin"></i>
</div>
<script>
const container = document.getElementById('container')
let editor = undefined
let url = '/cdn' + window.location.pathname
const lightTheme = 'vs'
const darkTheme = 'vs-dark'
function setButtons () {
const theme = getTheme()
if (theme === darkTheme) {
document.getElementById('toggleDarkTheme').checked = true
}
if (localStorage.getItem('linewrap') === 'true') {
document.getElementById('toggleLineWrap').checked = true
}
if (localStorage.getItem('basicrender') === 'true') {
document.getElementById('toggleRenderer').checked = true
}
}
function toggleTheme (btn) {
localStorage.setItem('dark', btn.checked)
switchColorScheme()
}
function toggleLineWrap (btn) {
localStorage.setItem('linewrap', btn.checked)
switchLineWrap()
}
function toggleRenderer (btn) {
localStorage.setItem('basicrender', btn.checked)
switchRender()
}
function switchColorScheme () {
const th = getTheme()
monaco.editor.setTheme(getTheme())
if (th === lightTheme) {
document.getElementById('basicrenderbox').style.backgroundColor = 'white';
document.getElementById('basicrenderbox').style.color = 'black';
} else {
document.getElementById('basicrenderbox').style.backgroundColor = 'black';
document.getElementById('basicrenderbox').style.color = 'white';
}
}
function switchLineWrap () {
try {
if (localStorage.getItem('linewrap') === 'true') {
editor.updateOptions({ wordWrap: 'on' })
} else {
editor.updateOptions({ wordWrap: 'off' })
}
} catch (e) {
console.log(e)
}
}
function switchRender () {
if (localStorage.getItem('basicrender') === 'true') {
document.getElementById('container').style.display = 'none'
document.getElementById('basicrender').style.display = 'block'
} else {
document.getElementById('basicrender').style.display = 'none'
document.getElementById('container').style.display = 'block'
}
}
function getTheme () {
let theme = lightTheme
let fromStorage = localStorage.getItem('dark')
if (fromStorage !== '') {
if (fromStorage === 'true') {
theme = darkTheme
}
} else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
theme = darkTheme
}
return theme
}
function download (url) {
try {
const req = new XMLHttpRequest()
req.open('GET', url)
req.onload = () => {
if (req.readyState === req.DONE) {
if (req.status === 200) {
transferComplete(req)
}
}
}
req.send()
} catch (error) {
console.error(error)
//return 'Failed to get file'
}
}
function transferComplete (e) {
require.config({ paths: { vs: 'https://cdn.jsdelivr.net/npm/[email protected]/min/vs' } })
require(['vs/editor/editor.main'], function () {
editor = monaco.editor.create(container, {
value: 'Loading',
minimap: { enabled: false },
automaticLayout: true,
readOnly: true,
})
monaco.editor.setTheme(getTheme())
const model = monaco.editor.createModel(e.responseText, undefined, monaco.Uri.parse(url))
document.getElementById('basicrenderbox').value = e.responseText
editor.setModel(model)
console.log(`model language was changed to ${editor.getModel().getLanguageId()}`)
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', () => {
switchColorScheme()
})
switchColorScheme()
switchLineWrap()
setButtons()
switchRender()
document.getElementById('spinner').style.display = 'none'
document.getElementById('contents').style.display = 'block'
})
}
download(url)
</script>
</body>
</html>