|
13 | 13 |
|
14 | 14 | try { |
15 | 15 | // Only run this code on the intended page(s) (useful when @required in a parent script) |
16 | | - if(['/dashboard'].includes(window.location.pathname)) (function () { |
17 | | - "use strict"; |
| 16 | + if (["/dashboard"].includes(window.location.pathname)) |
| 17 | + (function () { |
| 18 | + "use strict"; |
18 | 19 |
|
19 | | - function addStyles() { |
20 | | - GM_addStyle(` |
| 20 | + function addStyles() { |
| 21 | + GM_addStyle(` |
21 | 22 | span[class*="rate_"]>span { |
22 | 23 | margin-left: 0.5em; |
23 | 24 | } |
24 | 25 | `); |
25 | | - } |
| 26 | + } |
26 | 27 |
|
27 | | - // Add absolute value to the Result column |
28 | | - function addAbsoluteResult(targets) { |
29 | | - // get unique currencyPairs: |
30 | | - var currencyTicketUpdatePairs = Object.keys(targets).map((cv, i) => |
31 | | - // Some coin pairs come back as 1INCH/USDT instead of 1INCHUSDT |
32 | | - cv.replace("/", "_") |
33 | | - ); |
34 | | - var spanSelectors = currencyTicketUpdatePairs.map((currentValue, index) => { |
35 | | - return `span.rate_${currentValue}`; |
36 | | - }); |
| 28 | + // Add absolute value to the Result column |
| 29 | + function addAbsoluteResult(targets) { |
| 30 | + // get unique currencyPairs: |
| 31 | + var currencyTicketUpdatePairs = Object.keys(targets).map((cv, i) => |
| 32 | + // Some coin pairs come back as 1INCH/USDT instead of 1INCHUSDT |
| 33 | + cv.replace("/", "_") |
| 34 | + ); |
| 35 | + var spanSelectors = currencyTicketUpdatePairs.map( |
| 36 | + (currentValue, index) => { |
| 37 | + return `span.rate_${currentValue}`; |
| 38 | + } |
| 39 | + ); |
37 | 40 |
|
38 | | - spanSelectors.forEach((currencyPairSelector, i) => { |
39 | | - $(`${currencyPairSelector}`).each(function () { |
40 | | - var el = $(this); // Turn it into a jquery object |
41 | | - var tx = el.text().split("(")[0]; // gets the percentage changed text |
42 | | - var change = tx.trim().replace("%", ""); // gets the raw number without % |
43 | | - let td = $(this).closest("td").prev(); // We think the previous td is the cost. |
44 | | - // Setup vars |
45 | | - let cost = false; |
46 | | - var thText; |
| 41 | + spanSelectors.forEach((currencyPairSelector, i) => { |
| 42 | + $(`${currencyPairSelector}`).each(function () { |
| 43 | + var el = $(this); // Turn it into a jquery object |
| 44 | + var tx = el.text().split("(")[0]; // gets the percentage changed text |
| 45 | + var change = tx.trim().replace("%", ""); // gets the raw number without % |
| 46 | + let td = $(this).closest("td").prev(); // We think the previous td is the cost. |
| 47 | + // Setup vars |
| 48 | + let cost = false; |
| 49 | + var thText; |
47 | 50 |
|
48 | | - // Try to find the cost of the position by searching the |
49 | | - // table headers for the word "Cost". |
50 | | - while (cost === false) { |
51 | | - thText = td |
52 | | - .closest("tbody") |
53 | | - .prev("thead") |
54 | | - .find("> tr > th:eq(" + td.index() + ")"); |
55 | | - if (thText.length) { |
56 | | - // If we found a header element |
57 | | - if (thText.text().toLowerCase() === "cost") { |
58 | | - // We know the current <td> contains the cost |
59 | | - cost = td.text().trim(); |
| 51 | + // Try to find the cost of the position by searching the |
| 52 | + // table headers for the word "Cost". |
| 53 | + while (cost === false) { |
| 54 | + thText = td |
| 55 | + .closest("tbody") |
| 56 | + .prev("thead") |
| 57 | + .find("> tr > th:eq(" + td.index() + ")"); |
| 58 | + if (thText.length) { |
| 59 | + // If we found a header element |
| 60 | + if (thText.text().toLowerCase() === "cost") { |
| 61 | + // We know the current <td> contains the cost |
| 62 | + cost = td.text().trim(); |
| 63 | + } else { |
| 64 | + // Go back one <td> and look at the header again. |
| 65 | + td = td.prev(); |
| 66 | + } |
60 | 67 | } else { |
61 | | - // Go back one <td> and look at the header again. |
62 | | - td = td.prev(); |
| 68 | + break; |
63 | 69 | } |
64 | | - } else { |
65 | | - break; |
66 | 70 | } |
67 | | - } |
68 | 71 |
|
69 | | - if (cost) { |
70 | | - try { |
71 | | - // Update the span with the change |
72 | | - const difference = ((change / 100) * cost).toFixed(2); |
73 | | - const elHTML = el.text().split("(")[0]; |
74 | | - el.html(elHTML + "<span>(" + difference + ")</span>"); |
75 | | - } catch (e) { |
76 | | - console.log( |
77 | | - "absolute-value.user.js - error setting absolute change value." |
78 | | - ); |
| 72 | + if (cost) { |
| 73 | + try { |
| 74 | + // Update the span with the change |
| 75 | + const difference = ((change / 100) * cost).toFixed(2); |
| 76 | + const elHTML = el.text().split("(")[0]; |
| 77 | + el.html(elHTML + "<span>(" + difference + ")</span>"); |
| 78 | + } catch (e) { |
| 79 | + console.log( |
| 80 | + "absolute-value.user.js - error setting absolute change value." |
| 81 | + ); |
| 82 | + } |
79 | 83 | } |
80 | | - } |
| 84 | + }); |
81 | 85 | }); |
82 | | - }); |
83 | | - } |
| 86 | + } |
84 | 87 |
|
85 | | - // This function listens for network requests and intercepts the target list to turn their icon on and off. |
86 | | - function watchTicker() { |
87 | | - setTimeout(() => { |
88 | | - socket.on("message", function (a) { |
89 | | - var parsed = JSON.parse(a); |
90 | | - if ("ticker" == parsed.type) { |
91 | | - // console.log("result", parsed.result) |
92 | | - addAbsoluteResult(parsed.result); |
93 | | - } |
94 | | - }); |
95 | | - }, 1000); // delay accessing the socket variable so we know it's initialized. |
96 | | - } |
| 88 | + // This function listens for network requests and intercepts the target list to turn their icon on and off. |
| 89 | + function watchTicker() { |
| 90 | + setTimeout(() => { |
| 91 | + socket.on("message", function (a) { |
| 92 | + var parsed = JSON.parse(a); |
| 93 | + if ("ticker" == parsed.type) { |
| 94 | + // console.log("result", parsed.result) |
| 95 | + addAbsoluteResult(parsed.result); |
| 96 | + } |
| 97 | + }); |
| 98 | + }, 1000); // delay accessing the socket variable so we know it's initialized. |
| 99 | + } |
97 | 100 |
|
98 | | - jQuery(() => { |
99 | | - addStyles(); |
100 | | - watchTicker(); |
101 | | - }); |
102 | | - })(); |
103 | | -} |
104 | | -catch(err) { |
105 | | - console.log(`Error in script absolute-value.user.js: ${err.name}: ${err.message}`); |
| 101 | + jQuery(() => { |
| 102 | + addStyles(); |
| 103 | + watchTicker(); |
| 104 | + }); |
| 105 | + })(); |
| 106 | +} catch (err) { |
| 107 | + console.log( |
| 108 | + `Error in script absolute-value.user.js: ${err.name}: ${err.message}` |
| 109 | + ); |
106 | 110 | } |
0 commit comments