NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name eRep Economy to csv // @version 0.5 // @author Runy69 // @match https://www.erepublik.com/*/country/economy/* // @copyright 2019, Runy69 (https://openuserjs.org/users/Runy69) // @updateURL https://openuserjs.org/meta/Runy69/eRep_Economy_to_csv.meta.js // @downloadURL https://openuserjs.org/install/Runy69/eRep_Economy_to_csv.user.js // @grant none // @license MIT // ==/UserScript== let $ = window.jQuery; if (!$) return; $(document).ready(function () { $("#country_charts").prepend('<a id="export" style="margin-left: 10px;" href="javascript:" class="std_global_btn mediumSize floatRight" original-title=""><span>Export</span></a>'); $("#export").click(() => exportData()); function exportData() { let data = window.chartDataJSON.map((arr) => arr.slice()); let rows = []; for (var i = 0; i < data.length; i++) { let row = []; let day = data[i].shift(); let total = "Total"; //let wam = data[i].shift(); //let vat = data[i].shift(); //let work = data[i].shift(); //let imp = data[i].shift(); //let medals = data[i].shift(); //let subsidy = data[i].shift(); if (i !== 0) { total = 0; day = day.match(/\d+\,\d+/)[0].replace(",", "."); for (let v in data[i]) { total += data[i][v]; } } row[0] = day; row[1] = total; for (let v in data[i]) { row.push(data[i][v]); } for (let v in row) { if (v != 0 && !isNaN(row[v])) { row[v] = Math.round(row[v]); } } rows.push(row); } let csvContent = "data:text/csv;charset=utf-8," + rows.map(e => e.join(",")).join("\n"); let encodedUri = encodeURI(csvContent); let link = document.createElement("a"); link.setAttribute("href", encodedUri); link.setAttribute("download", `erep-${rows[1][0]}-${rows[rows.length-1][0]}.csv`); document.body.appendChild(link); link.click(); link.remove(); } });