warthunder.com / squadron members to CSV

Adds a button to WarThunder clan info pages allowing to export members' stats as CSV file.

当前为 2021-12-31 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        warthunder.com / squadron members to CSV
// @namespace   mimimimimi userscripts
// @match       https://warthunder.com/*/community/claninfo/*
// @match       https://warthunder.ru/ru/community/claninfo/*
// @grant       none
// @version     1.3.1
// @author      M
// @license MIT
// @description Adds a button to WarThunder clan info pages allowing to export members' stats as CSV file.
// ==/UserScript==

(function () {
    'use strict';
    let table, members, title, stat, activity;
    try {
        table = document.querySelector('div.squadrons-members__table');
        members = table.querySelectorAll('div.squadrons-members__grid-item');
        title = document.querySelector('div.squadrons-info__title').innerHTML.trim();
        stat = document.querySelector('div.squadrons-counter__count-icon--stat').nextElementSibling.innerHTML.trim();
        activity = document.querySelector('div.squadrons-counter__count-icon--activity').nextElementSibling.innerHTML.trim();
    }
    catch (err) {
        console.log("WT2CSV " + err);
        return;
    }
    let clicky = document.createElement('div');
    table.before(clicky);
    clicky.outerHTML = '<div id="clicky" class="button">Save as CSV</div>';
    document.getElementById('clicky').addEventListener('click', saveCSV);

    function saveCSV() {
        let now = new Date(),
            fname = "WT_" + title + "_(" + stat + "_" + activity + ")_members_" + now.toISOString().slice(0, 10) + ".csv";
        download(buildCSV(), fname);
        document.getElementById('clicky').style.display = 'none';
    }
    function buildCSV() {
        let dump = "", sep = ";", col = 6;
        members.forEach(function (el, i) {
            let m = el.textContent.trim();
            if ((i + 1) % col) {
                dump += m + sep;
            } else {
                dump += m + "\r\n";
            }
        });
        return dump;
    }
    function download(data, filename) {
        let a = window.document.createElement('a'),
            url = window.URL.createObjectURL(new Blob([data], {
                type: 'text/csv'
            }));
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
        window.URL.revokeObjectURL(url);
    }
})();