Guest User

Untitled

a guest
Jul 20th, 2025
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Saddlebag Exchange - Download Sale History CSV
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Adds a button to download the sale history table as CSV on Saddlebag Exchange
  6. // @author BananaLumps
  7. // @match https://saddlebagexchange.com/ffxiv/extended-history*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function createDownloadButton() {
  15. const container = document.querySelector('.mx-3'); // place near "Sale History"
  16. if (!container || document.querySelector('#downloadCsvButton')) return;
  17.  
  18. const button = document.createElement('button');
  19. button.id = 'downloadCsvButton';
  20. button.textContent = 'Download CSV';
  21. button.style.cssText = `
  22. background: #2563eb;
  23. color: white;
  24. padding: 6px 12px;
  25. margin: 8px 0;
  26. border: none;
  27. border-radius: 5px;
  28. cursor: pointer;
  29. font-size: 14px;
  30. `;
  31. button.addEventListener('mouseenter', () => button.style.background = '#1d4ed8');
  32. button.addEventListener('mouseleave', () => button.style.background = '#2563eb');
  33.  
  34. button.addEventListener('click', () => {
  35. const table = document.querySelector('table');
  36. if (!table) return alert('Table not found!');
  37.  
  38. let csv = '';
  39. const rows = table.querySelectorAll('tr');
  40. rows.forEach((row, i) => {
  41. const cells = row.querySelectorAll('th, td');
  42. const rowData = Array.from(cells)
  43. .map(cell => `"${cell.innerText.replace(/"/g, '""')}"`)
  44. .join(',');
  45. csv += rowData + '\n';
  46. });
  47.  
  48. const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
  49. const url = URL.createObjectURL(blob);
  50. const a = document.createElement('a');
  51. a.href = url;
  52. a.download = 'sale_history.csv';
  53. document.body.appendChild(a);
  54. a.click();
  55. document.body.removeChild(a);
  56. URL.revokeObjectURL(url);
  57. });
  58.  
  59. container.appendChild(button);
  60. }
  61.  
  62. // Run after page loads (in case table is dynamically loaded)
  63. const observer = new MutationObserver(() => {
  64. if (document.querySelector('table') && !document.querySelector('#downloadCsvButton')) {
  65. createDownloadButton();
  66. }
  67. });
  68. observer.observe(document.body, { childList: true, subtree: true });
  69. })();
  70.  
Advertisement
Add Comment
Please, Sign In to add comment