Provides some general additions to Elethor
目前為
// ==UserScript==
// @name Elethor General Purpose
// @description Provides some general additions to Elethor
// @namespace https://www.elethor.com/
// @version 1.0.11
// @author Anders Morgan Larsen (Xortrox)
// @match https://elethor.com/*
// @match https://www.elethor.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function() {
const moduleName = 'Elethor General Purpose';
const version = '1.0.11'
const playerHealthBarElementDefinition = '.progress.is-medium.is-danger';
const playerHealthBarTextElementDefinition = '.is-fight-health';
function getBattleHealthPercentage() {
const playerHealth = document.querySelector(playerHealthBarElementDefinition);
if (!playerHealth) {
return 0;
}
return playerHealth.value / playerHealth.max * 100;
}
function initializeUpdateBattleHealthPercentage() {
if (window.elethorExtrasInterval) {
clearInterval(window.elethorExtrasInterval);
}
window.elethorExtrasInterval = setInterval(() => {
const playerHealthText = document.querySelector(playerHealthBarTextElementDefinition);
const healthPercentage = getBattleHealthPercentage();
if (playerHealthText && healthPercentage && !isNaN(healthPercentage)) {
let percentageDisplay;
if (playerHealthText.children.length === 0) {
percentageDisplay = document.createElement('span');
playerHealthText.appendChild(percentageDisplay);
} else {
percentageDisplay = playerHealthText.children[0];
}
if (percentageDisplay) {
percentageDisplay.innerText = ` (${healthPercentage.toFixed(3)}%)`;
}
}
}, 500);
console.log(`[${moduleName} v${version}] Battle Percentage initialized.`);
}
function initializeToastKiller() {
document.addEventListener('click', function(e) {
if (e.target
&& e.target.className
&& e.target.className.includes
&& e.target.className.includes('toasted')
) {
e.target.remove();
}
});
console.log(`[${moduleName} v${version}] Toast Killer initialized.`);
}
function initializeXHRHook() {
let rawSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.send = function() {
if (!this._hooked) {
this._hooked = true;
this.addEventListener('readystatechange', function() {
if (this.readyState === XMLHttpRequest.DONE) {
setupHook(this);
}
}, false);
}
rawSend.apply(this, arguments);
}
function setupHook(xhr) {
if (window.elethorGeneralPurposeOnUserLoad) {
const e = new Event('EGPXHR');
e.xhr = xhr;
window.elethorGeneralPurposeOnUserLoad.dispatchEvent(e);
}
}
window.elethorGeneralPurposeOnUserLoad = new EventTarget();
console.log(`[${moduleName} v${version}] XHR Hook initialized.`);
}
function initializeUserLoadListener() {
elethorGeneralPurposeOnUserLoad.addEventListener('EGPXHR', function (e) {
if (e && e.xhr
&& e.xhr.responseURL
&& e.xhr.responseURL.endsWith
&& e.xhr.responseURL.endsWith('/game/user')
) {
try {
const userData = JSON.parse(e.xhr.responseText);
console.log(`[${moduleName} v${version}] User Data hook:`, userData);
} catch (e) {
console.log(`[${moduleName} v${version}] Error parsing userData:`, e);
}
}
});
console.log(`[${moduleName} v${version}] User Load Listener initialized.`);
}
function initializeInventoryStatsLoadListener() {
elethorGeneralPurposeOnUserLoad.addEventListener('EGPXHR', function (e) {
if (e && e.xhr
&& e.xhr.responseURL
&& e.xhr.responseURL.endsWith
&& e.xhr.responseURL.endsWith('/game/inventory/stats')
) {
setTimeout(() => {
updateEquipmentPercentageSummary();
});
}
});
console.log(`[${moduleName} v${version}] User Load Listener initialized.`);
}
function updateEquipmentPercentageSummary() {
document.querySelector('.is-equipment>div>div').setAttribute('style', 'width: 60%')
let percentagesTable = document.querySelector('#egpPercentagesSummary')
if (!percentagesTable){
percentagesTable = document.querySelector('.is-equipment>div>div:nth-child(2)').cloneNode(true);
percentagesTable.setAttribute('style', 'width: 15%');
percentagesTable.id='egpPercentagesSummary';
document.querySelector('.is-equipment>div').appendChild(percentagesTable);
for (const child of percentagesTable.children[0].children) {
child.children[0].remove();
}
document.querySelector('#egpPercentagesSummary>table>tr:nth-child(8)').setAttribute('style', 'height:43px');
}
}
(function run() {
initializeUpdateBattleHealthPercentage();
initializeToastKiller();
initializeXHRHook();
initializeUserLoadListener();
initializeInventoryStatsLoadListener();
console.log(`[${moduleName} v${version}] Loaded.`);
})();
})();