From e19cf881d271e60c0312c08a4e670d2a20f12420 Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Wed, 19 Jun 2024 14:49:20 -0500 Subject: [PATCH] first commit --- src/module.json | 31 ++++++++++++++++++++ src/script/main.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 src/module.json create mode 100644 src/script/main.js diff --git a/src/module.json b/src/module.json new file mode 100644 index 0000000..8ac83fd --- /dev/null +++ b/src/module.json @@ -0,0 +1,31 @@ +{ + "id": "asc-session-title-suggestions", + "title": "Session Title Suggestions", + "description": "A simple module that keeps track of session title suggestions", + "authors": [ + { + "name": "lmxsdl" + } + ], + "version": "1.0.0", + "compatibility": { + "minimum": "10", + "verified": "11" + }, + "scripts": [ + "scripts/main.js" + ], + "relationships": { + "requires": [ + { + "id": "_chatcommands", + "type": "module", + "manifest": "https://gitlab.com/woodentavern/foundryvtt-chat-command-lib/-/raw/master/src/module.json", + "compatability": { + "minimum": "2.0.2", + "verified": "2.0.2" + } + } + ] + } +} \ No newline at end of file diff --git a/src/script/main.js b/src/script/main.js new file mode 100644 index 0000000..504a221 --- /dev/null +++ b/src/script/main.js @@ -0,0 +1,70 @@ +const NAME = "/title" + +const TEMPLATE = " " + +function copyToClipboardListener(event) { + const text=event.target.dataset.clipboardText; + console.log(text); + navigator.clipboard.writeText(text) +} + +game.chatCommands.unregister(NAME) +game.chatCommands.unregister(NAME+"s") +game.chatCommands.register({ + name: NAME, + module: "_chatcommands", + aliases: ["/t"], + description: "Suggest a title for this episode", + icon: '', + requiredRole: "NONE", + callback: (chat, parameters, messageData) => { + console.log('test'); + return { content: `
${parameters}
`, flavor: ' suggesting an episode title...', flags:{title_suggestion: true}}; + }, + autocompleteCallback: (menu, alias, parameters) => [game.chatCommands.createInfoElement("Enter a message.")], + closeOnComplete: true + }); + + game.chatCommands.register({ + name: NAME+"s", + module: "_chatcommands", + aliases: ["/ts"], + description: "List all titles for the most recent episode", + icon: '', + requiredRole: "GAMEMASTER", + callback: (chat, parameters, messageData) => { + const content = document.createElement('ul') + const parser = new DOMParser() + + const suggestions = game.messages.filter(m => { + return m.flags.title_suggestion + }) + + const last_message_date = new Date(suggestions[suggestions.length-1].timestamp) + + suggestions.filter(m=>{ + const message_date = new Date(m.timestamp) + return message_date.toDateString() == last_message_date.toDateString() + }).forEach(m=>{ + const content_doc = parser.parseFromString(m.content,'text/html') + const element = document.createElement('li') + const icon = document.createElement('a') + icon.classList.add('fa-regular') + icon.classList.add('fa-clipboard') + icon.classList.add('clipboard') + icon.style.paddingLeft='.5em' + icon.style.paddingRight='.5em' + icon.dataset.clipboardText=content_doc.firstElementChild.textContent + const span = document.createElement('span') + span.classList.add('message-content') + span.textContent = `"${content_doc.firstElementChild.textContent}" - ${m.user?.name}` + element.appendChild(icon) + element.appendChild(span) + content.appendChild(element) + }) + + return { content: content.outerHTML, flavor: ` title suggestions (${last_message_date.toDateString()}):`}; + }, + autocompleteCallback: (menu, alias, parameters) => [game.chatCommands.createInfoElement("Enter a message.")], + closeOnComplete: true + }); \ No newline at end of file