I think the user search feature is also very useful, so I have now implemented it in my tampermonkey script.
It looks like this:
The code to use in a tampermonkey script if you are interested:
Code
// ==UserScript==
// @name D2jsp Gold Additions
// @namespace D2jspGoldAdditions
// @version 1
// @description Add overview of total gold moved for the month + more features.
// @author Klexmoo
// @match https://*.d2jsp.org/gold.php*
// @grant none
// ==/UserScript==
const toFixedFloat = (num) => parseFloat(num.toFixed(2)).toLocaleString(undefined, { minimumFractionDigits:2, maximumFractionDigits:2 })
var parent = document.getElementById('itgr').parentElement;
parent.removeChild(document.querySelector('#sALb'))
var goldInSpan = document.getElementById('itgr');
var goldOutSpan = document.getElementById('itgs');
var goldSpan = document.createElement('span');
var goldIn = 0;
var goldOut = 0;
const myID = w;
var total = Array.isArray(g) ? g.reduce((sum, arr) => {
if (arr[0] == myID) {
goldOut += arr[2];
return sum - arr[2];
} else {
goldIn += arr[2];
return sum + arr[2];
}
}, 0) : 0.0;
goldInSpan.innerHTML = toFixedFloat(goldIn);
goldOutSpan.innerHTML = toFixedFloat(goldOut);
goldSpan.innerHTML = ` / Total: ${toFixedFloat(total)} `;
parent.appendChild(goldSpan);
const allRows = g.slice(0);
gdt = (d) => {
return new Date(d * 1000).toLocaleString('en-GB');
}
try {
bL();
} catch(error){}
function updateRows(event){
switch (event.target.value) {
case 'All':
g = allRows.slice(0);
break;
case 'Received':
g = allRows.filter(arr => arr[1] === myID);
break;
case 'Sent':
g = allRows.filter(arr => arr[0] === myID);
break;
default:
return;
}
try {
bL();
} catch(error){}
};
function createSelect() {
let selectReference = document.getElementsByClassName('p3 ce')[0].children.item(1);
let selectElement = document.createElement("select");
selectElement.setAttribute("id", "newFeatureSelect");
selectElement.onchange=updateRows;
let insertedNode = selectReference.parentElement.insertBefore(selectElement, selectReference.nextSibling);
for (let i = 0; i < 2; i++) {
const element = document.createTextNode("\u00A0");
insertedNode.parentElement.insertBefore(element, insertedNode);
}
const options = ['All', 'Received', 'Sent'];
options.forEach(option => {
let optionElement = document.createElement("option");
optionElement.setAttribute("value", option);
let textNode = document.createTextNode(option);
optionElement.appendChild(textNode);
document.getElementById("newFeatureSelect").appendChild(optionElement);
})
}
createSelect();
function searchTransactions(username){
if (!username) g = allRows.slice(0);
g = allRows.filter((row) => row[8].toLowerCase().includes(username.toLowerCase()));
try {
bL();
} catch(error){}
}
function createUserSearch() {
const infoDiv = document.getElementsByClassName('p3 ce')[0];
let newDiv = document.createElement('div');
newDiv.style['text-align'] = 'center';
newDiv.style['margin-top'] = '15px';
let newInput = document.createElement('input');
newInput.oninput=(event) => searchTransactions(event.target.value);
let inputDescription = document.createTextNode('User search: ');
newDiv.appendChild(inputDescription);
newDiv.appendChild(newInput);
let insertedDiv = infoDiv.parentElement.insertBefore(newDiv, infoDiv.nextSibling);
}
createUserSearch()
This post was edited by Klexmoo on Nov 28 2020 06:32pm