var SPNAPI = (function(SPNAPI, $, undefined) { SPNAPI.settings = {}; SPNAPI.getCheckBoxDetails = function(agent) { var extraInfo = ''; switch (agent) { case 'InstantDEX': extraInfo = 'Extra Info on this '+agent+' Agent'; break; case 'pangea': extraInfo = 'Extra Info on this '+agent+' Agent'; break; case 'Jumblr': extraInfo = 'Extra Info on this '+agent+' Agent'; break; case 'MGW': extraInfo = 'Extra Info on this '+agent+' Agent'; break; case 'Atomic': extraInfo = 'Extra Info on this '+agent+' Agent'; break; case 'PAX': extraInfo = 'Extra Info on this '+agent+' Agent'; break; case 'Tradebots': extraInfo = 'Extra Info on this '+agent+' Agent'; break; case 'Wallet': extraInfo = 'Extra Info on this '+agent+' Agent'; break; case 'Jay': extraInfo = 'Extra Info on this '+agent+' Agent'; break; } return extraInfo; } SPNAPI.pageContent.Settings = function () { var filehandle_map = {}; var dirhandle_map = {}; var rows = '

Agents

'; $.each(SPNAPI.methods, function (index, value) { var this_state; $.each(SPNAPI.settings, function (settings_index, settings_value) { $.each(settings_value, function (this_setting_index, this_setting_value) { if(this_setting_value.agent == index) { this_state = this_setting_value.state; } }) }); var checkbox_text = ""; var checkbox_checked = ""; var extraDetails = SPNAPI.getCheckBoxDetails(index); if(this_state == 'inactive') { checkbox_text = 'Disabled'; checkbox_checked = ''; extraDetails = ""; } else { checkbox_text = 'Enabled'; checkbox_checked = 'checked="checked"'; } rows += '' + '
'+ '
'+ '
'+index+'
'+ '
' + '
'+ ''+ '
' + '
' + '
'+extraDetails+'
'+ '
'+ '
'; }); var filename = "/persistent/SuperNET.conf"; var access = "w+"; postCall('fopen', filename, access, function(filename_return, filehandle) { filehandle_map[filehandle] = filename_return; common.logMessage('File ' + filename_return + ' opened successfully.'); console.log(filehandle + " and "+filename_return); }); /* var data = "SuperNETconfigurationsdaaaaa TES TEST TEST TEST"; postCall('fwrite', 0, data, function(filehandle, bytesWritten) { var filename = filehandle_map[filehandle]; common.logMessage('Wrote ' + bytesWritten + ' bytes to file ' + filename + '.'); }); var filesize = ""; postCall('stat', filename, function(filename, size) { common.logMessage('File ' + filename + ' has size ' + size + '.'); filesize = size; }); var filehandle = parseInt(filehandle_map, 10); var numBytes = parseInt(filesize, 10); postCall('fread', 0, 0, function(filehandle, data) { var filename = filehandle_map[filehandle]; common.logMessage('Read "' + data + '" from file ' + filename + '.'); }); */ $("#agent_settings").html(rows); var config = '

Config

'; $("#config_settings").html(config); var agent_checkbox = $('.agent_checkbox'); agent_checkbox.on("click", function () { var checkbox_agent = $(this).val(); var thisCheck = $(this); if (thisCheck.is (':checked')) { $('.checkbox_'+checkbox_agent+'_text').html("Enabled"); var extraDetails = SPNAPI.getCheckBoxDetails(checkbox_agent); $("."+checkbox_agent+"_extra_info").html(extraDetails); } else { $("."+checkbox_agent+"_extra_info").html(''); $('.checkbox_'+checkbox_agent+'_text').html("Disabled"); } }); $("#save_settings").on("click", function () { var agent_checkbox = $('.agent_checkbox'); var settings = []; $.each(agent_checkbox, function(index, value) { var agent = value.value; console.log(agent); var thisCheck = $("#"+agent+"_checkbox"); var state; if (thisCheck.is (':checked')) { state = "active"; } else { state = 'inactive'; } var json = { "agent" : "InstantDEX", "state" : "inactive" }; json.agent = agent; json.state = state; settings.push(json); }); //console.log(settings); var filename = "/persistent/SuperNET.conf"; var access = "w"; postCall('fopen', filename, access, function(filename_return, filehandle) { filehandle_map[filehandle] = filename_return; common.logMessage('File ' + filename_return + ' opened successfully.'); }); //var settings = { "agent" : "InstantDEX", "state" : "active" }; chrome.storage.sync.set({ "settings" : settings }, function() { if (chrome.runtime.error) { console.log("Runtime error."); } }); chrome.storage.sync.get("settings", function(items) { if (!chrome.runtime.error) { //console.log(items); //document.getElementById("data").innerText = items.data; SPNAPI.settings = items; } }); }); }; return SPNAPI; }(SPNAPI || {}, jQuery));