|
| 1 | +// ==UserScript== |
| 2 | +// @name Cryptohopper Export Saved Trade History |
| 3 | +// @namespace https://github.com/markrickert/cryptohopper-dashboard-watchlist |
| 4 | +// @version 0.1 |
| 5 | +// @description Adds single-click export functionality to the trade history page using the saved settings (after saving at least once), and allows for saving and loading export settings. The author of this script finds it useful to set the to part of the date range to sometime in the future when using this functionality, such as 01/01/2030 12:00 AM. |
| 6 | +// @author @eatsleepcoderepeat-gl |
| 7 | +// @homepage https://github.com/markrickert/cryptohopper-dashboard-watchlist |
| 8 | +// @updateURL https://github.com/markrickert/cryptohopper-dashboard-watchlist/raw/main/export-saved-trade-history.user.js |
| 9 | +// @match https://www.cryptohopper.com/trade-history |
| 10 | +// @icon https://www.google.com/s2/favicons?domain=cryptohopper.com |
| 11 | +// @grant GM_addStyle |
| 12 | +// @grant GM_getValue |
| 13 | +// @grant GM_setValue |
| 14 | +// ==/UserScript== |
| 15 | + |
| 16 | +// Only run this code on the trade-history page (useful when included in a parent script) |
| 17 | +if(['/trade-history'].includes(window.location.pathname)) (function () { |
| 18 | + "use strict"; |
| 19 | + |
| 20 | + const EXPORT_KEY = 'export-trade-history-settings'; |
| 21 | + const EXPORT_BUTTON_NAME = '#export-saved-trade-history'; |
| 22 | + const SAVE_BUTTON_NAME = '#save-export-settings'; |
| 23 | + const LOAD_BUTTON_NAME = '#load-export-settings'; |
| 24 | + const BUTTON_PRIMARY_CLASS = 'btn btn-primary waves-effect waves-light'; |
| 25 | + const BUTTON_SECONDARY_CLASS = 'btn btn-default waves-effect'; |
| 26 | + var buttonsAdded = false; |
| 27 | + |
| 28 | + // This function loads the currently saved settings |
| 29 | + function loadSavedSettings() { |
| 30 | + var exportSettings = JSON.parse(GM_getValue(EXPORT_KEY)); |
| 31 | + |
| 32 | + // Apply saved settings |
| 33 | + $('#export_type').val(exportSettings.format); |
| 34 | + $('#check_sells').prop('checked',exportSettings.buys); |
| 35 | + $('#check_buys').prop('checked',exportSettings.sells); |
| 36 | + $('#export_daterange').val(exportSettings.daterange); |
| 37 | + } |
| 38 | + |
| 39 | + // This function sets our CSS |
| 40 | + function setStyles() { |
| 41 | + GM_addStyle( |
| 42 | + 'button' + EXPORT_BUTTON_NAME + |
| 43 | + ',button' + SAVE_BUTTON_NAME + |
| 44 | + '{ margin-right: 3px; }' + |
| 45 | + 'button' + LOAD_BUTTON_NAME + |
| 46 | + '{ margin-right: 2px; }' |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + // This function adds the Export Saved button and handles click events |
| 51 | + function exportButtonHandler() { |
| 52 | + if(!$(EXPORT_BUTTON_NAME).length && GM_getValue(EXPORT_KEY,false) !== false) { |
| 53 | + // Add the Export Saved button |
| 54 | + $(`button[onclick="jQuery('#exportDiv').toggle()"]`).before('<button id="' + EXPORT_BUTTON_NAME.replace('#','') + '" type="button" class="' + BUTTON_PRIMARY_CLASS + '"><i class="fa fa-download m-r-5"></i> Export Saved</button>'); |
| 55 | + |
| 56 | + // Handle clicks of the Export Saved button |
| 57 | + $(EXPORT_BUTTON_NAME).on('click',function() { |
| 58 | + loadSavedSettings(); |
| 59 | + |
| 60 | + startExport(); |
| 61 | + }); |
| 62 | + |
| 63 | + buttonsAdded = true; |
| 64 | + } |
| 65 | + } |
| 66 | + |
| 67 | + // This function saves the current settings when exporting |
| 68 | + function saveSettingsButtonHandler() { |
| 69 | + // Add the Save Settings button |
| 70 | + $('button[onclick="startExport()"]').before('<button id="' + SAVE_BUTTON_NAME.replace('#','') + '" type="button" class="' + BUTTON_PRIMARY_CLASS + '">Save Settings</button>'); |
| 71 | + |
| 72 | + // Handle clicks of the Save Settings button |
| 73 | + $(SAVE_BUTTON_NAME).on('click',function() { |
| 74 | + var format = $('#export_type').val(); |
| 75 | + var buys = $('#check_sells').prop('checked'); |
| 76 | + var sells = $('#check_buys').prop('checked'); |
| 77 | + var daterange = $('#export_daterange').val(); |
| 78 | + |
| 79 | + // Save these values for future use |
| 80 | + GM_setValue(EXPORT_KEY,JSON.stringify({'format':format,'buys':buys,'sells':sells,'daterange':daterange})); |
| 81 | + |
| 82 | + // If this is the first time saving, add the Export Saved button |
| 83 | + if(!buttonsAdded) { |
| 84 | + exportButtonHandler(); |
| 85 | + loadSettingsButtonHandler(); |
| 86 | + } |
| 87 | + }); |
| 88 | + } |
| 89 | + |
| 90 | + // This function loads the currently saved settings |
| 91 | + function loadSettingsButtonHandler() { |
| 92 | + if(!$(LOAD_BUTTON_NAME).length && GM_getValue(EXPORT_KEY,false) !== false) { |
| 93 | + // Add the Load Saved button |
| 94 | + $(SAVE_BUTTON_NAME).before('<button id="' + LOAD_BUTTON_NAME.replace('#','') + '" type="button" class="' + BUTTON_SECONDARY_CLASS + '">Load Saved</button>'); |
| 95 | + |
| 96 | + // Handle clicks of the Load Saved button |
| 97 | + $(LOAD_BUTTON_NAME).on('click',loadSavedSettings); |
| 98 | + |
| 99 | + buttonsAdded = true; |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + jQuery(() => { |
| 104 | + setStyles(); |
| 105 | + exportButtonHandler(); |
| 106 | + saveSettingsButtonHandler(); |
| 107 | + loadSettingsButtonHandler(); |
| 108 | + }); |
| 109 | +})(); |
0 commit comments