Claude Storage Data Exporter

Monitors storage for Claude chat data and exports to endpoint

  1. // ==UserScript==
  2. // @name Claude Storage Data Exporter
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Monitors storage for Claude chat data and exports to endpoint
  6. // @author nickm8
  7. // @match https://claude.ai/chat/*
  8. // @grant GM.xmlHttpRequest
  9. // @grant GM_xmlhttpRequest
  10. // @run-at document-start
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Debug logging
  18. const DEBUG = true;
  19. const log = {
  20. debug: (...args) => DEBUG && console.log('🔍 EXPORT:', ...args),
  21. error: (...args) => console.error('❌ EXPORT:', ...args),
  22. info: (...args) => console.log('ℹ️ EXPORT:', ...args)
  23. };
  24.  
  25. // Configuration
  26. const CONFIG = {
  27. storageKey: 'captured_chat_data',
  28. endpoint: 'http://localhost:8000/collect',
  29. checkInterval: 1000
  30. };
  31.  
  32. // Export functionality
  33. function exportData(data) {
  34. const requestObj = {
  35. method: 'POST',
  36. url: CONFIG.endpoint,
  37. headers: {
  38. 'Content-Type': 'application/json'
  39. },
  40. data: JSON.stringify({
  41. type: 'chatData',
  42. data: data,
  43. timestamp: new Date().toISOString(),
  44. url: window.location.href
  45. }),
  46. onload: function(response) {
  47. log.info('Data exported successfully:', response.responseText);
  48. // Clear storage after successful export
  49. localStorage.removeItem(CONFIG.storageKey);
  50. },
  51. onerror: function(error) {
  52. log.error('Error exporting data:', error);
  53. }
  54. };
  55.  
  56. if (typeof GM !== 'undefined' && GM.xmlHttpRequest) {
  57. GM.xmlHttpRequest(requestObj);
  58. }
  59. else if (typeof GM_xmlhttpRequest !== 'undefined') {
  60. GM_xmlhttpRequest(requestObj);
  61. }
  62. else {
  63. log.error('Neither GM.xmlHttpRequest nor GM_xmlhttpRequest is available');
  64. }
  65. }
  66.  
  67. // Check storage and export
  68. function checkAndExport() {
  69. try {
  70. const data = localStorage.getItem(CONFIG.storageKey);
  71. if (data) {
  72. log.debug('Found data in storage');
  73. const parsedData = JSON.parse(data);
  74. exportData(parsedData);
  75. }
  76. } catch (error) {
  77. log.error('Check and export failed:', error);
  78. }
  79. }
  80.  
  81. // Start monitoring
  82. setInterval(checkAndExport, CONFIG.checkInterval);
  83.  
  84. // Initialize
  85. log.info('Storage export initialized');
  86. })();