Skip to content

Instantly share code, notes, and snippets.

@kylekyle
Created November 12, 2020 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kylekyle/13999ad1711c1dee9dcfdeec294a20ab to your computer and use it in GitHub Desktop.
Save kylekyle/13999ad1711c1dee9dcfdeec294a20ab to your computer and use it in GitHub Desktop.
Tampermonkey script to add buttons for downloading MMI results as CSV
// ==UserScript==
// @name MMI CSV
// @namespace K-Dizzle
// @version 1.0
// @description Adds a button to download MMI results as a CSV
// @author K-Dizze
// @match https://mmi.run/*
// @grant none
// @require https://cdn.jsdelivr.net/gh/uzairfarooq/arrive/minified/arrive.min.js
// ==/UserScript==
(function() {
'use strict';
const original_axios_get = axios.get;
axios.get = (path, args) => {
const promise = original_axios_get(path, args);
if (path == "inc/rax.php") {
const filename = Object.values(args.params).filter(p => p).join('-');
promise.then(response => {
const data = response.data;
document.arrive('#output .nav-tabs', element => {
for (let key in data) {
if (key != 'status') {
console.log(`Generating CSV for ${key} ...`);
let csv = "data:text/csv;charset=utf-8,";
// headers
const headers = Object.keys(data[key][0]);
csv += encodeURIComponent(headers.join("\t") + "\r\n")
// rows
data[key].forEach(row => {
const values = Object.values(row);
csv += encodeURIComponent(values.join("\t") + "\r\n")
});
$(element).append(
$('<li>', { class: "nav-item" }).append(
$('<a>', {
href: csv,
type: 'button',
class: "btn btn-outline-success",
download: `${key}-${filename}.csv`
}).text(`Download ${key}`)
)
);
}
}
});
});
}
return promise;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment