Skip to content

Commit

Permalink
#3 MFクラウド勤怠の新マイページリリースによる不具合対応
Browse files Browse the repository at this point in the history
  • Loading branch information
sakasa committed Aug 15, 2023
1 parent 3196e02 commit 75733b1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
70 changes: 48 additions & 22 deletions attendance-ext/contentScript.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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);
// })
2 changes: 1 addition & 1 deletion attendance-ext/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Kintai Post with Moneyforward Attendance",
"version": "0.1.2",
"version": "0.1.3",
"description": "「マネーフォワード クラウド勤怠」の打刻に合わせて、設定したチャットに投稿を行います。チャットの設定は拡張機能のオプションページで行ってください。",
"permissions": [
"declarativeContent",
Expand Down

0 comments on commit 75733b1

Please sign in to comment.