Skip to content

Instantly share code, notes, and snippets.

@saltyfireball
Last active March 21, 2020 19:48
Show Gist options
  • Select an option

  • Save saltyfireball/9856368526e6ce5c7a143dd1eeb1edc6 to your computer and use it in GitHub Desktop.

Select an option

Save saltyfireball/9856368526e6ce5c7a143dd1eeb1edc6 to your computer and use it in GitHub Desktop.
Gunbot Trading View

copy:

function stripHTML(dirtyString) {
    var container = document.createElement('div');
    var text = document.createTextNode(dirtyString);
    container.appendChild(text);
    return container.innerHTML;
}

function gb_data_clean(data){
    var _dl = [' (-1 = -1001)', ' (-0.01 = -1001)', ' (Slow)', ' (Fast)', '  Exchange =', ' placeholder'];
    $(_dl).each(function(i) {
        data = data.replace(_dl[i], '');
    });
    if ($.isNumeric(data)){
        data = data * 1;
    }
    return data;
}
var pre_gun_opts = [];
$('body > div:eq(5) > div > div > div:first > div > div:eq(2) > div > div').each(function(i) {
    var content = $(this).html();
    var len = $(this).find('div').length;
    var text = $("<div/>").html(content).text();
    var _t = stripHTML($.trim(text));

    if (len == 4){
        pre_gun_opts.push(gb_data_clean(_t));

        if($(this).find('input:checked').val()){
            pre_gun_opts.push(true);
        }else{
            pre_gun_opts.push(false);
        }
    }else if (len == 9){
        if($(this).find('input').val()){
            pre_gun_opts.push(gb_data_clean($(this).find('input').val()));
        }else{
            pre_gun_opts.push(false);
        }
    }else if(len == 1 || len == 3){
        pre_gun_opts.push(gb_data_clean(_t));
    }else{
        console.log(len, "missed: "+ _t);
        console.log(content);
    }
});

var gunbot_config = {};
for(var i = 0; i < pre_gun_opts.length; i += 2) {  // take every second element
    gunbot_config[pre_gun_opts[i]] = pre_gun_opts[i+1];
}
function showyourself() {
    var w = window.open('', '', 'width=400,height=400,resizeable,scrollbars');
    w.document.write('<pre>' + JSON.stringify({'tv_strat':gunbot_config}, undefined, 2) + '</pre>');
    w.document.close(); // needed for chrome and safari
}
showyourself()

into

https://chriszarate.github.io/bookmarkleter/ - Follow instructions here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment