add share collection as text

This commit is contained in:
X4Lo committed 2025-02-15 22:44:07 +01:00
1 parent dbb00fdb61
commit 6b7cca1fe9
3 files changed
+45 -10

No files matched your search

@@ -32,7 +32,8 @@
</li>
<li><a class="dropdown-item" (click)="switchViewMode()">Switch View</a></li>
<li><a class="dropdown-item" (click)="deleteCollection()">Delete</a></li>
<li><a class="dropdown-item" (click)="shareScreenshot()">Share (as image)</a></li>
<li><a class="dropdown-item" (click)="shareScreenshot()">Share (Image)</a></li>
<li><a class="dropdown-item" (click)="copyTitles()">Share (Text)</a></li>
<li>
<a class="dropdown-item" *ngIf="!collection.isUserCollection" (click)="refreshCollection()">Refresh
Information
@@ -195,7 +195,7 @@ export class CollectionInfoPageComponent implements OnInit {
this.screenshotService
.capture('gridDiv')
.then((dataUrl) => {
this.copyToClipboard(dataUrl);
this.copyDataUrlToClipboard(dataUrl);
})
.catch((error) => {
console.error('Error capturing screenshot:', error);
@@ -205,7 +205,24 @@ export class CollectionInfoPageComponent implements OnInit {
this.viewMode = oldViewMode;
}
private copyToClipboard(dataUrl: string) {
async copyTitles() {
let str = `${this.collection.name}: \n`;
await this.collection.entries.forEach((entry) => {
const year = new Date(entry.release_date).getFullYear();
if (entry.is_tvseries) {
str += `${entry.title} (${year} - Seasons: ${
entry.seasons.length
})\n`;
} else {
str += `${entry.title} (${year})\n`;
}
});
this.copyTextToClipboard(str);
}
private copyDataUrlToClipboard(dataUrl: string) {
const img = new Image();
img.src = dataUrl;
const canvas = document.createElement('canvas');
@@ -221,6 +238,23 @@ export class CollectionInfoPageComponent implements OnInit {
};
}
private async copyTextToClipboard(text: string): Promise<void> {
try {
// Create a Blob from the text
const blob = new Blob([text], { type: 'text/plain' });
// Create a ClipboardItem with the Blob
const item = new ClipboardItem({ 'text/plain': blob });
// Write the item to the clipboard
await navigator.clipboard.write([item]);
//console.log('Text copied to clipboard successfully!');
} catch (error) {
console.error('Failed to copy text to clipboard:', error);
}
}
refreshCollection() {
this.collectionService.refreshCollection(this.collection.id).subscribe({
next: (data) => {