// ==UserScript==
// @name FF14国服竞猜中心数据统计
// @namespace https://unlucky.ninja/
// @version 2024-06-20-1
// @description 在页面上显示数据统计
// @author UnluckyNinja
// @match https://actff1.web.sdo.com/20240520_NewJingCai/index.html
// @icon https://www.google.com/s2/favicons?sz=64&domain=sdo.com
// @grant none
// @require https://code.jquery.com/jquery-3.7.1.slim.min.js
// @require https://update.greasyfork.icu/scripts/498113/1395364/waitForKeyElements_mirror.js
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
function getStats(node){
const div = document.createElement('div')
const costs = node.find('.items.guessit.itw4').map(function(){
return parseInt(this.textContent)
}).toArray().reduce((a,b)=>a+b)
console.log(costs)
const gains = node.find('.items.guessit.itw6').map(function(){
return parseInt(this.textContent)
}).toArray().reduce((a,b)=>a+b)
const ratio = costs === 0 ? 0 : (gains-costs)/costs
const ratioText = (ratio*100).toFixed(2)+'%'
const ratioStyle = ratio >0 ? 'color: forestgreen' : ratio < 0 ? 'color: crimson' : ''
div.innerHTML = `${gains} / ${costs}, 盈亏:${ratio > 0 ? '+' : ''}${ratioText}`
div.style.textAlign = 'right'
div.style.margin = '0.25rem auto'
return div
}
waitForKeyElements('.pageGuesshis div.tabCont.tabContCls:nth-child(1)', (node)=>{
node.before(getStats(node))
})
})();