Skip to content

Instantly share code, notes, and snippets.

@eiiot
Created October 19, 2024 08:03
Show Gist options
  • Save eiiot/b8abdb2e7482d64b0290813f390a19f4 to your computer and use it in GitHub Desktop.
Save eiiot/b8abdb2e7482d64b0290813f390a19f4 to your computer and use it in GitHub Desktop.
Download Stanford Dining Data
// ==UserScript==
// @name Download Stanford Dining Data
// @namespace http://tampermonkey.net/
// @version 2024-10-12
// @description try to take over the world!
// @author You
// @match https://rdeapp.stanford.edu/MyMealPlan/Transactions
// @icon https://www.google.com/s2/favicons?sz=64&domain=stanford.edu
// @grant none
// ==/UserScript==
(function() {
'use strict';
setTimeout(() => {
const filters = document.querySelector('#tableID1_filter');
if (filters) {
const button = document.createElement("button");
button.innerText = "Download";
button.style = "margin-left: 1rem;";
filters.appendChild(button);
button.addEventListener('click', () => {
const json = Array.from(document.querySelectorAll('#tableID1 tr'))
.map(row => ({
date: row.querySelector('td:nth-of-type(1)')?.innerText,
location: row.querySelector('td:nth-of-type(2)')?.innerText,
}))
.filter(row => !!row.date && !!row.location);
// Convert JSON to a string
const jsonString = JSON.stringify(json, null, 2);
// Create a Blob with the JSON data
const blob = new Blob([jsonString], { type: 'application/json' });
// Create a temporary URL for the Blob
const url = URL.createObjectURL(blob);
// Create a temporary anchor element for downloading
const a = document.createElement('a');
a.href = url;
a.download = 'table_data.json';
// Trigger the download
document.body.appendChild(a);
a.click();
// Clean up
document.body.removeChild(a);
URL.revokeObjectURL(url);
});
}
}, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment