From 75733b138a2a8dab2afe0b228d79898621f89ed8 Mon Sep 17 00:00:00 2001 From: sakasa Date: Tue, 15 Aug 2023 16:38:55 +0900 Subject: [PATCH] =?UTF-8?q?#3=20MF=E3=82=AF=E3=83=A9=E3=82=A6=E3=83=89?= =?UTF-8?q?=E5=8B=A4=E6=80=A0=E3=81=AE=E6=96=B0=E3=83=9E=E3=82=A4=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=83=AA=E3=83=AA=E3=83=BC=E3=82=B9=E3=81=AB?= =?UTF-8?q?=E3=82=88=E3=82=8B=E4=B8=8D=E5=85=B7=E5=90=88=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- attendance-ext/contentScript.js | 70 ++++++++++++++++++++++----------- attendance-ext/manifest.json | 2 +- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/attendance-ext/contentScript.js b/attendance-ext/contentScript.js index 0f44758..0ae5bb4 100644 --- a/attendance-ext/contentScript.js +++ b/attendance-ext/contentScript.js @@ -1,23 +1,7 @@ -const datetime = function(){ - const statusContainer = document.getElementsByClassName('status-container')[0]; - const dateStr = statusContainer.firstChild.firstChild.firstChild.innerText; - const timeStr = statusContainer.lastChild.firstChild.firstChild.innerText; - return '[' + dateStr + ' ' + timeStr + ']'; -}; -// console.log(datetime()); - -let userElem = document.getElementsByClassName("attendance-header-user-name")[0]; -if (userElem && userElem.hasChildNodes()) { - userElem = userElem.firstChild; -} else { - userElem = document.getElementsByClassName("attendance-mobile-header-user-name")[0]; -} -const re = /^(.+?)さん$/ -const user = re.exec(userElem.innerText)[1]; -// console.log(user); - +let user = ''; let chatConf = {}; -const load = function(){ + +function loadChatConf(){ chrome.storage.local.get(['chatConfig'], function(data) { if (data.chatConfig) { chatConf.webhook = data.chatConfig.webhook; @@ -26,13 +10,51 @@ const load = function(){ } }); }; -load(); +loadChatConf(); // console.log(chatConf); +function getUserText() { + // console.log('getUserText') + let userElem = document.getElementsByClassName("attendance-header-user-name")[0]; + userElem = userElem||document.getElementsByClassName("attendance-mobile-header-user-name")[0]; + // console.log(userElem); + + let userName = ''; + if (userElem && userElem.hasChildNodes()) { + if (userElem.childElementCount == 1) { + userName = userElem.firstChild.innerText; + } else { + [...userElem.childNodes].forEach(function(element) { + if (!element.hasChildNodes()) { + userName = element.data; + } else if (element.innerText.endsWith('さん')) { + userName = element.innerText; + } + }); + } + } + // console.log(userName); + + const re = /^(.+?)さん$/ + user = re.exec(userName)[1]; + // console.log(user); + return user; +} + +function getDateText() { + // console.log('getDateText') + const statusContainer = document.getElementsByClassName('status-container')[0]; + const dateStr = statusContainer.firstChild.firstChild.firstChild.innerText; + const timeStr = statusContainer.lastChild.firstChild.firstChild.innerText; + const datetime = '[' + dateStr + ' ' + timeStr + ']'; + // console.log(datetime); + return datetime; +} + function dataJson(text){ // console.log(text); let ret = { - "text": user + " - " + datetime() + " " + text, + "text" : `${user||getUserText()} - ${getDateText()} ${text}`, "username": (chatConf.username || null) ?? "kintai-bot" }; if(chatConf.channel) { @@ -81,5 +103,9 @@ chrome.storage.onChanged.addListener(function(changes, namespace) { storageChange.oldValue, storageChange.newValue); } - load(); + loadChatConf(); }); + +// document.addEventListener('click', function(e) { +// console.log(e); +// }) diff --git a/attendance-ext/manifest.json b/attendance-ext/manifest.json index 2f331b3..f761749 100644 --- a/attendance-ext/manifest.json +++ b/attendance-ext/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Kintai Post with Moneyforward Attendance", - "version": "0.1.2", + "version": "0.1.3", "description": "「マネーフォワード クラウド勤怠」の打刻に合わせて、設定したチャットに投稿を行います。チャットの設定は拡張機能のオプションページで行ってください。", "permissions": [ "declarativeContent",