jadefin/mods/Screenshot.js

73 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-03-01 21:01:22 +01:00
//@ts-check
import JadefinIntegrity from '../JadefinIntegrity.js';
import Jadefin from "../Jadefin.js";
import JadefinMod from "../JadefinMod.js";
import JadefinUtils from "../JadefinUtils.js";
export default JadefinIntegrity("Screenshot", import.meta.url, () => new (class Screenshot extends JadefinMod {
canvas = document.createElement("canvas");
constructor() {
super();
}
async init(name, url) {
await super.init(name, url);
const ExtrasMenu = /** @type {import("./ExtrasMenu.js").default} */ (Jadefin.getMod("ExtrasMenu"));
ExtrasMenu.items.push({
name: "Screenshot",
secondaryText: "Copy to clipboard",
icon: "camera",
in: ExtrasMenu.IN_MOVIE,
cb: () => {
this.copy();
}
});
}
copy() {
const video = JadefinUtils.video;
if (!video) {
this.log.e("No video");
return;
}
this.canvas.width = video.videoWidth;
this.canvas.height = video.videoHeight;
const ctx = this.canvas.getContext("2d");
if (!ctx) {
this.log.e("No 2D context");
return;
}
ctx.drawImage(video, 0, 0);
/*
const assCanvas = JadefinUtils.assCanvas;
if (assCanvas) {
ctx.drawImage(assCanvas, 0, 0);
}
*/
this.canvas.toBlob(blob => {
if (!blob) {
this.log.e("No blob");
return;
}
navigator.clipboard.write([
// @ts-ignore
new ClipboardItem({
[blob.type]: blob
})
]);
});
}
})());