Добавил еще ведущие нули к миллисекундам, если кому-то еще когда-то этот код понадобится
log = function (text, color, define){ var id, time, thread, logHtml, textLog; define = (typeof define == 'string') ? define.split(/[\s,.|:;]+/g) : define; if(typeof define === 'object' && define !== null){ if(Array.isArray(define)){ id = define.indexOf('id') > -1; time = define.indexOf('time') > -1; thread = define.indexOf('thread') > -1; } else{ id = define.id == true; time = define.time == true; thread = define.thread == true; } } else id = time = thread = true; id = id ? '<a href="action://action' + ScriptWorker.GetCurrentAction() + '" style="color:gray;">[' + ScriptWorker.GetCurrentAction() + ']</a>' : ''; time = time ? ' ' + getTime() : ''; thread = thread ? ' Поток №' + thread_number() : ''; logHtml = (id || time || thread) ? id + '<span style="color: white">' + time + thread + ' : </span>' : ''; logHtml += '<span style="color:' + (color ? color : 'white') + '">' + text + '</span>'; textLog = '[' + ScriptWorker.GetCurrentAction() + ']' + time + thread + ' : ' + text function getTime(){ var checkTime = function(i){ return (i < 10) ? "0" + i : i; }; var checkMilliSeconds = function(ms){ if (ms < 10) { return "00" + ms; } else if (ms < 100) { return "0" + ms; } else { return ms; } }; var d = new Date(); var hh = checkTime(d.getHours()); var mm = checkTime(d.getMinutes()); var ss = checkTime(d.getSeconds()); var ms = checkMilliSeconds(d.getMilliseconds()); return '[' + hh + ':' + mm + ':' + ss + '.' + ms + ']'; }; Logger.WriteHtml(logHtml, textLog); }Ошибка в работе модуля
-
Впервые создаю собственный модуль, подробно изучил примеры, тем не менее не получается реализовать первое же простейшее действие с добавлением в переменную URL сайта.
С файлом manifest.json всё ок, работает и переводит, а вот где ошибка в действии не могу понять.
Интерфейс действия:
<div class="container-fluid"> <%= _.template($('#input_constructor').html())({id:"WebsiteURL", description:tr("Site URL"), default_selector: "string", disable_int:true, value_string: ""}) %> <%= _.template($('#variable_constructor').html())({id:"WebsiteName", description:tr("Site name"), default_variable: "NEW_WEBSITE"}) %> </div> <%= _.template($('#back').html())({action:"executeandadd", visible:true}) %>Передача в код:
var WebsiteURL = GetInputConstructorValue("WebsiteURL", loader); var WebsiteName = this.$el.find("#WebsiteName").val().toUpperCase(); if(WebsiteURL["original"].length == 0) { Invalid("Website URL is empty"); return; } if(WebsiteName.length == 0) { Invalid("Sitename is empty"); return; } try{ var code = loader.GetAdditionalData() + _.template($("#add_website_code").html())({variable:"VAR_" + WebsiteName,value: WebsiteURL}) code = Normalize(code,0) BrowserAutomationStudio_Append("", BrowserAutomationStudio_SaveControls() + code, action, DisableIfAdd); }catch(e) {}Ну и сам простейший код:
<%= variable %> = <%= value %>При применении действия выводит ошибку "Parse error во время выполнения действия". Переменная с именем сайта создаётся, но url в неё не присваивается.
Пробовал проверять весь код js через экшен "выполнить код", ошибок не обнаружил... Может чего-то не догоняю, но по логике всё ж должно работать?
-
@pragmatik
передача из селекта в код полей, которые прописываются по дефолту, производится с пометкой ["updated"]Т.е. в самом низу вам нужно писать value: WebsiteURL["updated"]
Вы же писали в проверке ["original"] :)
И это всегда так, если дело не касается передачи переменных и значений из html элементов
-
@oyasumi-punpun благодарю, помогло. А как сделать так, чтобы в экшене выводилось значение и имя переменной? А то у меня только стрелочка:

-
@pragmatik в манифесте пропишите правильно template у действия
{{WebsiteURL}} -> {{WebsiteName}}
Будет вида "Ссылка -> Переменная"
{{WebsiteURL}}
Будет вида "Ссылка"
-
@oyasumi-punpun said in Ошибка в работе модуля:
{{WebsiteURL}} -> {{WebsiteName}}
Отлично, благодаря вашим ответам теперь до конца разобрался что к чему.