add content copy, fix #280

This commit is contained in:
Nicolas Constant 2020-05-17 16:51:51 -04:00
parent 6a7d389b55
commit c14009692f
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 31 additions and 1 deletions

View File

@ -11,6 +11,9 @@
<ng-template contextMenuItem (execute)="copyStatusLink()" *ngIf="statusWrapper">
Copy link to status
</ng-template>
<ng-template contextMenuItem (execute)="copyAllData()" *ngIf="statusWrapper">
Copy all data
</ng-template>
<ng-template contextMenuItem divider="true" *ngIf="statusWrapper"></ng-template>
<ng-template contextMenuItem (execute)="mentionAccount()" *ngIf="!isOwnerSelected">
Mention @{{ this.username }}

View File

@ -75,7 +75,7 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
private checkStatus(accounts: AccountInfo[]): void {
const selectedAccount = accounts.find(x => x.isSelected);
this.isOwnerSelected = selectedAccount.username.toLowerCase() === this.displayedStatus.account.username.toLowerCase()
&& selectedAccount.instance.toLowerCase() === this.displayedStatus.account.url.replace('https://', '').split('/')[0].toLowerCase();
}
@ -118,6 +118,33 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
return false;
}
copyAllData(): boolean {
const newLine = String.fromCharCode(13, 10);
let selBox = document.createElement('textarea');
selBox.style.position = 'fixed';
selBox.style.left = '0';
selBox.style.top = '0';
selBox.style.opacity = '0';
selBox.value = `${this.displayedStatus.url}${newLine}${newLine}${this.displayedStatus.content}${newLine}${newLine}`;
let parser = new DOMParser();
var dom = parser.parseFromString(this.displayedStatus.content, 'text/html')
selBox.value += `${dom.body.textContent}${newLine}${newLine}`;
for (const att of this.displayedStatus.media_attachments) {
selBox.value += `${att.url}${newLine}${newLine}`;
}
document.body.appendChild(selBox);
selBox.focus();
selBox.select();
document.execCommand('copy');
document.body.removeChild(selBox);
return false;
}
mentionAccount(): boolean {
this.navigationService.replyToUser(this.fullHandle, false);
return false;