From bbd4a20284dfd874cee0a9d2d10ff4d8d1f6c8de Mon Sep 17 00:00:00 2001 From: Mathium05 Date: Tue, 28 Jul 2026 22:17:38 -0500 Subject: [PATCH] copy media URL --- src/webpage/file.ts | 21 +++++++++++++++++++++ translations/en.json | 1 + 2 files changed, 22 insertions(+) diff --git a/src/webpage/file.ts b/src/webpage/file.ts index 710ffe5..fecca48 100644 --- a/src/webpage/file.ts +++ b/src/webpage/file.ts @@ -4,6 +4,7 @@ import {ImagesDisplay} from "./disimg.js"; import {makePlayBox, MediaPlayer} from "./media.js"; import {I18n} from "./i18n.js"; import {createImg} from "./utils/utils.js"; +import {Contextmenu} from "./contextmenu.js"; class File { readonly owner: Message | null; id: string; @@ -15,6 +16,22 @@ class File { url: string; size: number; files?: File[]; + static menu = this.makeMenu(); + static makeMenu() { + const menu = new Contextmenu("", true); + I18n.done.then(() => { + menu.addButton( + I18n.copyMedia(), + function () { + navigator.clipboard.writeText(this.url); + }, + { + group: "copyLink", + }, + ); + }); + return menu; + } constructor(fileJSON: filejson, owner: Message | null) { this.owner = owner; this.id = fileJSON.id; @@ -128,6 +145,7 @@ class File { div.append(makeSpoilerHTML()); } } + File.menu.bindContextmenu(div, this); return div; } else if (this.content_type.startsWith("video/")) { const video = document.createElement("video"); @@ -150,18 +168,21 @@ class File { div.append(video, makeSpoilerHTML()); return div; } + File.menu.bindContextmenu(video, this); return video; } else if (this.content_type.startsWith("audio/") || this.content_type === "application/ogg") { const a = this.getAudioHTML(url); if (OSpoiler) { a.append(makeSpoilerHTML()); } + File.menu.bindContextmenu(a, this); return a; } else { const uk = this.createunknown(url); if (OSpoiler) { uk.append(makeSpoilerHTML()); } + File.menu.bindContextmenu(uk, this); return uk; } } diff --git a/translations/en.json b/translations/en.json index 3316790..543c69d 100644 --- a/translations/en.json +++ b/translations/en.json @@ -29,6 +29,7 @@ "enable":"Enable onboarding", "title":"Welcome to $1!" }, + "copyMedia":"Copy media URL", "DMs": { "add": "Add someone to this DM", "close": "Close DM",