diff --git a/ChangesInput.html b/changesInput.html similarity index 75% rename from ChangesInput.html rename to changesInput.html index 6331a19..a63eaec 100644 --- a/ChangesInput.html +++ b/changesInput.html @@ -62,9 +62,18 @@ publishButton.disabled = true; publishButton.textContent = '送信中...'; // ボタンのテキストを変更してユーザーにフィードバック - const changes = document.getElementById('changesInput').value; + const changesTxt = document.getElementById('changesInput').value; const statusDiv = document.getElementById('status'); + let changes = [] + if (String(changesTxt).includes('\n')) { + changes = changesTxt.split('\n'); + } else if (String(changesTxt).includes(',')) { + changes = changesTxt.split(','); + } else { + changes = [changesTxt]; + } + // Google Apps Scriptの関数を呼び出してデータを渡す google.script.run .withSuccessHandler(function() { @@ -78,6 +87,16 @@ }) .processAndSend(changes); } + + document.getElementById('changesInput').addEventListener('keydown', function(event) { + // CtrlキーまたはCmdキー(Mac)が押されながらEnterキーが押されたかチェック + if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) { + // デフォルトのEnterキーの動作(改行)をキャンセル + event.preventDefault(); + // 送信関数を呼び出し + sendChanges(); + } + }); diff --git a/main.gs b/main.gs index 26dec97..7bb378f 100644 --- a/main.gs +++ b/main.gs @@ -8,7 +8,7 @@ function onOpen() { // ユーザーに変更内容を尋ねるダイアログを表示する関数 function showChangesDialog() { - const html = HtmlService.createTemplateFromFile('ChangesInput') + const html = HtmlService.createTemplateFromFile('changesInput') .evaluate() .setWidth(400) .setHeight(300); @@ -51,8 +51,15 @@ function processAndSend(changes) { const mono_data = exportSheetAsPdf(spreadsheetId, mono_sheet_name, folder_id, false) // Google Chat で送信 - const google_chat_message = sheetName + "が更新されました\n変更内容:\n" + changes + "\nカラー版: " + color_data.sharingUrl + "\nモノクローム版: " + mono_data.sharingUrl; - google_chat_webhook(google_chat_message, GOOGLE_CHAT_WEBHOOK_URL); + const message_content = { + "sheetName": sheetName, + "changes": changes, + "download": { + "color": color_data.sharingUrl, + "mono": mono_data.sharingUrl + } + } + sendGooglechat(message_content, GOOGLE_CHAT_WEBHOOK_URL); SpreadsheetApp.getUi().alert('出版が完了しました。'); } diff --git a/notice.gs b/notice.gs index d035c08..2bda252 100644 --- a/notice.gs +++ b/notice.gs @@ -1,8 +1,22 @@ -function google_chat_webhook(message, webhookUrl) { +/** + * Google Chat にメッセージを送信 + * + * @param {string} messageContents - メッセージの内容 + * @param {string} spreadsheetId - webhook の URL。 + */ +function sendGooglechat(messageContents, webhookUrl) { + // 変更内容 + let changesOutput = "" + for (let i = 0; i < messageContents.changes.length; i++) { + changesOutput += " - " + messageContents.changes[i] + "\n" + } + + const googlechatMessage = "「" + messageContents.sheetName + "」が更新されました\n変更内容:\n" + changesOutput + "カラー版: " + messageContents.download.color + "\nモノクローム版: " + messageContents.download.mono; + const options = { "method": "post", "headers": {"Content-Type": "application/json; charset=UTF-8"}, - "payload": JSON.stringify({"text": message}) + "payload": JSON.stringify({"text": googlechatMessage}) }; const response = UrlFetchApp.fetch(webhookUrl, options); console.log(response); diff --git a/print.gs b/print.gs index a80fdd2..cb55b53 100644 --- a/print.gs +++ b/print.gs @@ -43,15 +43,3 @@ function copyAndFormatSheet(spreadsheetId, sheetName) { return copiedSheet.getName(); } - -function test_copyAndFormatSheet() { - const spreadsheetId = "あなたのGoogle Spreadsheet IDをここに貼り付けてください"; // 例: "1abcdefgHIJKLMNOPqrstuvwxyz1234567890" - const sheetName = "コピーしたいシートの名前"; // 例: "OriginalData" - - try { - const newSheetName = copyAndFormatSheet(spreadsheetId, sheetName); - Logger.log(`新しいシートが作成されました: ${newSheetName}`); - } catch (e) { - Logger.log(`エラーが発生しました: ${e.message}`); - } -} \ No newline at end of file