From e637d8e806d24bcdccd0ab713382751b6e99e70d Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Sun, 2 Mar 2025 11:39:01 -0600 Subject: [PATCH] Add copy button to Star Wars Style Journal - Added a copy button to the Star Wars Style Journal sheet. - The copy button allows users to easily copy the content of the journal to their clipboard. - A notification is displayed upon successful copying. --- src/module.json | 3 ++- src/scripts/journalSheets.js | 33 +++++++++++++++++++++++++++++ src/styles/asc-starwars-journal.css | 7 ++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/module.json b/src/module.json index ee2f0d6..44f0454 100644 --- a/src/module.json +++ b/src/module.json @@ -1,13 +1,14 @@ { "id": "asc-starwars-style-journal", "title": "Star Wars Style Journal", - "version": "0.3.1", + "version": "0.4", "download": "https://gitea.ascorrea.com/asc/asc-starwars-style-journal/releases/download/latest/module.zip", "manifest": "https://gitea.ascorrea.com/asc/asc-starwars-style-journal/releases/download/latest/module.json", "compatibility": { "minimum": "12", "verified": "12" }, + "scripts": ["scripts/vendor/turndown.js"], "esmodules": ["scripts/asc-starwars.js"], "styles": [ "styles/asc-ffg-starwars.css", diff --git a/src/scripts/journalSheets.js b/src/scripts/journalSheets.js index 13de1a1..c666c4c 100644 --- a/src/scripts/journalSheets.js +++ b/src/scripts/journalSheets.js @@ -1,3 +1,5 @@ +var turndownService = new TurndownService() + export class StarWarsStyleJournalSheet extends JournalSheet { static get defaultOptions() { return mergeObject(super.defaultOptions, { @@ -7,6 +9,8 @@ export class StarWarsStyleJournalSheet extends JournalSheet { async _render(force, options) { await super._render(force, {...options, collapsed:true}); } + + } export class StarWarsTextPageSheet extends JournalTextPageSheet { @@ -18,4 +22,33 @@ export class StarWarsTextPageSheet extends JournalTextPageSheet { resizable: true, }); } + activateListeners(html) { + super.activateListeners(html); + // Ensure the button is not duplicated + if (html.find(".asc-copy-button").length > 0) return; + + // Create the button element + const button = $(`
`); + + // Insert it inside the .journal-header + const journal_header = html.find(".journal-header aside") + journal_header.append(button); + + // Attach event listener + button.click(this._onCopyButtonClick.bind(this)); + } + + _onCopyButtonClick(event) { + event.preventDefault(); + var editorContent = this.element.find(".editor-content").html(); + + // Replace linked items + editorContent = editorContent.replace(/@\w+\[.+\]\{(.*?)\}/g,"$1") + + const markdownContent = turndownService.turndown(editorContent) + + // Copy to clipboard + navigator.clipboard.writeText(markdownContent) + .then(()=>ui.notifications.info("Journal content copied as Markdown!")); + } } \ No newline at end of file diff --git a/src/styles/asc-starwars-journal.css b/src/styles/asc-starwars-journal.css index 020abe7..b1f596c 100644 --- a/src/styles/asc-starwars-journal.css +++ b/src/styles/asc-starwars-journal.css @@ -18,6 +18,13 @@ src: url("../fonts/SWCrawlBody.ttf"); } +.asc-starwars .asc-copy { + width: 100%; + button { + + } +} + .asc-starwars .journal-entry-content, .asc-starwars .editor-container, .chat-message.asc-starwars .message-content { background-image:url(../artwork/stars.png) !important; background-repeat:repeat !important;