Last active
December 25, 2024 01:05
-
-
Save book000/b837130726b98a22676d6d66b04fe171 to your computer and use it in GitHub Desktop.
ジョブカン 給与明細・賞与明細ダウンロードスクリプト。https://payroll.jobcan.jp/employees/my_data/payslips で実行
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get all bonus data from the page | |
* | |
* @returns {Array} - Array of all bonus data | |
*/ | |
function get_all_bonus() { | |
const all_bonus = JSON.parse(document.querySelector('div[data-react-class="App"]').getAttribute("data-react-props")).values.all_bonus | |
const results = [] | |
for (const bonus of all_bonus) { | |
const pay_on = bonus.pay_on | |
const label = bonus.label | |
const subscription_amount = bonus.subscription_amount | |
results.push({ | |
pay_on, | |
label, | |
subscription_amount, | |
}) | |
} | |
return results | |
} | |
/** | |
* Check if the current page is a valid jobcan payslips page | |
* | |
* @returns {Boolean} - True if the page is a valid jobcan payslips page, False otherwise | |
*/ | |
function is_valid_url() { | |
const url = window.location.href | |
const valid_url = "https://payroll.jobcan.jp/employees/my_data/bonus" | |
return url.startsWith(valid_url) | |
} | |
/** | |
* Download all payrolls data as a json file | |
* | |
* @returns {void} | |
*/ | |
function download_json() { | |
if (!is_valid_url()) { | |
alert("This is not a valid page. Please run this script on the jobcan bonus page.") | |
return | |
} | |
const all_bonus = get_all_bonus() | |
const json = JSON.stringify(all_bonus, null, 4) | |
const blob = new Blob([json], { type: 'application/json' }) | |
const url = URL.createObjectURL(blob) | |
const a = document.createElement('a') | |
a.download = 'all_bonus.json' | |
a.href = url | |
a.click() | |
} | |
// Run the script | |
download_json() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Get all payrolls data from the page | |
* | |
* @returns {Array} all_payrolls - Array of all payrolls data | |
*/ | |
function get_all_payrolls() { | |
const all_payrolls = JSON.parse(document.querySelector('div[data-react-class="App"]').getAttribute("data-react-props")).values.all_payrolls | |
const results = [] | |
for (const all_payroll of all_payrolls) { | |
const payment_date = all_payroll.payment_date | |
const label = all_payroll.label | |
const display_yearmonth_on_slip = all_payroll.display_yearmonth_on_slip | |
const date_display_yearmonth_on_slip = new Date(display_yearmonth_on_slip) | |
const year = date_display_yearmonth_on_slip.getFullYear() | |
const month = date_display_yearmonth_on_slip.getMonth() + 1 | |
const display_label = `${year}年${month}月給与明細` | |
const subscription_amount = all_payroll.subscription_amount | |
results.push({ | |
payment_date, | |
label, | |
display_yearmonth_on_slip, | |
subscription_amount, | |
display_label | |
}) | |
} | |
return results | |
} | |
/** | |
* Check if the current page is a valid jobcan payslips page | |
* | |
* @returns {Boolean} - True if the page is a valid jobcan payslips page, False otherwise | |
*/ | |
function is_valid_url() { | |
const url = window.location.href | |
const valid_url = "https://payroll.jobcan.jp/employees/my_data/payslips" | |
return url.startsWith(valid_url) | |
} | |
/** | |
* Download all payrolls data as a json file | |
* | |
* @returns {void} | |
*/ | |
function download_json() { | |
if (!is_valid_url()) { | |
alert("This is not a valid page. Please run this script on the jobcan payslips page.") | |
return | |
} | |
const all_payrolls = get_all_payrolls() | |
const json = JSON.stringify(all_payrolls, null, 4) | |
const blob = new Blob([json], { type: 'application/json' }) | |
const url = URL.createObjectURL(blob) | |
const a = document.createElement('a') | |
a.download = 'all_payrolls.json' | |
a.href = url | |
a.click() | |
} | |
// Run the script | |
download_json() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment