Skip to content

Commit

Permalink
fix: text file web paste
Browse files Browse the repository at this point in the history
  • Loading branch information
ozwaldorf committed Oct 14, 2024
1 parent 6a2331a commit 9ed7618
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@
body {{
color: #f4f4f4;
background: #0b0b0b;
}}
pre {{
font-family: 'IBM Plex Mono', monospace;
font-size: 1em;
}}
pre {{
max-width: 73ch;
margin: 0 auto;
}}
</style>
<script nonce="{nonce}">
document.addEventListener('paste', async (event) => {{
const preElement = document.querySelector('pre');
// Handle text data
const text = event.clipboardData.getData("text");
if (text) {{
preElement.innerHTML = `<a href=${{text}}>${{text}}</a>`;
return;
}}
// Or handle files
const responses = await Promise.all([...event.clipboardData.items]
.filter(item => item.kind === 'file' || item.kind === 'string')
.map(async item => {{
const file = item.getAsFile();
const uploadUrl = `/${{file.name}}`;
const file = item.getAsFile() || item.getAsString();
if (!file)
return `Error reading from clipboard`;
const uploadUrl = `/${{typeof file === "object" ? file.name : "" }}`;
try {{
const response = await fetch(uploadUrl, {{
method: 'PUT',
Expand Down

0 comments on commit 9ed7618

Please sign in to comment.