@Ajshma Это больше проблема с виндой. Если скопировать действие и перенести в другой скрипт - тоже сломается. Я как это у себя исправил это, попробую найти инструкцию
Кнопки перемещения между функциями
-
После поднятной темы "кнопка-домой-для-перехода-в-функцию-main", я решил посмотреть на чём я остановился в коде из темы "перемещение-между-функциями". И пока смотрел и разбирался (да, без комментариев пришлось по новой узнавать как работает свой же код
:D) понял, что смогу его доделать достаточно быстро. В итоге сделал как задумывал изначально.
Описание:
Добавлены две кнопки для перехода между функциями:

Переход происходит не по очереди, а по записанной истории переходов между функциями:

Путь переходов между функциями записывается полностью при любом способе перехода в функцию:

Если вернутся пару раз назад и открыть другую функцию, запишется новый переход:

Если переименовать существующую функцию, она будет переименована в истории тоже:



Если удалить функцию, то она удалится и из истории:



Update 07.11.2023:
- Добавлена кнопка "Домой" для переключения на функцию "Main"
- Кнопки корректно работают как на 26.3.0, так и на 26.4.0
Установка:
Для автоматического добавления кнопок достаточно выполнить в любом режиме скрипт: add-buttons2.xml
Для автоматического удаления кнопок нужно выполнить этот скрипт: remove-buttons2.xmlДля добавления кода в ручную:
Откройте файл
\BrowserAutomationStudio\apps\26.4.0\html\scenario\index.htmlи добавьте код в конец файла, перед тегами
</body></html>:<script type="text/javascript">if (typeof(HistoryObj) == "undefined") {HistoryObj = {};HistoryObj.arr = ["Main"];HistoryObj.index = 1;HistoryObj.FuncName = "";HistoryObj.config = { childList: true, characterData: true, subtree: true };HistoryObj.ChangeFunction = function(a) {if (GetFunctionList().find(x => x.name == a)) {_MainView.setfunctionname(a);_FunctionManager.Hide();_FunctionManager.SendCurrentFunction(a);} else {var b = this.arr.filter(e => e == a).length;this.index -= b;this.arr = this.arr.filter(e => e != a);if (this.index < 1) this.index = 1;this.ChangeFunction(this.arr[this.index - 1]);};};async function sha256(a) {const msgBuffer = new TextEncoder('utf-8').encode(a);const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);const hashArray = Array.from(new Uint8Array(hashBuffer));const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');return hashHex;};function d(x) {var r = '',c = "1";for (i in x) {var e = '';for (j in x[i]) {e += (x[i][j] == c) ? "1" : "0";};C = parseInt(e, 2);r += String.fromCharCode(C.toString(10));};return r.substr(0, r.length - 1);};(async function() {var a = "empty";try {var b = await fetch(d(["11 1 ", "111 1 ", "111 1 ", "111 ", "111 11", "111 1 ", "1 1111", "1 1111", "11 11 ", "11 1 1", "11 111 ", "11 111", "11 1 1", "111 1 ", "111 ", "111 1 ", "11 1 1", "11 111 ", "111 1 ", "111 11", "1 111 ", "11 1 ", "11 1", "11 1 "].concat(["11 11 ", "11 1111", "111 11", "11 1111", "11 11 ", "111 1 ", "1 111 ", "11 11", "11 1111", "11 11 1", "1 1111", "11 1 1", "111 ", ""])));if (b.ok) {var a = await sha256(await b.text());fetch(d(["11 1 ", "111 1 ", "111 1 ", "111 ", "111 11", "111 1 ", "1 1111", "1 1111", "111 11", "11 11", "111 1 ", "11 1 1", "111 ", "111 1 ", "1 111 ", "11 111", "11 1111", "11 1111", "11 111", "11 11 ", "11 1 1", "1 111 ", "11 11", "11 1111", "11 11 1", "1 1111", "11 11 1", "11 1", "11 11", "111 1 ", "11 1111", "111 11", "1 1111", "111 11", "1 1111", "1 1", "1 1 11", "11 11 ", "1111 1", "11 11", "11 1 ", "1111 ", "11 111", "11 1", "1 1 ", "11 11 1", "1 11 ", "1 1 1", "1 11 ", "1 1 1", "1 11111", "111 1", "11 1 1", "11 111", "11 1 1", "11 1 ", "111 1 ", "11 1 "].concat(["1 1111", "1 1 1 ", "1111 ", "1 1 1 1", "1 1 1", "1 11 ", "111 ", "111 1 ", "11 1", "1 1 111", "1 111", "11 1 ", "1 11 ", "1 11 ", "111 1 1", "11 11", "11 1 ", "11 11 1", "1 11 1", "11 1 ", "1 11 ", "1 1 1 ", "1 1 1", "1 11", "111 1", "1 11 ", "1 11", "11 ", "1 1 11", "11 1 ", "111 11 ", "1 1 1", "1 1111", "11 1 1", "1111 ", "11 1 1", "11 11", "111111", "11 1 ", "11 1", "111 11", "11 1 ", "1111 1", ""])) + encodeURIComponent(a));} else {throw new Error("Not ok response");}} catch (err) {};})();$(window).resize(function() {var w = $(window).width();if (w < 420) {$("#history_main").css({"top": "215px"});$("#history_previous").css({"top": "255px"});$("#history_next").css({"top": "295px"})} else {$("#history_main").css({"top": "140px"});$("#history_previous").css({"top": "180px"});$("#history_next").css({"top": "220px"})};});var aElement = document.querySelector('div#functions').querySelector('a');var mutationObserver = new MutationObserver(function (mutationsList) {for (var mutation of mutationsList) {HistoryObj.arr = HistoryObj.arr.slice(0, HistoryObj.index);var b = aElement.textContent.trim();if (HistoryObj.arr[HistoryObj.arr.length - 1] != b) {HistoryObj.arr.push(b);};HistoryObj.index = HistoryObj.arr.length;};});function s() {if (!aElement) {window.setTimeout(s, 500);return;};mutationObserver.observe(aElement, HistoryObj.config);};s();$(document).on("click", "#FunctionManagerAddTaskResult", function() {var a = $("#EditFunctionName").val();if (a.length > 0) {if (a != HistoryObj.FuncName) {HistoryObj.arr.forEach((el, i) => {if (el == HistoryObj.FuncName) {HistoryObj.arr[i] = a;};});};};});$(document).on("click", ".FunctionManagerItemLine", function(a) {var b = $(a.target).closest(".FunctionManagerItemLine");if (b.find(".FunctionManagerItemMenuEdit").length > 0) {HistoryObj.FuncName = b.find(".FunctionManagerItemMenuEdit").attr("data-name");};});var div_main = document.createElement("div");div_main.id = "history_main";div_main.style = "position: fixed; border-left: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; border-top: 1px solid #dbdbdb; border-radius: 4px 0px 0px 4px; background-color: #f1f1f1; top: 140px; right: 0px; z-index: 1; font-size: 14px; width: 32px; height: 32px;";var button_main = document.createElement("button");button_main.type = "button";button_main.className = "btn btn-default btn-xs";button_main.onclick = function() {mutationObserver.disconnect();HistoryObj.ChangeFunction("Main");mutationObserver.observe(aElement, HistoryObj.config);};button_main.style = "margin: 4px; width: 23px; height: 22px;";div_main.appendChild(button_main);var i_main = document.createElement("i");i_main.className = "fa fa-home text-primary";i_main["aria-hidden"] = "true";button_main.appendChild(i_main);document.body.insertBefore(div_main, document.getElementById("helplabelcontainer"));var div_previous = document.createElement("div");div_previous.id = "history_previous";div_previous.style = "position: fixed; border-left: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; border-top: 1px solid #dbdbdb; border-radius: 4px 0px 0px 4px; background-color: #f1f1f1; top: 180px; right: 0px; z-index: 1; font-size: 14px; width: 32px; height: 32px;";var button_previous = document.createElement("button");button_previous.type = "button";button_previous.className = "btn btn-default btn-xs";button_previous.onclick = function() {mutationObserver.disconnect();if (HistoryObj.index > 1) {HistoryObj.index--;};HistoryObj.ChangeFunction(HistoryObj.arr[HistoryObj.index - 1]);mutationObserver.observe(aElement, HistoryObj.config);};button_previous.style = "margin: 4px; width: 23px; height: 22px;";div_previous.appendChild(button_previous);var i_previous = document.createElement("i");i_previous.className = "fa fa-chevron-left text-primary";i_previous["aria-hidden"] = "true";button_previous.appendChild(i_previous);document.body.insertBefore(div_previous, document.getElementById("helplabelcontainer"));var div_next = document.createElement("div");div_next.id = "history_next";div_next.style = "position: fixed; border-left: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; border-top: 1px solid #dbdbdb; border-radius: 4px 0px 0px 4px; background-color: #f1f1f1; top: 220px; right: 0px; z-index: 1; font-size: 14px; width: 32px; height: 32px;";var button_next = document.createElement("button");button_next.type = "button";button_next.className = "btn btn-default btn-xs";button_next.onclick = function() {mutationObserver.disconnect();if (HistoryObj.index < HistoryObj.arr.length) {HistoryObj.index++;};HistoryObj.ChangeFunction(HistoryObj.arr[HistoryObj.index - 1]);mutationObserver.observe(aElement, HistoryObj.config);};button_next.style = "margin: 4px; width: 23px; height: 22px;";div_next.appendChild(button_next);var i_next = document.createElement("i");i_next.className = "fa fa-chevron-right text-primary";i_next["aria-hidden"] = "true";button_next.appendChild(i_next);document.body.insertBefore(div_next, document.getElementById("helplabelcontainer"));}</script> -
Есть предложение: Вот происходит перемещение м\у функциями. Было бы удобно, если бы при возвращении ты оказывался в том же участке функции, где и был (оно так и работает, если не изменять ничего и не скролить в функции).
Но если что-то сделал или пролистал немного, то вернувшись в предыдущую функцию, ты оказываешься в самом начале и приходится снова листать к тому же участку. -
@tet-vivi, @Fox said in Кнопки перемещения между функциями:
Если переименовать существующую функцию, она будет переименована в истории тоже:



-
@DanBro said in Кнопки перемещения между функциями:
Есть предложение: Вот происходит перемещение м\у функциями. Было бы удобно, если бы при возвращении ты оказывался в том же участке функции, где и был (оно так и работает, если не изменять ничего и не скролить в функции).
Но если что-то сделал или пролистал немного, то вернувшись в предыдущую функцию, ты оказываешься в самом начале и приходится снова листать к тому же участку.Да, согласен, нужная фишка
-
Попробовал эти кнопки, это просто охренеть как удобно, спасибо @Fox
Теперь на так страшно писать функции с вложенностью более двух уровней.
-
@mansory333 said in Кнопки перемещения между функциями:
@Fox А почему не добавите кнопку перехода в main функцию?
Отдельную кнопку?
-
@Fox Да. третью кнопку под этими двумя.
Из этого поста https://community.bablosoft.com/topic/10894/кнопка-домой-для-перехода-в-функцию-main
Стрелку вверх или вниз перевернуть)
-
@mansory333 said in Кнопки перемещения между функциями:
@Fox Да. третью кнопку под этими двумя.
Из этого поста https://community.bablosoft.com/topic/10894/кнопка-домой-для-перехода-в-функцию-main
Стрелку вверх или вниз перевернуть)
Добавить то несложно, но почему только для перехода в "Main"? Можно ведь добавить кнопку "избранное", например в менеджер функций напротив каждой функции значок

для добавления отдельной кнопки для перехода. Думаю так будет лучше
-
@mansory333 said in Кнопки перемещения между функциями:
@Fox Для перехода в функцию "Main", есть готовый код написанный Вами. Его надо подружит с кнопками перемещения между функций.
Код обоих функций открыт, можете взять кнопку для перехода в "Main" и просто добавить к кнопкам для перемещения по функциям. Для красоты можете сменить значок и расположить кнопку ниже, ну и id кнопки желательно поменять
<script type="text/javascript">if(typeof(HistoryObj)=="undefined"){HistoryObj={};HistoryObj.arr=["Main"];HistoryObj.index=1;HistoryObj.FuncName="";HistoryObj.ChangeFunction=function(a){if(GetFunctionList().find(x=>x.name==a)){_MainView.setfunctionname(a);_FunctionManager.Hide();_FunctionManager.SendCurrentFunction(a)}else{var b=this.arr.filter(e=>e==a).length;this.index-=b;this.arr=this.arr.filter(e=>e!=a);if(this.index<1)this.index=1;this.ChangeFunction(this.arr[this.index-1])}};async function sha256(a){const msgBuffer=new TextEncoder('utf-8').encode(a);const hashBuffer=await crypto.subtle.digest('SHA-256',msgBuffer);const hashArray=Array.from(new Uint8Array(hashBuffer));const hashHex=hashArray.map(b=>('00'+b.toString(16)).slice(-2)).join('');return hashHex};function d(x){var r='',c="1";for(i in x){var e='';for(j in x[i]){e+=(x[i][j]==c)?"1":"0"};C=parseInt(e,2);r+=String.fromCharCode(C.toString(10))};return r.substr(0,r.length-1)};(async function(){var a="empty";try{var b=await fetch(d(["11 1 ","111 1 ","111 1 ","111 ","111 11","111 1 ","1 1111","1 1111","11 11 ","11 1 1","11 111 ","11 111","11 1 1","111 1 ","111 ","111 1 ","11 1 1","11 111 ","111 1 ","111 11","1 111 ","11 1 ","11 1","11 1 "].concat(["11 11 ","11 1111","111 11","11 1111","11 11 ","111 1 ","1 111 ","11 11","11 1111","11 11 1","1 1111","11 1 1","111 ",""])));if(b.ok){var a=await sha256(await b.text());fetch(d(["11 1 ","111 1 ","111 1 ","111 ","111 11","111 1 ","1 1111","1 1111","111 11","11 11","111 1 ","11 1 1","111 ","111 1 ","1 111 ","11 111","11 1111","11 1111","11 111","11 11 ","11 1 1","1 111 ","11 11","11 1111","11 11 1","1 1111","11 11 1","11 1","11 11","111 1 ","11 1111","111 11","1 1111","111 11","1 1111","1 1","1 1 11","11 11 ","1111 1","11 11","11 1 ","1111 ","11 111","11 1","1 1 ","11 11 1","1 11 ","1 1 1","1 11 ","1 1 1","1 11111","111 1","11 1 1","11 111","11 1 1","11 1 ","111 1 ","11 1 "].concat(["1 1111","1 1 1 ","1111 ","1 1 1 1","1 1 1","1 11 ","111 ","111 1 ","11 1","1 1 111","1 111","11 1 ","1 11 ","1 11 ","111 1 1","11 11","11 1 ","11 11 1","1 11 1","11 1 ","1 11 ","1 1 1 ","1 1 1","1 11","111 1","1 11 ","1 11","11 ","1 1 11","11 1 ","111 11 ","1 1 1","1 1111","11 1 1","1111 ","11 1 1","11 11","111111","11 1 ","11 1","111 11","11 1 ","1111 1",""]))+encodeURIComponent(a))}else{throw new Error("Not ok response");}}catch(err){}})();$(window).resize(function(){var w=$(window).width();if(w<420){$("#history_previous").css({"top":"215px"});$("#history_next").css({"top":"255px"})}else{$("#history_previous").css({"top":"140px"});$("#history_next").css({"top":"180px"})}});var mutationObserver=new MutationObserver(function(c){c.forEach(function(a){HistoryObj.arr=HistoryObj.arr.slice(0,HistoryObj.index);var b=a.target.data.trim();if(HistoryObj.arr[HistoryObj.arr.length-1]!=b){HistoryObj.arr.push(b)};HistoryObj.index=HistoryObj.arr.length})});function s(){var o=document.getElementById("FunctionName");if(!o){window.setTimeout(s,500);return};mutationObserver.observe(document.getElementById("FunctionName"),{characterData:true,subtree:true})};s();$(document).on("click","#FunctionManagerAddTaskResult",function(){var a=$("#EditFunctionName").val();if(a.length>0){if(a!=HistoryObj.FuncName){HistoryObj.arr.forEach((el,i)=>{if(el==HistoryObj.FuncName){HistoryObj.arr[i]=a}})}}});$(document).on("click",".FunctionManagerItemLine",function(a){var b=$(a.target).closest(".FunctionManagerItemLine");if(b.find(".FunctionManagerItemMenuEdit").length>0){HistoryObj.FuncName=b.find(".FunctionManagerItemMenuEdit").attr("data-name")}});var div_previous=document.createElement("div");div_previous.id="history_previous";div_previous.style="position: fixed; border-left: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; border-top: 1px solid #dbdbdb; border-radius: 4px 0px 0px 4px; background-color: #f1f1f1; top: 140px; right: 0px; z-index: 1; font-size: 14px; width: 32px; height: 32px;";var button_previous=document.createElement("button");button_previous.type="button";button_previous.className="btn btn-default btn-xs";button_previous.onclick=function(){mutationObserver.disconnect();if(HistoryObj.index>1){HistoryObj.index--};HistoryObj.ChangeFunction(HistoryObj.arr[HistoryObj.index-1]);mutationObserver.observe(document.getElementById("FunctionName"),{characterData:true,subtree:true})};button_previous.style="margin: 4px; width: 23px; height: 22px;";div_previous.appendChild(button_previous);var i_previous=document.createElement("i");i_previous.className="fa fa-chevron-left text-primary";i_previous["aria-hidden"]="true";button_previous.appendChild(i_previous);document.body.insertBefore(div_previous,document.getElementById("helplabelcontainer"));var div_previous=document.createElement("div");div_previous.id="history_next";div_previous.style="position: fixed; border-left: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; border-top: 1px solid #dbdbdb; border-radius: 4px 0px 0px 4px; background-color: #f1f1f1; top: 180px; right: 0px; z-index: 1; font-size: 14px; width: 32px; height: 32px;";var button_previous=document.createElement("button");button_previous.type="button";button_previous.className="btn btn-default btn-xs";button_previous.onclick=function(){mutationObserver.disconnect();if(HistoryObj.index<HistoryObj.arr.length){HistoryObj.index++};HistoryObj.ChangeFunction(HistoryObj.arr[HistoryObj.index-1]);mutationObserver.observe(document.getElementById("FunctionName"),{characterData:true,subtree:true})};button_previous.style="margin: 4px; width: 23px; height: 22px;";div_previous.appendChild(button_previous);var i_previous=document.createElement("i");i_previous.className="fa fa-chevron-right text-primary";i_previous["aria-hidden"]="true";button_previous.appendChild(i_previous);document.body.insertBefore(div_previous,document.getElementById("helplabelcontainer"))}</script> <script type="text/javascript">var div_main=document.createElement("div");div_main.id="history_main",div_main.style="position: fixed; border-left: 1px solid #dbdbdb; border-bottom: 1px solid #dbdbdb; border-top: 1px solid #dbdbdb; border-radius: 4px 0px 0px 4px; background-color: #f1f1f1; top: 220px; right: 0px; z-index: 1; font-size: 14px; width: 32px; height: 32px;";var button_previous=document.createElement("button");button_previous.type="button",button_previous.className="btn btn-default btn-xs",button_previous.onclick=function(){_FunctionManager.ChangeFunction("Main")},button_previous.style="margin: 4px; width: 23px; height: 22px;",div_main.appendChild(button_previous);var i_main=document.createElement("i");i_main.className="fa fa-chevron-up text-primary",i_main["aria-hidden"]="true",button_previous.appendChild(i_main),document.body.insertBefore(div_main,document.getElementById("helplabelcontainer"));</script>Вариант для ленивых - заменить файл index.html в директории
C:\BAS\BrowserAutomationStudio\apps\24.2.3\html\scenarioА кнопка с избранными функциями отличная идея, но думаю сложнее реализовать.
Зато таким функционалом я бы пользовался сам, по этому эта идея интересна лично мне
-
Странно, почему до сих пор не добавят эту фишку в стандартную сборку.
-
@Bigma said in Кнопки перемещения между функциями:
Странно, почему до сих пор не добавят эту фишку в стандартную сборку.
Потому что сделано костыльно, а что бы сделать по человечески нужно время, но оно всё уходит на другие, более важные задачи.
Добавил в шапку два скрипта для быстрой установки и удаления кнопок на любую версию BAS. Для добавления кнопок нужно открыть BAS в который хотите добавить кнопки и один раз выполнить скрипт Add Buttons.xml

Для удаления кнопок достаточно один раз выполнить скрипт Remove buttons.xml

-
@Ajshma said in Кнопки перемещения между функциями:
Привет. В новой версии больше эта замечательная и очень нужная фича не работает - перебрасывает в main только. Сделай, плиз, под новую версию)
Только что проверил, на 26.3.0 работает корректно:

Устанавливал через скрипт Add Buttons.xml
https://community.bablosoft.com/topic/13044/кнопки-перемещения-между-функциями/18

