-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathoverwrite-same-template.user.js
47 lines (43 loc) · 2.22 KB
/
overwrite-same-template.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// ==UserScript==
// @name Cryptohopper Overwrite Same Template
// @namespace https://github.com/markrickert/cryptohopper-dashboard-watchlist
// @version 0.2
// @description This script will automatically select the template with the same name as the currently active configuration for the overwrite target when saving a template. If a template of the same name does not yet exist, saving as a new template will be automatically selected. Note: template names must be unique for this to function properly.
// @author @eatsleepcoderepeat-gl
// @homepage https://github.com/markrickert/cryptohopper-dashboard-watchlist
// @updateURL https://github.com/markrickert/cryptohopper-dashboard-watchlist/raw/main/overwrite-same-template.user.js
// @match https://www.cryptohopper.com/config*
// @icon https://www.google.com/s2/favicons?domain=cryptohopper.com
// ==/UserScript==
try {
// Only run this code on the intended page(s) (useful when @required in a parent script)
if (["/config","/config/config-pools","/config/signals","/config/triggers"].includes(window.location.pathname))
(function () {
"use strict";
function setOverwriteTarget() {
var hopperMenu = $('#sidebar-menu>ul>li:first-of-type');
var hopperName = $('>a>span:first-of-type',hopperMenu).text().trim();
var existingTemplate = jQuery(`#overwrite_template div.radio label:contains(${hopperName})`);
// If there's a template that matches the name of the active template, select it as the overwrite target
if(existingTemplate.length)
existingTemplate.each(function() {
if(jQuery(this).text().trim().replace('Template of ','') == hopperName) {
jQuery(this).prev('input[type="radio"]').prop('checked',true);
return true;
}
});
// Otherwise select the save as new template option
else {
jQuery('#radio_asnew').prop('checked',true);
jQuery('#saveasnew_template,#overwrite_template').toggle();
}
}
jQuery(() => {
setOverwriteTarget();
});
})();
} catch (err) {
console.log(
`Error in script overwrite-same-template.user.js: ${err.name}: ${err.message}`
);
}