Greasy Fork is available in English.

CanadaHelps fundraising donations totals

Adds total rows to the admin fundraising page, donations tab


Installer dette script?
  1. // ==UserScript==// @name CanadaHelps fundraising donations totals// @namespace https://gfork.dahi.icu/users/1// @version 1.0// @description Adds total rows to the admin fundraising page, donations tab// @author Jason Barnabe// @match https://www.canadahelps.org/en/pages/*/edit/// @grant none// @license GPL3// ==/UserScript==(function() {'use strict';let donationRoot = document.querySelector("#donations-pane h2 + table")if (!donationRoot) {return}let groupedTotals = {}let sum = Array.from(donationRoot.querySelectorAll("tbody tr:not(.message-row)")).forEach((row) => {let name = row.querySelector('.charity').innerTextlet amount = parseFloat(row.querySelector('.amount').innerText.replace('$', ''))groupedTotals[name] ||= 0.0groupedTotals[name] += amount})let tfoot = document.createElement("tfoot")tfoot.style.borderTop = '4px solid black'Object.entries(groupedTotals).forEach(([key, value]) => {tfoot.appendChild(createFooterRow(key, value))})let totalRow = createFooterRow('TOTAL', Object.values(groupedTotals).reduce((sum, el) => sum + el))totalRow.style.borderTop = '4px solid black'tfoot.appendChild(totalRow)donationRoot.appendChild(tfoot)})();function createFooterRow(name, value) {let row = document.createElement("tr")row.appendChild(createNameCell(name))row.appendChild(document.createElement("td"))row.appendChild(creat###mCell(value))row.appendChild(document.createElement("td"))return row}function createNameCell(name) {let nameCell = document.createElement("td")nameCell.classList.add('charity')nameCell.style.fontWeight = 'bold'nameCell.innerText = namereturn nameCell}function creat###mCell(value) {let sumCell = document.createElement("td")sumCell.classList.add('amount')sumCell.innerText = "$" + value.toFixed(2)return sumCell}