Created
December 24, 2023 05:08
-
-
Save alanhe421/59eb136af12ed8df7cf3ffe1c9eec7fe to your computer and use it in GitHub Desktop.
中信银行贷款信息统计
This file contains 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
// ==UserScript== | |
// @name 中信还款 | |
// @namespace http://tampermonkey.net/ | |
// @version 0.5 | |
// @description try to take over the world! | |
// @author You | |
// @match https://i.bank.ecitic.com/perbank6/gotomain.do | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=ecitic.com | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
/** | |
* 根据还款计划,扫描到日期超过当前日期即停止 | |
* | |
* 目前统计目标为 | |
*/ | |
function sleep(seconds = 2) { | |
return new Promise((resolve) => { | |
setTimeout(resolve, seconds * 1000); | |
}); | |
} | |
async function jumpToPage() { | |
document.querySelector('#m3_113').click(); | |
await sleep(5); | |
const operationBtn = window.mainframe.document.querySelector( | |
'#loanDiv > table > tbody > tr > td.moreThing > button.loanMoreBtn.already' | |
); | |
operationBtn.click(); | |
await sleep(); | |
operationBtn.nextElementSibling.children[2].click(); | |
} | |
async function collectData(initRes) { | |
const res = [ | |
...window.mainframe.document.querySelector( | |
'#listDiv > div.tradingCon > table > tbody' | |
).children | |
].reduce((res, el) => { | |
let [, date, moneyWithInterest, money, interest] = [...el.children].map( | |
(el) => el.innerText | |
); | |
money = +money.replace(/,/g, ''); | |
moneyWithInterest = +moneyWithInterest.replace(/,/g, ''); | |
interest = +interest.replace(/,/g, ''); | |
res.monery += money; | |
res.moneryWithInterest += moneyWithInterest; | |
res.interest += interest; | |
return res; | |
}, initRes); | |
const nextBtn = window.mainframe.document.querySelector( | |
'button[name="next"]' | |
); | |
if (nextBtn.disabled) { | |
return res; | |
} else { | |
nextBtn.click(); | |
await sleep(); | |
return await collectData(res); | |
} | |
} | |
async function doSum() { | |
const initRes = { | |
monery: 0, // 还了多少本金 | |
moneryWithInterest: 0, // 还了多少本金+利息 | |
interest: 0, // 还了多少利息 | |
interestPercentOfTotal: 0 | |
}; | |
const res = await collectData(initRes); | |
res.interestPercentOfTotal = ( | |
(res.interest / res.moneryWithInterest) * | |
100 | |
).toFixed(2); | |
window.mainframe.document | |
.querySelector('body > div.mine > div > h1') | |
.insertAdjacentHTML( | |
'afterend', | |
`<h2 style="color:red;padding-left: 0;">目前多还利息:${res.interest.toLocaleString()}CNY,共还本息:${res.moneryWithInterest.toLocaleString()}CNY,利息占比${ | |
res.interestPercentOfTotal | |
}%</h2>` | |
); | |
return res; | |
} | |
(async function () { | |
await jumpToPage(); | |
await sleep(5); | |
await doSum(); | |
})(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment