Last active
December 19, 2022 05:28
-
-
Save whiteball/a2a3af48b3132c00231bf1d77673dddb 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 TrinArtでページを開いてからのルミナ消費を表示する | |
// @namespace https://ai-novelist-share.geo.jp/ | |
// @version 0.2.0 | |
// @description TrinArtの生成ページに、ページを開いてからのルミナ消費を表示します。ざっくり取得しているため、計算が合わない場合があります。※有料プランでの消費量割引とアップスケール時の消費量増が総消費に反映されるようにしました。消費予定は通常の絵を描く時の消費量です。 | |
// @author しらたま | |
// @match https://ai-novel.com/art/ | |
// @match https://ai-novel.com/art/index.php* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=ai-novel.com | |
// @updateURL https://gist.github.com/whiteball/a2a3af48b3132c00231bf1d77673dddb/raw/ai_novelist_trinart_lumina_info.user.js | |
// @downloadURL https://gist.github.com/whiteball/a2a3af48b3132c00231bf1d77673dddb/raw/ai_novelist_trinart_lumina_info.user.js | |
// @supportURL https://gist.github.com/whiteball/a2a3af48b3132c00231bf1d77673dddb | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const template = `<div id="mod-lumina-info-area-1" align="center" style="margin-top: 10px;font-size: 16px;text-align: center"></div>` | |
const download_button_area = document.getElementById('mod-download-button-area') | |
if (download_button_area) { | |
download_button_area.insertAdjacentHTML('afterend', template) | |
} else { | |
document.getElementById('submit_area').insertAdjacentHTML('beforeend', template) | |
} | |
let currentLumina = -1, currentReqLumina = -1, sumConsLumina = 0, initialLumina = -1, lastLumina = 0 | |
const updateLuminaInfo = function () { | |
const lumina_info_area = document.getElementById('mod-lumina-info-area-1') | |
if (lumina_info_area) { | |
lumina_info_area.innerText = `消費予定 ${currentReqLumina} / 現在 ${currentLumina} / 初期 ${initialLumina} / 総消費 ${Math.round(sumConsLumina*100)/100}` | |
} | |
} | |
const originalShowpost = window.showpost, | |
lumina_info = document.getElementById("lumina_info") | |
if (lumina_info) { | |
currentLumina = initialLumina = Number(lumina_info.innerText) | |
} | |
window.showpost = function () { | |
if (lumina_info) { | |
currentLumina = Number(lumina_info.innerText) | |
} | |
originalShowpost() | |
} | |
const originalSavePrefs = window.savePrefs, | |
current_req_lumina = document.getElementById("current_req_lumina"), | |
getReqLumina = function () { | |
if (current_req_lumina) { | |
let res = current_req_lumina.innerText.match(/会員:([0-9\.]+)ルミナ\(/) | |
if (!res) { | |
res = current_req_lumina.innerText.match(/ discount = ([0-9\.]+) Lumina \(/) | |
} | |
if (!res) { | |
res = current_req_lumina.innerText.match(/一枚描くと([0-9\.]+)ルミナ消費します/) | |
} | |
if (!res) { | |
res = current_req_lumina.innerText.match(/Price: ([0-9\.]+) Lumina per request/) | |
} | |
if (res) { | |
currentReqLumina = Number(res[1]) | |
} | |
} | |
} | |
window.savePrefs = function () { | |
getReqLumina() | |
originalSavePrefs() | |
updateLuminaInfo() | |
} | |
const originalAddUndoHistory = window.addUndoHistory | |
window.addUndoHistory = function (imgval,hash) { | |
originalAddUndoHistory(imgval,hash) | |
// sumConsLumina += currentReqLumina | |
sumConsLumina += lastLumina | |
updateLuminaInfo() | |
} | |
const originalAjax = window.jQuery.ajax | |
window.jQuery.ajax = function (param) { | |
if (param.type === 'POST' && param.data) { | |
if (param.url.indexOf('.ingress.coreweave.cloud/request') >= 0) { | |
const temp_lumina = JSON.parse(param.data).lumina | |
lastLumina = temp_lumina ? temp_lumina : 0 | |
} | |
} | |
return originalAjax(param) | |
} | |
getReqLumina() | |
updateLuminaInfo() | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment