From c14009692f40964f637b119af2c5ce3df2bd8966 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sun, 17 May 2020 16:51:51 -0400 Subject: [PATCH] add content copy, fix #280 --- .../status-user-context-menu.component.html | 3 ++ .../status-user-context-menu.component.ts | 29 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/app/components/stream/status/action-bar/status-user-context-menu/status-user-context-menu.component.html b/src/app/components/stream/status/action-bar/status-user-context-menu/status-user-context-menu.component.html index 7dc20c38..f58473a2 100644 --- a/src/app/components/stream/status/action-bar/status-user-context-menu/status-user-context-menu.component.html +++ b/src/app/components/stream/status/action-bar/status-user-context-menu/status-user-context-menu.component.html @@ -11,6 +11,9 @@ Copy link to status + + Copy all data + Mention @{{ this.username }} diff --git a/src/app/components/stream/status/action-bar/status-user-context-menu/status-user-context-menu.component.ts b/src/app/components/stream/status/action-bar/status-user-context-menu/status-user-context-menu.component.ts index 05098ade..a726539b 100644 --- a/src/app/components/stream/status/action-bar/status-user-context-menu/status-user-context-menu.component.ts +++ b/src/app/components/stream/status/action-bar/status-user-context-menu/status-user-context-menu.component.ts @@ -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;