这是indexloc提供的服务,不要输入任何密码
Skip to content
21 changes: 20 additions & 1 deletion ChangesInput.html → changesInput.html
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
}
});
</script>
</body>
</html>
13 changes: 10 additions & 3 deletions main.gs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function onOpen() {

// ユーザーに変更内容を尋ねるダイアログを表示する関数
function showChangesDialog() {
const html = HtmlService.createTemplateFromFile('ChangesInput')
const html = HtmlService.createTemplateFromFile('changesInput')
.evaluate()
.setWidth(400)
.setHeight(300);
Expand Down Expand Up @@ -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('出版が完了しました。');
}
18 changes: 16 additions & 2 deletions notice.gs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
12 changes: 0 additions & 12 deletions print.gs
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}