Skip to content

Instantly share code, notes, and snippets.

@nickcheng
Created August 28, 2023 08:35
Show Gist options
  • Save nickcheng/3bc6e5fbc912f2dcc266c2a79f3f160f to your computer and use it in GitHub Desktop.
Save nickcheng/3bc6e5fbc912f2dcc266c2a79f3f160f to your computer and use it in GitHub Desktop.
Violentmonkey(GreaseMonkey) script for showing if the day has been mended on Jobcan.
// ==UserScript==
// @name script - jobcan.jp
// @namespace Violentmonkey Scripts
// @match https://ssl.jobcan.jp/employee/attendance*
// @grant
// @version 1.0
// @author Nick
// @description 8/28/2023, 1:40:55 PM
// ==/UserScript==
var url = document.URL;
(async function() {
'use strict';
const days = [...document.querySelectorAll('#search-result tr.jbc-table-danger')]
.map(tr => [...tr.querySelectorAll('td')])
.filter(tds => tds.length > 1);
for(let idx in days) {
const tr = days[idx];
const td = tr[0].querySelector("a");
if (!td) { continue; }
const link = tr[0].querySelector("a").href;
const dayPage = await fetch(link, {
headers: {
"accept": "text/html",
"accept-language": "ja,en-US;q=0.9",
"cache-control": "max-age=0",
"upgrade-insecure-requests": "1"
},
referrer: "https://id.jobcan.jp/",
referrerPolicy: "strict-origin-when-cross-origin",
method: "GET",
mode: "cors",
credentials: "include"
});
const dayPageContent = await dayPage.text();
const dayStatus = handleResponse(dayPageContent);
tr[8].innerHTML = dayStatus;
}
function handleResponse(responseText) {
let parser = new DOMParser();
let doc = parser.parseFromString(responseText, "text/html");
const types = [...doc.querySelectorAll('#logs-table tr')]
.map(tr => [...tr.querySelectorAll('td')])
.filter(tds => tds.length > 0)
.map(([td0]) => td0.textContent.trim());
return types.join(",")
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment