MediaWiki:Cycle11.js: Difference between revisions
Appearance
miraheze>CodeTriangle switch min shareholder to bold + no underline |
miraheze>CodeTriangle no parking for bob |
||
| Line 20: | Line 20: | ||
// Code to generate a hover-over indication of percentages. | // Code to generate a hover-over indication of percentages. | ||
for (let row of st.children) { | for (let row of st.children) { | ||
// The cell that contains the entity's name. | |||
let ent = row.children[0]; | |||
let ch = row.children[i]; | let ch = row.children[i]; | ||
if (!isNaN(ch.innerText)) { | if (!isNaN(ch.innerText)) { | ||
| Line 25: | Line 27: | ||
let majority = percent > 0.5; | let majority = percent > 0.5; | ||
let minority = majority ? false : percent >= 0.1; | let minority = majority ? false : percent >= 0.1; | ||
// But the BoB cannot be a shareholder at all. | |||
if (ent.innerText.match(/Bureau/)) { | |||
majority = minority = false; | |||
} | |||
ch.setAttribute( | ch.setAttribute( | ||
"title", | "title", | ||
Revision as of 20:24, 10 January 2022
// DOM objects
let st = document.querySelector("#sharetable tbody");
// Only do the rest if the sharetable exists
if (st) {
// This block gets the total amount of shares for each rule
var totals = [];
// Loop over the number of columns in the first row (should never be greater
// than number of rows in table)
for (let i = 1; i < st.children[0].children.length; i++) {
let total = 0;
for (let row of st.children) {
// Skip over anything that doesn't look like a number (i.e. headings)
if (!isNaN(row.children[i].innerText)) {
total += parseInt(row.children[i].innerText);
}
}
totals.push(total);
// Code to generate a hover-over indication of percentages.
for (let row of st.children) {
// The cell that contains the entity's name.
let ent = row.children[0];
let ch = row.children[i];
if (!isNaN(ch.innerText)) {
let percent = parseInt(ch.innerText) / total;
let majority = percent > 0.5;
let minority = majority ? false : percent >= 0.1;
// But the BoB cannot be a shareholder at all.
if (ent.innerText.match(/Bureau/)) {
majority = minority = false;
}
ch.setAttribute(
"title",
// hacky way to round to two decimal points
// because the right way is worse
((percent * 10000) | 0) / 100 + "%" + (majority ? " (majority)" : minority ? " (minority)" : "")
);
if (majority) {
ch.innerHTML = `<b><u>${ch.innerText}</u></b>`;
}
if (minority) {
ch.innerHTML = `<b>${ch.innerText}</b>`;
}
}
}
}
// Construct a new row to contain totals for each rule.
let newRow = document.createElement("tr");
let totalLabel = document.createElement("th");
totalLabel.innerText = "Total";
newRow.appendChild(totalLabel);
for (let total of totals) {
let newEle = document.createElement("th");
newEle.innerText = total;
newEle.style = "text-align: left;";
newRow.appendChild(newEle);
}
// Append this row to the share table.
st.appendChild(newRow);
}