Skip to content

Commit 74d5d7c

Browse files
eatsleepcoderepeat-gleatsleepcoderepeat
andauthored
Added ability to export trade history using saved settings (#13)
* Added ability to export using the last used settings * Added quick install link, updated description, fixed file name * Updated constant * Updated functionality to allow explicitly saving and loading settings * Code maintainability improvements Moved CSS into its own function Added constants for button classes * Updated comment * Comment updates * Updated description * Updated description * Updated script name * Ensured export and load buttons are only added once settings are saved * Adjusted CSS * Added type attribute to buttons * Updated description, added author * Description update * Minor description update Co-authored-by: eatsleepcoderepeat <[email protected]>
1 parent f5de20b commit 74d5d7c

File tree

2 files changed

+116
-0
lines changed

2 files changed

+116
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ Cryptohopper may change their website at any moment, causing one or all of these
9595
9696
* Adds shift+click functionality for position checkboxes to allow selecting all positions of the same coin/token at once.
9797

98+
## export-saved-trade-history.user.js
99+
100+
> By [@eatsleepcoderepeat-gl](https://github.com/eatsleepcoderepeat-gl) (Xerahn on Discord)
101+
102+
* 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.
103+
98104
---
99105

100106
# Installation:
@@ -119,6 +125,7 @@ Cryptohopper may change their website at any moment, causing one or all of these
119125
* [`remove-hoppie.user.js`](https://github.com/markrickert/cryptohopper-dashboard-watchlist/raw/main/remove-hoppie.user.js)
120126
* [`stay-level-headed.user.js`](https://github.com/markrickert/cryptohopper-dashboard-watchlist/raw/main/stay-level-headed.user.js)
121127
* [`multi-select.user.js`](https://github.com/markrickert/cryptohopper-dashboard-watchlist/raw/main/multi-select.user.js)
128+
* [`export-saved-trade-history.user.js`](https://github.com/markrickert/cryptohopper-dashboard-watchlist/raw/main/export-saved-trade-history.user.js)
122129

123130
# Donate
124131

export-saved-trade-history.user.js

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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

Comments
 (0)