Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Saddlebag Exchange - Download Sale History CSV
- // @namespace http://tampermonkey.net/
- // @version 1.0
- // @description Adds a button to download the sale history table as CSV on Saddlebag Exchange
- // @author BananaLumps
- // @match https://saddlebagexchange.com/ffxiv/extended-history*
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- function createDownloadButton() {
- const container = document.querySelector('.mx-3'); // place near "Sale History"
- if (!container || document.querySelector('#downloadCsvButton')) return;
- const button = document.createElement('button');
- button.id = 'downloadCsvButton';
- button.textContent = 'Download CSV';
- button.style.cssText = `
- background: #2563eb;
- color: white;
- padding: 6px 12px;
- margin: 8px 0;
- border: none;
- border-radius: 5px;
- cursor: pointer;
- font-size: 14px;
- `;
- button.addEventListener('mouseenter', () => button.style.background = '#1d4ed8');
- button.addEventListener('mouseleave', () => button.style.background = '#2563eb');
- button.addEventListener('click', () => {
- const table = document.querySelector('table');
- if (!table) return alert('Table not found!');
- let csv = '';
- const rows = table.querySelectorAll('tr');
- rows.forEach((row, i) => {
- const cells = row.querySelectorAll('th, td');
- const rowData = Array.from(cells)
- .map(cell => `"${cell.innerText.replace(/"/g, '""')}"`)
- .join(',');
- csv += rowData + '\n';
- });
- const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
- const url = URL.createObjectURL(blob);
- const a = document.createElement('a');
- a.href = url;
- a.download = 'sale_history.csv';
- document.body.appendChild(a);
- a.click();
- document.body.removeChild(a);
- URL.revokeObjectURL(url);
- });
- container.appendChild(button);
- }
- // Run after page loads (in case table is dynamically loaded)
- const observer = new MutationObserver(() => {
- if (document.querySelector('table') && !document.querySelector('#downloadCsvButton')) {
- createDownloadButton();
- }
- });
- observer.observe(document.body, { childList: true, subtree: true });
- })();
Advertisement
Add Comment
Please, Sign In to add comment