-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: simplify/shorten html wrappers
- Loading branch information
Showing
2 changed files
with
70 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,58 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{host} - no bs pastebin</title> | ||
<meta name="description" content="{host} - no bs command line pastebin"> | ||
<style> | ||
@font-face {{ | ||
font-family: 'IBM Plex Mono'; | ||
src: url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff2') format('woff2'), | ||
url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff') format('woff'); | ||
font-weight: normal; | ||
font-style: normal; | ||
font-display: swap; | ||
<head> | ||
<title>{host} - no bs pastebin</title> | ||
<meta name="description" content="{host} - no bs command line pastebin"> | ||
<style> | ||
@font-face {{ | ||
font-family: 'IBM Plex Mono'; font-weight: normal; font-style: normal; font-display: swap; | ||
src: url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff2') format('woff2'), | ||
url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff') format('woff'); }} | ||
body {{ font-family: 'IBM Plex Mono', monospace; font-size: 1em; color: #f4f4f4; background: #0b0b0b; }} | ||
pre {{ max-width: 73ch; margin: 0 auto; }} | ||
a {{ color: #78a9ff; }} | ||
</style> | ||
<script nonce="{nonce}"> | ||
// Upload a file and return the url | ||
async function upload(data, name = "") {{ | ||
const uploadUrl = `/${{name}}`; | ||
try {{ | ||
const response = await fetch(uploadUrl, {{ | ||
method: 'PUT', | ||
body: data | ||
}}); | ||
const responseBody = await response.text(); | ||
return response.ok | ||
? `<a href="${{responseBody}}" target="_blank">${{responseBody}}</a>` | ||
: `Failed to upload "${{uploadUrl}}": ${{response.statusText}}`; | ||
}} catch (error) {{ | ||
return `Error uploading "${{uploadUrl}}": ${{error.message}}`; | ||
}} | ||
body {{ | ||
color: #f4f4f4; | ||
background: #0b0b0b; | ||
font-family: 'IBM Plex Mono', monospace; | ||
font-size: 1em; | ||
}} | ||
// Listen for ctrl/cmd + V | ||
document.addEventListener('paste', async (event) => {{ | ||
const preElement = document.querySelector('pre'); | ||
preElement.innerHTML = "Uploading..."; | ||
const text = event.clipboardData.getData("text"); | ||
if (text) {{ | ||
preElement.innerHTML = await upload(text); | ||
return; | ||
}} | ||
pre {{ | ||
max-width: 73ch; | ||
margin: 0 auto; | ||
}} | ||
a {{ color: #78a9ff; }} | ||
</style> | ||
<script nonce="{nonce}"> | ||
// Upload a file and return the url | ||
async function upload(data, name = "") {{ | ||
const uploadUrl = `/${{name}}`; | ||
try {{ | ||
const response = await fetch(uploadUrl, {{ | ||
method: 'PUT', | ||
body: data | ||
}}); | ||
const responseBody = await response.text(); | ||
return response.ok | ||
? `<a href="${{responseBody}}" target="_blank">${{responseBody}}</a>` | ||
: `Failed to upload "${{uploadUrl}}": ${{response.statusText}}`; | ||
}} catch (error) {{ | ||
return `Error uploading "${{uploadUrl}}": ${{error.message}}`; | ||
}} | ||
}} | ||
|
||
// Listen for ctrl/cmd + V | ||
document.addEventListener('paste', async (event) => {{ | ||
const preElement = document.querySelector('pre'); | ||
preElement.innerHTML = "Uploading..."; | ||
const text = event.clipboardData.getData("text"); | ||
if (text) {{ | ||
preElement.innerHTML = await upload(text); | ||
return; | ||
}} | ||
const responses = await Promise.all([...event.clipboardData.items] | ||
.filter(item => item.kind === 'file') | ||
.map(async item => {{ | ||
const file = item.getAsFile(); | ||
if (!file) | ||
return `Error reading from clipboard`; | ||
return await upload(file, file.name) | ||
}}) | ||
); | ||
preElement.innerHTML = responses.join('\n'); | ||
}}); | ||
|
||
|
||
// Replace urls with links on page load | ||
document.addEventListener('DOMContentLoaded', () => {{ | ||
const preElement = document.querySelector('pre'); | ||
preElement.innerHTML = preElement.innerHTML.replace(/((https:)[^\s]+[\w])/g, '<a href="$1" target="_blank">$1</a>'); | ||
}}, false); | ||
</script> | ||
</head> | ||
<body> | ||
<pre>{body}</pre> | ||
</body> | ||
</html> | ||
const responses = await Promise.all([...event.clipboardData.items] | ||
.filter(item => item.kind === 'file') | ||
.map(async item => {{ | ||
const file = item.getAsFile(); | ||
if (!file) | ||
return `Error reading from clipboard`; | ||
return await upload(file, file.name) | ||
}}) | ||
); | ||
preElement.innerHTML = responses.join('\n'); | ||
}}); | ||
// Replace urls with links on page load | ||
document.addEventListener('DOMContentLoaded', () => {{ | ||
const preElement = document.querySelector('pre'); | ||
preElement.innerHTML = preElement.innerHTML.replace(/((https:)[^\s]+[\w])/g, '<a href="$1" target="_blank">$1</a>'); | ||
}}, false); | ||
</script> | ||
</head> | ||
<body><pre>{body}</pre></body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>{host} - privacy policy</title> | ||
<meta name="description" content="{host} privacy policy"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/ibm-plex-mono.min.css"> | ||
<style> | ||
body {{ | ||
color: #f4f4f4; | ||
background: #0b0b0b; | ||
}} | ||
pre {{ | ||
font-family: 'IBM Plex Mono', monospace; | ||
font-size: 1em; | ||
max-width: 73ch; | ||
margin: 0 auto; | ||
}} | ||
</style> | ||
</head> | ||
<body> | ||
<pre>{body}</pre> | ||
</body> | ||
</html> | ||
<head> | ||
<title>{host} - privacy policy</title> | ||
<meta name="description" content="{host} privacy policy"> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/ibm-plex-mono.min.css"> | ||
<style> | ||
@font-face {{ | ||
font-family: 'IBM Plex Mono'; font-weight: normal; font-style: normal; font-display: swap; | ||
src: url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff2') format('woff2'), | ||
url('https://cdn.jsdelivr.net/npm/@xz/fonts@1/serve/src/ibm-plex-mono/IBMPlexMono.woff') format('woff'); }} | ||
body {{ font-family: 'IBM Plex Mono', monospace; font-size: 1em; color: #f4f4f4; background: #0b0b0b; }} | ||
pre {{ max-width: 73ch; margin: 0 auto; }} | ||
a {{ color: #78a9ff; }} | ||
</style> | ||
</head> | ||
<body><pre>{body}</pre></body> |