Skip to content

Commit e79f650

Browse files
authored
@HenryGarle Bug fix for certain combinations making a mess of comma separators (#17)
* Added target-restore target-restore reimplements the old functionality of the target list but now shows any items hidden by the default UI in the platform warning colour instead of green. * Updated readme * Accidental copy and paste * Renamed file, updated main function name and updated meta data * Bug fix for certain combinations making a mess of comma separators * Fix a bad merge
1 parent bd01eb5 commit e79f650

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,4 @@ This project follows the [all-contributors](https://github.com/all-contributors/
173173

174174
> This project is not affiliated, associated, authorized, endorsed by, or in any way officially connected with Cryptohopper.com, or any of its subsidiaries or its affiliates.
175175
176-
> The Cryptohopper name as well as related marks, emblems and images are registered trademarks of Cryptohopper.com.
176+
> The Cryptohopper name as well as related marks, emblems and images are registered trademarks of Cryptohopper.com.

target-restore.user.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22
// @name Cryptohopper Target Restore
33
// @namespace https://github.com/markrickert/cryptohopper-dashboard-watchlist
4-
// @version 0.1
4+
// @version 0.2
55
// @description Replicates old target functionality but marks any targets that would otherwise be hidden as "inactive" and displays them in the platforms warning colour
66
// @author @henrygarle
77
// @homepage https://github.com/markrickert/cryptohopper-dashboard-watchlist
@@ -17,7 +17,6 @@
1717
const response = JSON.parse(xhr.responseText);
1818
if (response.data && response.data.ta_values) {
1919
const { new_target, ta_values } = response.data;
20-
2120
// KVP of targets, true/false donates "active"
2221
// "Active" targets are those which the default UI would still show even after the change
2322
let targets = {};
@@ -39,21 +38,23 @@
3938

4039
let targetKeys = Object.keys(targets);
4140
if (targetKeys.length > 0) {
42-
let inactiveOutput = "";
43-
let activeOutput = "";
41+
42+
let inactiveTargets = [];
43+
let activeTargets = [];
44+
4445
targetKeys.forEach((target, index) => {
4546
if (targets[target]) {
46-
activeOutput += `${target}`;
47-
if (index < targetKeys.length - 1) activeOutput += ", ";
47+
activeTargets.push(target);
4848
} else {
49-
inactiveOutput += `${target}`;
50-
if (index < targetKeys.length - 1) inactiveOutput += ", ";
49+
inactiveTargets.push(target)
5150
}
5251
});
5352

54-
let spinnerClass = activeOutput ? "text-success" : "text-warning";
53+
let activeOutput = activeTargets.length ? activeTargets.reduce((acc, x, index) => inactiveTargets.length && index == activeTargets.length - 1 ? `${acc}, ${x}, ` : `${acc}, ${x}`) : "";
54+
let inactiveOutput = inactiveTargets.length ? inactiveTargets.reduce((acc, x, index) => `${acc}, ${x}`) : "";
5555

5656
const output = `${activeOutput}<span class="text-warning">${inactiveOutput}</span>`;
57+
let spinnerClass = activeOutput ? "text-success" : "text-warning";
5758

5859
// Set the target list
5960
jQuery("#current_target_coin")

0 commit comments

Comments
 (0)