User:Chlod/Scripts/StormCountTally.js
// Storm Count Tally
// Author: Chlod
// Version: 1.0.0-REL
// Counts the total amount of storms on the WPTC Storm Count Tally. This makes
// counting typhoons easier and require less time, as long as the table is kept
// up to date.
mw.loader.using( 'oojs-ui-core' ).done(function () {
// Find our tally
var tally = document.getElementById("wptc-sct-table");
var button = document.getElementById("wptc-sct-button");
// Doesn't have a tally. Skip.
if (tally == null || button == null) return;
// Instance counting function
function instances(arr) { var a = [], b = [], prev; arr.sort(); for (var i = 0; i < arr.length; i++) { if (arr[i] !== prev) { a.push(arr[i]); b.push(1); } else { b[b.length - 1]++; } prev = arr[i]; } return [a, b]; }
// Total counting function
function count(a) { var b = a.split("\t"); b = b.map(c => c.trim()); b = b.filter(c => `${c}`.length > 0); var r = instances(b); console.dir({"TD": +(r[1][0]) + +(r[1][1]) + +(r[1][2]), "TS": +(r[1][1]) + +(r[1][2]), "TY": +(r[1][2])}) }
function calculate() {
var counts = {};
var rows = document.querySelectorAll("[data-wptc-stc]");
for (var row of rows) {
var children = [...row.children].slice(1);
var rowName = row.getAttribute("data-wptc-stc").trim();
var countsString = "";
for (var child of children) {
countsString += `${child.innerText.trim()}\t`;
}
counts[rowName] = count(countsString);
}
alert(JSON.stringify(counts));
}
var b = new OO.ui.ButtonWidget( {
label: "Calculate"
} );
b.$element[0].setAttribute("type", "button");
b.$element[0].onclick = calculate;
button.appendChild(b.$element);
});
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.