MediaWiki:Cycle11.js: Difference between revisions

From Infinite Nomic Wiki
miraheze>CodeTriangle
m Protected "MediaWiki:Cycle11.js": don't want any trolls ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [Delete=Allow only administrators] (indefinite))
miraheze>CodeTriangle
it shouldn't try to go farther than it can now
Line 2: Line 2:
let st = document.querySelector("#sharetable tbody");
let st = document.querySelector("#sharetable tbody");


// This block gets the total amount of shares for each rule
// Only do the rest if the sharetable exists
let totals = [];
if (st) {
// Loop over the number of columns in the first row (should never be greater
// This block gets the total amount of shares for each rule
// than number of rows in table)
let totals = [];
for (let i = 1; i < st.children[0].children.length; i++) {
// Loop over the number of columns in the first row (should never be greater
  let total = 0;
// than number of rows in table)
  for (let row of st.children) {
for (let i = 1; i < st.children[0].children.length; i++) {
  // Skip over anything that doesn't look like a number (i.e. headings)
let total = 0;
    if (!isNaN(row.children[i].innerText)) {
for (let row of st.children) {
      total += parseInt(row.children[i].innerText);
// 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);
}
}
totals.push(total);
}
// 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);
}
}
// 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);

Revision as of 18:30, 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
	let 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);
	}
	
	// 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);
}