Compare commits

...

1 Commits

Author SHA1 Message Date
e637d8e806 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.
2025-03-02 11:39:01 -06:00
3 changed files with 42 additions and 1 deletions

View File

@@ -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",

View File

@@ -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 = $(`<div class="asc-copy"><button><i class="fas fa-clipboard"></i>Copy</button></div>`);
// 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!"));
}
}

View File

@@ -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;