123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265 |
- function initLanguage(langKey) {
- let defaultLang = 'en';
- let lang = langKey || defaultLang;
- if (defaultLang !== lang) {
- injectLanguageJsSources(lang);
- //updateLanguageText();
- }
- }
- var datasetName = ''
- var screenIndex = 0
- // logout
- $("#modal_logout_btn").on("click", function () {
- // logout();
- });
- // if(document.location.host != "beta.v.cocorobo.cn" && document.location.host != "pi.cocorobo.cn"){
- // document.domain = "cocorobo.cn";
- // }
- function logout() {
- $.ajax(`${CCB.base_url}api/logout`, {
- type: "GET",
- xhrFields: {
- withCredentials: true
- },
- success: () => {
- // $('#login_iframe').attr('src', '//staging.cocorobo.hk/login/');
- appendIframe("TM_login");
- $('#TM_login').children().css("height", "820px");
- appendIframe("TM_login_Model_download_modal");
- $('#TM_login_Model_download_modal').children().css("height", "820px");
- $('#TM_login_Model_download_modal').children().css("margin-top", "-225px");
- appendIframe("TM_login_object");
- $('#TM_login_object').children().css("height", "820px");
- appendIframe("TM_login_posenet");
- $('#TM_login_posenet').children().css("height", "820px");
- appendIframe("TM_posenet_login");
- $('#TM_posenet_login').children().css("height", "820px");
- appendIframe("before_login");
- appendIframe("cloud_askLogin");
- appendIframe("TM_login_webcam_capture_modal");
- $('#TM_login_webcam_capture_modal').children().css("width", "820px");
- $('#TM_login_webcam_capture_modal').children().css("height", "820px");
- appendIframe("TM_login_gesture_recog_modal");
- $('#TM_login_gesture_recog_modal').children().css("width", "820px");
- $('#TM_login_gesture_recog_modal').children().css("height", "820px");
- appendIframe("TM_login_voice_input_modal");
- $('#TM_login_voice_input_modal').children().css("width", "820px");
- $('#TM_login_voice_input_modal').children().css("height", "820px");
- appendIframe("TM_center_game");
- $('#TM_center_game').children().css("margin-top", "-300px");
- $('#TM_center_game').children().css("height", "820px");
- Materialize.toast(CCB.str_group.success_userLogout, 4000);
- CCB.userState = false;
- $("#cloud_fileListArea").html("");
- loginModalStatus();
- $("#modal_logout_btn").addClass('blue')
- $(".svgImg").css('display', 'none');
- $(".translate-signout").css('opacity', '1')
- }
- });
- }
- // 点击语言下拉隐藏
- // document.onclick = function () {
- // $('#languages').removeClass('active');
- // $('#languages').css({ display: 'none' })
- // }
- // 点击切换语言
- // $('#nav_language').click(function (e) {
- // $('#languages').addClass('active');
- // $('#languages').css({ display: 'block', opacity: 1, position: 'absolute',top:'64px' })
- // var ev = e || window.event;
- // if (ev.stopPropagation) { //阻止冒泡,否则会触发点击空白区域的事件
- // ev.stopPropagation();
- // } else if (window.event) {
- // window.event.cancelBubble = true; //兼容IE
- // }
- // })
- function getUrlLanguage() {
- const val = location.search.match(new RegExp('[?&]lang=([^&]+)'));
- let language = val ? decodeURIComponent(val[1].replace(/\+/g, '%20')) : '';
- if (['en', 'zh-hant', 'zh-hans'].indexOf(language) < 0) return 'zh-hant';
- return language;
- };
- function injectLanguageJsSources(langKey) {
- const head = document.getElementsByTagName('head')[0];
- // Retrieve and inject Ardublockly translations synchronously
- const appLangJsLoad = document.createElement('script');
- const request = createAjaxRequest();
- const appLangJdPath = `msg/${langKey}.js`;
- try {
- request.open('GET', appLangJdPath, false);
- request.send('');
- appLangJsLoad.text = request.responseText;
- } catch (e) {
- // But still asynchronous lazy load so at least some text gets translated
- appLangJsLoad.src = appLangJdPath;
- }
- head.appendChild(appLangJsLoad);
- // Retrieve and inject Blockly translations asynchronously
- const blocklyLangJsLoad = document.createElement('script');
- blocklyLangJsLoad.src = `blockly/msg/js/${langKey}.js`;
- head.appendChild(blocklyLangJsLoad);
- };
- function createAjaxRequest() {
- let request = false;
- try {
- // Firefox, Chrome, IE7+, Opera, Safari
- request = new XMLHttpRequest();
- } catch (e) {
- // IE6 and earlier
- try {
- request = new ActiveXObject('Msxml2.XMLHTTP');
- } catch (e) {
- try {
- request = new ActiveXObject('Microsoft.XMLHTTP');
- } catch (e) {
- throw 'Your browser does not support AJAX. You will not be able to' +
- 'use all of Ardublockly features.';
- request = null;
- }
- }
- }
- return request;
- };
- function updateLanguageText() {
- for (let textId in LOCALISED_TEXT) {
- const textStrings = document.getElementsByClassName(`translate-${textId}`);
- for (let i = 0; i < textStrings.length; i++) {
- textStrings[i].innerHTML = LOCALISED_TEXT[textId];
- }
- }
- };
- function clearBlocks(cb = () => { }) {
- const length = Blockly.mainWorkspace.getAllBlocks(true).length;
- if (length < 2) {
- Blockly.mainWorkspace.clear();
- cb();
- } else {
- Blockly.confirm(
- Blockly.Msg.DELETE_ALL_BLOCKS.replace("%1", length),
- ok => {
- if (!ok) return;
- Blockly.mainWorkspace.clear();
- cb();
- }
- );
- }
- }
- function addLibButton(lang) {
- // const addLib = document.createElement("button");
- // addLib.className = "waves-effect waves-light btn blue";
- // let content = lang === 'zh-hans' ? "添加库" : lang === 'zh-hant' ? "添加庫" : "Add Library";
- // addLib.textContent = content;
- // addLib.style = `
- // position: absolute;
- // width: 88%;
- // bottom: 10px;
- // left: 50%;
- // transform: translateX(-50%);
- // `;
- // $(addLib).click(e =>
- // blockpy.components.dialog.show("Add Library", document.createElement("div")));
- // $(".blocklyToolboxDiv").append(addLib);
- }
- // /**
- // * Save blocks into local storage. Note that MSIE 11 does not support
- // * LocalStorage on file:// URLs.
- // */
- // function saveLocalStorageBlocks() {
- // if (window.sessionStorage) {
- // var xml = blockpy.components.editor.getBlocksFromXml();
- // var text = Blockly.Xml.domToText(xml);
- // localStorage.setItem("blocks", text);
- // }
- // // blockpy.components.editor.getBlocksFromXml()
- // };
- // /** Load blocks saved on loacl storage and deletes them from storage. */
- // function loadLocalStorageBlocks() {
- // // try {
- // // var loadOnce = window.localStorage.loadOnceBlocks;
- // // } catch (e) {
- // // // Firefox sometimes throws a SecurityError when accessing sessionStorage.
- // // // Restarting Firefox fixes this, so it looks like a bug.
- // // var loadOnce = null;
- // // }
- // var loadBlocks = localStorage.getItem("blocks");
- // if (loadBlocks) {
- // var xml = Blockly.Xml.textToDom(loadBlocks);
- // blockpy.components.editor.setBlocksFromXml(xml);
- // localStorage.removeItem('blocks')
- // }
- // };
- var copyCodeClipboard;
- window.onbeforeunload = window.onunload = function () {
- if ($("#mode")[0].selectedIndex == 0) {
- saveLocalStorage("type", 1);
- saveLocalStorageBlocks("pythonai-mode-blocks-xml");
- } else {
- saveLocalStorage("type", 1);
- saveLocalStorageBlocks("pythonai-mode-blocks-xml");
- }
- }
- function getJsonData(filepath) {
- return new Promise(resolve => {
- $.getJSON(filepath, data => resolve(data));
- });
- }
- var isRunCodeData = '';
- var RunInterval = '';
- window.onload = async function () {
- var url = window.location.hash.substring(1);
- // if (url) {
- // document.getElementById('ipAddress').value = 'ws://' + url;
- // }
- // document.domain = "cocorobo.cn";
- $('.dropdown-trigger').dropdown();
- setTimeout(() => $('.modal').modal(), 0);
- let xmlName = '图像传输显示电脑.xml'
- readTxt("src/python/" + xmlName, function (txt) {
- if (xmlName.split(".")[1] == "xml") {
- var xmlfile = Blockly.Xml.textToDom(txt);
- blockpy.components.editor.setBlocksFromXml(xmlfile);
- } else {
- blockpy.components.editor.codeMirror.setValue(txt);
- }
- saveLocalStorageBlocks("pythonai-mode-blocks-xml");
- // setTimeout(() => {
- // $('#loading').css({ 'display': 'none' });
- // $('#example_alert').modal('close');
- // }, 300)
- });
- blockpy = new BlockPy({
- blocklyPath: "blockly/",
- attachmentPoint: document.getElementById("blockpy-div"),
- instructor:
- !getQueryParams()["instructor"] ||
- getQueryParams()["instructor"] == "true",
- developer: true,
- editor: getQueryParams()["mode"] || "Split",
- urls: {
- }
- });
- // ready();
- var size = calculate_size($("#term")[0]);
- term = new Terminal({
- cols: size[0],
- rows: size[1],
- useStyle: true,
- screenKeys: true,
- cursorBlink: false
- });
- term.open(document.getElementById("term"));
- //show_https_warning();
- $(".filled-in")[0].onclick = function () {
- var _chi = $(".filled-in")[0];
- var _par = $(".filled-in")[0].parentNode;
- if (!_chi.checked) {
- _par.children[1].className = 'filled-in_nocheked translatable_Adapter_fill_connected';
- _par.children[1].innerHTML = CCB.str_group.Adapter_fill_connected;
- } else {
- _par.children[1].className = 'translatable_Adapter_connected';
- _par.children[1].innerHTML = CCB.str_group.Adapter_connected;
- };
- }
- setTimeout(() => {
- cocoblockly();
- }, 0);
- $('.blockpy-toolbar-download').on(
- "click", () => export_data(
- pythonnewcode || Blockly.Python.workspaceToCode(blockpy.components.editor.blockly) || blockpy.components.editor.codeMirror.getValue(), '.py', 0
- )
- );
- // uploadpy
- document.getElementById('uploadpy').onclick = function () {
- window.file_manger_modal = false
- $("#runCode").addClass('disabled')
- $("#uploadpy").addClass('disabled')
- $("#resetDevice").addClass('disabled')
- $("#poweroff").addClass('disabled')
- $("#backHome").addClass('disabled')
- // 上传
- $('.progress > .determinate').css('width', 10);
- // 这么写是因为文件转换是异步任务
- transToFile = async (blob, fileName, fileType) => {
- return new window.File([blob], fileName, { type: fileType })
- }
- let text = pythonnewcode || Blockly.Python.workspaceToCode(blockpy.components.editor.blockly) || blockpy.components.editor.codeMirror.getValue()
- // console.log(text)
- // 开始上传
- // function test(){
- let blob = new Blob([text], { type: "text/plain;charset=utf-8" })
- let textContain = transToFile(blob, "user_latest_code.py", "text/plain")
- if (isWifiContent) {
- sendWebsocket(text, 'upload')
- } else {
- // 转换完成后可以将file对象传给接口
- textContain.then((res) => {
- let file = res;
- // window.stateapi.upload(file,"/root/")
- $('.progress > .determinate').css('width', '50%');
- setTimeout(() => {
- if (file) {
- $('.progress > .determinate').css('width', '100%');
- document.getElementById('webadb_iframe').contentWindow.upload(file, "/root/")
- } else {
- $('.progress > .determinate').css('width', 0);
- }
- window.file_manger_modal = true
- $("#runCode").removeClass('disabled')
- $("#uploadpy").removeClass('disabled')
- $("#resetDevice").removeClass('disabled')
- $("#poweroff").removeClass('disabled')
- }, 500)
- })
- }
- // }
- }
- // runCode
- document.getElementById('runCode').onclick = async function () {
- window.file_manger_modal = false
- $("#runCode").addClass('disabled')
- $("#uploadpy").addClass('disabled')
- $("#resetDevice").addClass('disabled')
- $("#poweroff").addClass('disabled')
- $("#backHome").addClass('disabled')
- $('.progress > .determinate').css('width', 0);
- $("#error-btn").css("display", "none")
- transToFile = async (blob, fileName, fileType) => {
- return new window.File([blob], fileName, { type: fileType })
- }
- let text = pythonnewcode || Blockly.Python.workspaceToCode(blockpy.components.editor.blockly) || blockpy.components.editor.codeMirror.getValue()
- let blob = new Blob([text], { type: "text/plain;charset=utf-8" })
- //let textContain =
- let file = await transToFile(blob, "user_latest_code.py", "text/plain")
- if (isWifiContent) {
- // 无线连接
- sendWebsocket(text, 'run')
- $('.progress > .determinate').css('width', '50%');
- } else {
- await document.getElementById('webadb_iframe').contentWindow.upload(file, "/root/");
- $('.progress > .determinate').css('width', '50%');
- clearInterval(RunInterval);
- if (isRunCodeData) {
- isRunCodeData.kill().then(() => {
- run_user_lastet_code()
- })
- }
- else {
- run_user_lastet_code()
- }
- setTimeout(function () {
- $('.progress > .determinate').css('width', '100%');
- window.file_manger_modal = true
- $("#runCode").removeClass('disabled')
- $("#uploadpy").removeClass('disabled')
- $("#resetDevice").removeClass('disabled')
- $("#poweroff").removeClass('disabled')
- }, 2000);
- }
- //})
- }
- const uploadXmlButton = $('#pyFileImport > input');
- uploadXmlButton.change(function () {
- var fr = new FileReader();
- var files = uploadXmlButton[0].files;
- const file = files[0];
- Ardublockly.alertExampleMessage(
- '', Ardublockly.getLocalStr('loadBlockBody'),
- true, {});
- fr.onload = function (e) {
- var pyInnerHTML = e.target.result;
- blockpy.components.editor.codeMirror.setValue(pyInnerHTML);
- };
- fr.readAsText(file);
- setTimeout(() => {
- $('#loading').css({ 'display': 'none' });
- $('#example_alert').modal('close');
- }, 300)
- uploadXmlButton.val("");
- });
- $('.blockpy-toolbar-upload').click(e => $('#pyFileImport > input').click());
- fanyi();
- selectOnload();
- styled()
- // let iframe = document.createElement("iframe")
- // iframe.src = window.location.host.indexOf("beta") > -1 ? "//beta.project-x.cocorobo.cn/" : '//project-x.cocorobo.cn/';
- // iframe.style.width = "100%";
- // iframe.style.height = "99%";
- // iframe.style.border = "none";
- // document.getElementById('iframe').appendChild(iframe)
- // $('#select_mode')[0].onchange = function(e){
- // var e = e.target;
- // selectmode(e.selectedIndex);
- // var _index = e.selectedIndex;
- // localStorage.setItem("ModeIndex",_index);
- //
- // }
- // var _index = localStorage.getItem("ModeIndex") != "undefined" ? localStorage.getItem("ModeIndex") : 0;
- // selectmode(parseInt(_index));
- // $('#select_mode')[0].selectedIndex = parseInt(_index);
- $('#toggle-button').click(() => {
- if ($('#toggle-button')[0].checked) {
- $('#edit')[0].style.display = 'none';
- // $('.translatable_editing')[0].style.display = "none";
- // $('.translatable_close_editing')[0].style.display = "inline-block"
- } else {
- $('#edit')[0].style.display = 'block';
- // $('.translatable_editing')[0].style.display = "inline-block";
- // $('.translatable_close_editing')[0].style.display = "none"
- }
- })
- const _lang = getUrlLanguage();
- if (window.location.search.indexOf('datasetName') > -1) {
- datasetName = window.location.search.split('datasetName=')[1]
- screenIndex = 0
- $.ajax(`//traininguser-api.cocorobo.cn/v831_update_code_connect_device`, {
- type: "POST",
- dataType: "json",
- contentType: 'application/json;charset=utf-8',
- data: JSON.stringify({ "DatasetName": datasetName }),
- success: (res) => {
- console.log(res)
- Materialize.toast(CCB.str_group.connection_success, 4000);
- }
- });
- }
- // 判断从python blcokly 跳转过来是ai或者iot
- if (window.location.search.indexOf('name=1') > -1 || window.location.search.indexOf('id=ai') > -1) {
- $("#mode")[0].selectedIndex = 1;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
- history.pushState(null, null, '//x.cocorobo.cn/?lang=' + _lang);
- selectmode($("#mode")[0], true);
- // document.getElementById("list").getElementsByTagName("li")[1].onclick();
- }
- else if (window.location.search.indexOf('name=0') > -1 || window.location.search.indexOf('id=iot') > -1) {
- $("#mode")[0].selectedIndex = 0;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
- history.pushState(null, null, '//x.cocorobo.cn/?lang=' + _lang);
- selectmode($("#mode")[0], true);
- // document.getElementById("list").getElementsByTagName("li")[0].onclick();
- }
- else {
- if (getLocalStorage("type") == 1) {
- $("#mode")[0].selectedIndex = 1;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
- selectmode($("#mode")[0], true);
- // document.getElementById("list").getElementsByTagName("li")[1].onclick();
- } else {
- $("#mode")[0].selectedIndex = 0;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
- selectmode($("#mode")[0], true);
- // document.getElementById("list").getElementsByTagName("li")[0].onclick();
- }
- }
- $('#white-box').css('display', 'none');
- const copyCodeClipboard = new ClipboardJS(".copy_code", {
- text: function () {
- return blockpy.components.editor.codeMirror.getValue();
- // const codes = $(".CodeMirror-code pre");
- // let target = "";
- // for (let i = 0; i < codes.length; i++) {
- // let line = codes[i].textContent;
- // !(line.length === 1 && line.charCodeAt(0) === 8203) ? target += line : "";
- // i !== codes.length - 1 ? target += "\n" : "";
- // }
- // return target;
- }
- });
- copyCodeClipboard.on("success", () => copyCodeToast(2000));
- mouseMove();
- const copyCodeToast = (function (lang) {
- let toast = null,
- timeout = null;
- const content = lang === 'zh-hans' ? "复制成功" :
- lang === 'zh-hant' ? "複製成功" : "Copy Successfully";
- return function (ms) {
- if (toast) {
- toast.dismiss();
- clearTimeout(timeout);
- }
- toast = Materialize.toast(content, ms);
- timeout = setTimeout(() => toast = timeout = null, ms);
- };
- })(_lang);
- $("#delete-all").click(() => clearBlocks());
- $("#screenshot").click(() => Blockly.captureDialog_());
- $("#clearOutput").click(() => $(".blockpy-printer").html(""));
- $("#resetAll").click(() => clearBlocks(() => $(".blockpy-printer").html("")));
- // $("#lang-tool").click(() => $("#side-lang-trigger > a").dropdown('open'));
- // $("#file-tool").click(() => $("#side-file-trigger > a").dropdown('open'));
- $("#blockpy-content > .blockpy-editor img.fullscreenIcon").click(e => {
- $(e.currentTarget.parentNode).toggleClass("fullscreen");
- $('#edit')[0].style.display = 'none';
- $("#blockpy-content > .blockpy-editor img.fullscreenIcon").toggleClass("hidden");
- $("html").toggleClass("fullscreenMode");
- setTimeout(function () {
- Blockly.svgResize(blockpy.components.editor.blockly);
- Blockly.svgResize(Blockly.mainWorkspace);
- }, 100)
- });
- $("#blockpy-content .card-header > img.fullscreenIcon").click(e => {
- $(e.currentTarget.parentNode.parentNode).toggleClass("fullscreen");
- $('#edit')[0].style.display = 'block';
- $("#blockpy-content .card-header > img.fullscreenIcon").toggleClass("hidden");
- $("html").toggleClass("fullscreenMode");
- setTimeout(() => $(".blockpy-toolbar > .blockpy-text")
- .css("height", "90%")
- .css("height", "100%"), 0);
- });
- let browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- if (browserWidth < 500) {
- $('.mobileSwitch')[0].style.display = "block"
- $('#py-editor')[0].style.display = "none"
- // $("#IP")[0].style.display = "block"
- // isWifiContent = true
- }
- // 提示全屏
- // setTimeout(() => {
- // // if (document.body.clientWidth < 1265) {
- // // alert(CCB.str_group.alert)
- // // }
- // myChart = echarts.init(document.getElementById('echartsMain'));
- // window.onresize = function () {
- // myChart.resize();
- // }
- // }, 1000)
- // 加载echarts
- // myChart = myChart = echarts.init(document.getElementById('echartsMain'));
- // window.onresize = function () {
- // myChart.resize();
- // }
- // 点击复制分享链接
- copyShare()
- let autoContent = 0
- window.file_manger_modal = true
- document.getElementById("webadb_iframe").onload = function () {
- setInterval(function () {
- if (document.getElementById("webadb_iframe").contentWindow.getdevice && window.file_manger_modal && !isWifiContent) {
- isDevice = document.getElementById("webadb_iframe").contentWindow.getdevice();
- isConnect = document.getElementById("webadb_iframe").contentWindow.isconnect()
- if (isDevice.device == undefined && isDevice.selectdevice == undefined) {
- $("#webadb_connect")[0].disabled = true;
- $("#webadb_add")[0].disabled = false;
- $("#runCode").addClass('disabled')
- $("#uploadpy").addClass('disabled')
- $("#resetDevice").addClass('disabled')
- $("#backHome").addClass('disabled')
- $("#poweroff").addClass('disabled')
- $('#message_file').css({ display: 'none' })
- $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn;
- $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusNotConn
- $('.progress > .determinate').css('width', 0);
- $('#cnt_icon').css('display', 'none')
- $('#discnt_icon').css('display', 'inline-block')
- $('#select-connected').attr("disabled", false)
- }
- else if (isDevice.device == undefined && isDevice.selectdevice != undefined) {
- $("#webadb_connect")[0].disabled = false;
- $("#webadb_add")[0].disabled = false;
- $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusNotConn
- $("#runCode").addClass('disabled')
- $("#uploadpy").addClass('disabled')
- $("#resetDevice").addClass('disabled')
- $("#backHome").addClass('disabled')
- $("#poweroff").addClass('disabled')
- $('#message_file').css({ display: 'none' })
- $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn;
- $('.progress > .determinate').css('width', 0);
- $('#cnt_icon').css('display', 'none')
- $('#discnt_icon').css('display', 'inline-block')
- $('#select-connected').attr("disabled", false)
- // if(autoContent<5){
- // setTimeout(()=>{
- // serialSwich('Serial_Interaction')
- // document.getElementById("webadb_iframe").contentWindow.document.getElementById("usbconnect").click()
- // $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.disConnect
- // autoContent++
- // },2000)
- // }else{
- // console.log('111111')
- // // alert('你的板子已在其他页面连接成功')
- // }
- }
- else if (isDevice.device != undefined && isDevice.selectdevice != undefined) {
- $("#webadb_add")[0].disabled = true;
- if (!!isConnect) {
- $('#select-connected').attr("disabled", true)
- $('#cnt_icon').css('display', 'inline-block')
- $('#discnt_icon').css('display', 'none')
- $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.disConnect
- $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusbar
- $("#webadb_connect")[0].disabled = false;
- $('#message_file').css({ display: 'inline-block' })
- $("#runCode").removeClass('disabled')
- $("#uploadpy").removeClass('disabled')
- $("#resetDevice").removeClass('disabled')
- $("#poweroff").removeClass('disabled')
- } else {
- $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn;
- $("#webadb_connect")[0].disabled = true;
- $('#message_file').css({ display: 'none' })
- }
- }
- }
- }, 1000)
- }
- // 加载更新提示框
- let updateData = await getJsonData('./update.json');
- // 最新更新你内容
- let updateNew = _lang == "zh-hans" ? updateData.updateNew.zhHans : _lang == "zh-hant" ? updateData.updateNew.zhHant : updateData.updateNew.en;
- let isUpdate = localStorage.getItem('isUpdate') || 0
- let blocklLis = "";
- let exampleLis = "";
- let noteLis = ""
- for (let i = 0; i < updateNew.blocks.length; i++) {
- let blockLi = `<li>${updateNew.blocks[i]}</li>`
- blocklLis = blocklLis + blockLi
- }
- $('#blockLis').append(blocklLis)
- for (let i = 0; i < updateNew.example.length; i++) {
- let exampleLi = `<li>${updateNew.example[i]}</li>`
- exampleLis = exampleLis + exampleLi
- }
- $('#exampleLis').append(exampleLis)
- for (let i = 0; i < updateNew.note.length; i++) {
- let noteLi = `<li>${updateNew.note[i]}</li>`
- noteLis = noteLis + noteLi
- }
- $('#noteLis').append(noteLis)
- $('.updateTime')[0].innerHTML = updateData.updateNew.time
- // 历史更新
- let updateDataOld = updateData.updateOld
- let leftStr = ''
- let noteStr = ''
- for (let i = 0; i < updateDataOld.length; i++) {
- let data = updateDataOld[i]
- let time = `<h5>${data.time}</h5>`;
- let updateData = _lang == "zh-hans" ? data.zhHans : _lang == "zh-hant" ? data.zhHant : data.en;
- let blocklLisOld = ''
- let exampleLisOld = ''
- let noteLisOld = ''
- for (let i = 0; i < updateData.blocks.length; i++) {
- let blockLi = `<li>${updateData.blocks[i]}</li>`
- blocklLisOld = blocklLisOld + blockLi
- }
- for (let i = 0; i < updateData.example.length; i++) {
- let exampleLi = `<li>${updateData.example[i]}</li>`
- exampleLisOld = exampleLisOld + exampleLi
- }
- for (let i = 0; i < updateData.note.length; i++) {
- let noteLi = `<li>${updateData.note[i]}</li>`
- noteLisOld = noteLisOld + noteLi
- }
- leftStr = leftStr + `${time}<li>积木<ul class="updateContent">${blocklLisOld}</ul></li><li>样例<ul class="updateContent">${exampleLisOld}</ul></li>`
- noteStr = noteStr + `${time}${noteLisOld}`
- }
- $('#leftUpdateOld').append(leftStr)
- $('#noteLisOld').append(noteStr)
- // $("#root").modal("open");
- setTimeout(() => {
- // // if (isUpdate < 2) {
- // $("#select_Example_modal").modal("close");
- // $("#loadModal").modal("open");
- // localStorage.setItem('isUpdate', Number(isUpdate) + 1)
- // // }
- }, 3000);
- }
- function styled() {
- if (window.location.search.indexOf("en") > -1) {
- $(".downbox-style").css({ width: '280px', marginLeft: '-100px' }),
- $(".HarxA1").css({ left: "calc(100% - 610px)" });
- $('#aaa .HarxA1').addClass('HarxA1_style')
- // $(".container-bottom").css("height","390px")
- $(".modelDownloadItemTitle").css("marginTop", "15px");
- $(".vision_category").css("marginTop", "15px");
- $(".model_download_modal_column").css("height", "435px");
- $(".modelDownloadItemDesc").css("height", "110px");
- }
- }
- function fanyi() {
- $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn
- $('.ModeSelect')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Example;
- $('.ModeBox')[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.artificial_intelligence_textbook_program;
- $('.Hardware9 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.third_grade;
- $('.ModeBox ul')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
- $('.ModeBox ul')[0].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.voice_recognition_lamp_stand;
- $('.Hardware4n div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.four_grade;
- $('.ModeBox ul')[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_aifr;
- $('.ModeBox ul')[1].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaor;
- $('.Hardware5 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.fifth_grade;
- $('.ModeBox ul')[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
- $('.ModeBox ul')[2].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_curtain;
- $('.ModeBox ul')[2].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.fruit_picking_robot;
- $('.ModeBox ul')[2].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.fntelligent_inspection_robot;
- $('.Hardware6 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.sixth_grade;
- $('.ModeBox ul')[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_traffic_lights;
- $('.ModeBox ul')[3].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.seeing_eye_necklace;
- $('.ModeBox ul')[3].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.code_package_sorting_robot;
- $('.ModeBox ul')[3].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.unmanned_circulation_car;
- $('.Hardware7 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.seventh_grade;
- $('.ModeBox ul')[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.face_recognition_electronic_police;
- $('.Hardware8 div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.eighth_grade;
- $('.ModeBox ul')[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.payment_platform;
- $('.ModeBox')[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Basics;
- $('.ModeBox ul')[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcb;
- $('.ModeBox ul')[6].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcsl;
- $('.ModeBox ul')[6].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_tacl;
- $('.ModeBox ul')[6].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ba;
- $('.ModeBox ul')[6].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_desl;
- $('.ModeBox ul')[6].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_tdsl;
- $('.ModeBox ul')[6].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ha;
- $('.ModeBox ul')[6].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ssl;
- $('.ModeBox ul')[6].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ldliv;
- $('.ModeBox')[0].children[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_imefc;
- $('.ModeBox ul')[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_uls;
- $('.ModeBox ul')[7].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_umdm;
- $('.ModeBox ul')[7].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_uoglls;
- $('.ModeBox ul')[7].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
- $('.ModeBox ul')[7].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctsotem;
- $('.ModeBox ul')[7].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_thwos;
- $('.ModeBox ul')[7].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
- $('.ModeBox ul')[7].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_line;
- $('.ModeBox ul')[7].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
- $('.ModeBox ul')[7].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_stepCounter;
- $('.ModeBox ul')[7].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_stepCounter_1;
- $('.ModeBox ul')[7].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_bluetooth_send;
- $('.ModeBox ul')[7].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_bluetooth_receive;
- $('.ModeBox')[0].children[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ionc;
- $('.ModeBox ul')[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_btsldtc;
- $('.ModeBox ul')[8].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_ktsedti;
- $('.ModeBox ul')[8].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_btoldalua;
- $('.ModeBox ul')[8].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_tsedtc;
- $('.ModeBox ul')[8].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_toedaluatc;
- $('.ModeBox ul')[8].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_ewhadtnocd;
- $('.ModeBox ul')[8].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledss;
- $('.ModeBox ul')[8].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledac;
- $('.ModeBox ul')[8].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctwn;
- $('.ModeBox ul')[8].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_bssbms;
- $('.ModeBox ul')[8].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_bsrbmc;
- $('.ModeBox ul')[8].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbms;
- $('.ModeBox ul')[8].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbmr;
- $('.ModeBox ul')[8].children[13].innerHTML = Ardublockly.LOCALISED_TEXT.select_snt;
- $('.ModeBox ul')[8].children[14].innerHTML = Ardublockly.LOCALISED_TEXT.select_dwsdat;
- $('.ModeBox')[0].children[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_work_u;
- $('.ModeBox ul')[9].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_middle_led;
- $('.ModeBox ul')[9].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_all_led;
- $('.ModeBox ul')[9].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_liu_led;
- $('.ModeBox ul')[9].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_warning;
- $('.ModeBox ul')[9].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_music;
- $('.ModeBox ul')[9].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_button_open;
- $('.ModeBox ul')[9].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_touch_open;
- $('.ModeBox ul')[9].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_button_close;
- $('.ModeBox ul')[9].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_control_LED;
- $('.ModeBox ul')[9].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_sensor_LED;
- $('.ModeBox ul')[9].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_humidity_alarm;
- $('.ModeBox')[0].children[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_work_d;
- $('.ModeBox ul')[10].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_shaking_LED;
- // $('.ModeBox ul')[4].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_connect_wifi;
- $('.ModeBox ul')[10].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_show_statement;
- $('.ModeBox ul')[10].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_establish_WiFi;
- $('.ModeBox ul')[10].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_download_lighting;
- $('.ModeBox ul')[10].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_controlling_servo;
- $('.ModeBox ul')[10].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_move_servo;
- $('.ModeBox ul')[10].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_button_controlling_servo;
- $('.ModeBox ul')[10].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_face_recognition_door;
- $('.ModeBox ul')[10].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_speech_recognition_car;
- $('.ModeBox ul')[10].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_gyro_control_robot;
- $('.ModeBox ul')[10].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_gesture_recognition_robot;
- $('.ModeBox ul')[10].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_speech_recogniton_lamp;
- $('.ModeBox')[0].children[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_smmlc;
- $('.ModeBox ul')[11].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.basis_face_Intelligent;
- $('.ModeBox ul')[11].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_gcaerhk;
- $('.ModeBox ul')[11].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_frs;
- $('.ModeBox ul')[11].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ors;
- $('.ModeBox ul')[11].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_fr;
- $('.ModeBox ul')[11].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_or;
- $('.ModeBox ul')[11].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_srd;
- $('.ModeBox ul')[11].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_srt;
- $('.ModeBox ul')[11].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_mhdr;
- $('.ModeBox')[0].children[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ambc;
- $('.ModeBox ul')[12].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bcsc;
- $('.ModeBox ul')[12].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpccs;
- $('.ModeBox ul')[12].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_kcpficc;
- $('.ModeBox ul')[12].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
- $('.ModeBox ul')[12].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_mc;
- $('.ModeBox ul')[12].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_sor;
- $('.ModeBox ul')[12].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
- $('.ModeBox')[0].children[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amefc;
- $('.ModeBox ul')[13].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_auls;
- $('.ModeBox ul')[13].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aumdm;
- $('.ModeBox ul')[13].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
- $('.ModeBox ul')[13].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_actsotem;
- $('.ModeBox ul')[13].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_greedy_snake;
- $('.ModeBox')[0].children[9].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_amvc;
- $('.ModeBox ul')[14].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_bctbotci;
- $('.ModeBox ul')[14].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aca;
- $('.ModeBox ul')[14].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_rqc;
- $('.ModeBox ul')[14].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_lhbl;
- $('.ModeBox ul')[14].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgr;
- $('.ModeBox ul')[14].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_fgaat;
- $('.ModeBox')[0].children[10].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_av;
- $('.ModeBox ul')[15].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.paly_video;
- $('.ModeBox ul')[15].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.paly_music;
- $('.ModeBox ul')[15].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.recording_camera;
- $('.ModeBox ul')[15].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.microphone_sound_analysis;
- $('.ModeBox')[0].children[11].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_teacher;
- $('.ModeBox ul')[16].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thw;
- $('.ModeBox ul')[16].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thwos;
- $('.ModeBox ul')[16].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_uoc;
- $('.ModeBox ul')[16].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_mc;
- $('.ModeBox ul')[16].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_sor;
- $('.ModeBox')[0].children[12].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_teacher2;
- $('.ModeBox ul')[17].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaor;
- $('.ModeBox ul')[17].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aifr;
- $('.ModeBox ul')[17].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_aica;
- $('.ModeBox ul')[17].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_aisrc;
- $('.ModeBox ul')[17].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_aisrr;
- $('.ModeBox ul')[17].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaa;
- $('.ModeBox')[0].children[13].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_teachingcases;
- $('.ModeBox ul')[18].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ex1_servo;
- $('.ModeBox ul')[18].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ex2_Ultrasound;
- // $('.ModeBox ul')[12].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ex3_RangeFinder;
- // $('.ModeBox ul')[12].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ex4_LightStrip;
- // $('.ModeBox ul')[12].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ex5_Microbit;
- // $('.ModeBox ul')[12].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.ex6_MicrobitFace;
- // $('.ModeBox ul')[12].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.ex7_Door;
- $('.ModeBox ul')[18].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ex4_LightStrip
- $('.ModeBox ul')[18].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ex5_Microbit;
- $('.ModeBox ul')[18].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.ex6_MicrobitFace;
- $('.ModeBox ul')[18].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.ex7_Door;
- $('.ModeBox')[0].children[14].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_wc;
- $('.ModeBox ul')[19].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_smaa;
- $('.ModeBox ul')[19].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_gc;
- $('.ModeBox ul')[19].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_wsb;
- $('.ModeBox')[0].children[15].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_ad;
- $('.ModeBox ul')[20].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_trsr;
- $('.ModeBox ul')[20].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpl2;
- $('.ModeBox ul')[20].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpll;
- $('.ModeBox ul')[20].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tph;
- $('.ModeBox')[0].children[16].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm;
- $('.ModeBox ul')[21].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm_iot_send;
- $('.ModeBox ul')[21].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm_ai_get;
- $('.ModeBox ul')[21].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm_ai_send;
- $('.ModeBox ul')[21].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.serial_comm_iot_get;
- $('.ModeBox1')[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.artificial_intelligence_textbook_program;
- $('.Hardware9 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.third_grade;
- $('.ModeBox1 ul')[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
- $('.ModeBox1 ul')[0].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.voice_recognition_lamp_stand;
- $('.Hardware4n div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.four_grade;
- $('.ModeBox1 ul')[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_aifr;
- $('.ModeBox1 ul')[1].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_aiaor;
- $('.Hardware5 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.fifth_grade;
- $('.ModeBox1 ul')[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.recorded_voice_command;
- $('.ModeBox1 ul')[2].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_curtain;
- $('.ModeBox1 ul')[2].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.fruit_picking_robot;
- $('.ModeBox1 ul')[2].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.fntelligent_inspection_robot;
- $('.Hardware6 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.sixth_grade;
- $('.ModeBox1 ul')[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.intelligent_traffic_lights;
- $('.ModeBox1 ul')[3].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.seeing_eye_necklace;
- $('.ModeBox1 ul')[3].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.code_package_sorting_robot;
- $('.ModeBox1 ul')[3].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.unmanned_circulation_car;
- $('.Hardware7 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.seventh_grade;
- $('.ModeBox1 ul')[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.face_recognition_electronic_police;
- $('.Hardware8 div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.eighth_grade;
- $('.ModeBox1 ul')[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.payment_platform;
- $('.ModeBox1')[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_Basics;
- $('.ModeBox1 ul')[6].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcb;
- $('.ModeBox1 ul')[6].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_sbcsl;
- $('.ModeBox1 ul')[6].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_tacl;
- $('.ModeBox1 ul')[6].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ba;
- $('.ModeBox1 ul')[6].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_desl;
- $('.ModeBox1 ul')[6].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_tdsl;
- $('.ModeBox1 ul')[6].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ha;
- $('.ModeBox1 ul')[6].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ssl;
- $('.ModeBox1 ul')[6].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ldliv;
- $('.ModeBox1')[0].children[2].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_imefc;
- $('.ModeBox1 ul')[7].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_uls;
- $('.ModeBox1 ul')[7].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_umdm;
- $('.ModeBox1 ul')[7].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_uoglls;
- $('.ModeBox1 ul')[7].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_auogsm;
- $('.ModeBox1 ul')[7].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctsotem;
- $('.ModeBox1 ul')[7].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_thwos;
- $('.ModeBox1 ul')[7].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_sdla;
- $('.ModeBox1 ul')[7].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_line;
- $('.ModeBox1 ul')[7].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_bccs;
- $('.ModeBox1 ul')[7].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_stepCounter;
- $('.ModeBox1 ul')[7].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_stepCounter_1;
- $('.ModeBox1 ul')[7].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_bluetooth_send;
- $('.ModeBox1 ul')[7].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_bluetooth_receive;
- $('.ModeBox1')[0].children[3].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_ionc;
- $('.ModeBox1 ul')[8].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_btsldtc;
- $('.ModeBox1 ul')[8].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_ktsedti;
- $('.ModeBox1 ul')[8].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_btoldalua;
- $('.ModeBox1 ul')[8].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_tsedtc;
- $('.ModeBox1 ul')[8].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_toedaluatc;
- $('.ModeBox1 ul')[8].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_ewhadtnocd;
- $('.ModeBox1 ul')[8].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledss;
- $('.ModeBox1 ul')[8].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_ledac;
- $('.ModeBox1 ul')[8].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_ctwn;
- $('.ModeBox1 ul')[8].children[9].innerHTML = Ardublockly.LOCALISED_TEXT.select_bssbms;
- $('.ModeBox1 ul')[8].children[10].innerHTML = Ardublockly.LOCALISED_TEXT.select_bsrbmc;
- $('.ModeBox1 ul')[8].children[11].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbms;
- $('.ModeBox1 ul')[8].children[12].innerHTML = Ardublockly.LOCALISED_TEXT.select_wrcbmr;
- $('.ModeBox1 ul')[8].children[13].innerHTML = Ardublockly.LOCALISED_TEXT.select_snt;
- $('.ModeBox1 ul')[8].children[14].innerHTML = Ardublockly.LOCALISED_TEXT.select_dwsdat;
- $('.ModeBox1')[0].children[4].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.select_smmlc;
- $('.ModeBox1 ul')[9].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.basis_face_Intelligent;
- $('.ModeBox1 ul')[9].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.select_gcaerhk;
- $('.ModeBox1 ul')[9].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.select_frs;
- $('.ModeBox1 ul')[9].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.select_ors;
- $('.ModeBox1 ul')[9].children[4].innerHTML = Ardublockly.LOCALISED_TEXT.select_fr;
- $('.ModeBox1 ul')[9].children[5].innerHTML = Ardublockly.LOCALISED_TEXT.select_or;
- $('.ModeBox1 ul')[9].children[6].innerHTML = Ardublockly.LOCALISED_TEXT.select_srd;
- $('.ModeBox1 ul')[9].children[7].innerHTML = Ardublockly.LOCALISED_TEXT.select_srt;
- $('.ModeBox1 ul')[9].children[8].innerHTML = Ardublockly.LOCALISED_TEXT.select_mhdr;
- $('.ModeBox1')[0].children[5].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_ad;
- $('.ModeBox1 ul')[10].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_trsr;
- $('.ModeBox1 ul')[10].children[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpl2;
- $('.ModeBox1 ul')[10].children[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tpll;
- $('.ModeBox1 ul')[10].children[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_tph;
- // $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
- $("#sketch_name").val(Ardublockly.LOCALISED_TEXT.sketch_name);
- // $('#runCode')[0].innerHTML = Ardublockly.LOCALISED_TEXT.runCode;
- // $('#uploadFiles')[0].innerHTML = Ardublockly.LOCALISED_TEXT.uploadFiles;
- // $('#resetMainUI')[0].innerHTML = Ardublockly.LOCALISED_TEXT.resetMainUI;
- $('#select_dropdown')[0].value = Ardublockly.LOCALISED_TEXT.select_dropdown;
- // $('#iot_modules')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
- $(".qiehuanbtn")[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_csm;
- $("#localsssssaveOrOpen")[0].children[0].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_butvmi;
- $("#localsssssaveOrOpen")[0].children[1].children[0].innerHTML = Ardublockly.LOCALISED_TEXT.a_buartlp;
- // $('#ai_tt div')[0].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thw;
- // $('#ai_tt div')[1].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_thwos;
- // $('#ai_tt div')[2].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_uoc;
- // $('#ai_tt div')[3].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_mc;
- // $('#ai_tt div')[4].innerHTML = Ardublockly.LOCALISED_TEXT.ai_modules_sor;
- }
- function selectOnload() {
- $('.select-connected')[0].onchange = function () {
- var a = $('.select-connected')[0].selectedIndex;
- if (a == 0) {
- isWifiContent = false
- $('#Serial_Interaction').css("display", 'inline-block')
- $('#IP').css('display', 'none')
- } else {
- isWifiContent = true
- $('#Serial_Interaction').css("display", 'none')
- $('#IP').css('display', 'block')
- // 进行socket 连接
- }
- }
- $('.selectMode_input')[0].parentNode.onclick = function (e) {
- $('.MouduleBox')[0].style.cssText = 'display:block';
- }
- $('.ModeSelectBox')[0].onclick = function (e) {
- U.UF.EV.stopBubble();
- // $('.ModeSelect')[0].className = 'ModeSelect active';
- $("#select_Example_modal").modal("open")
- }
- $('#update_log')[0].onclick = function (e) {
- $("#loadModal").modal("open")
- }
- $('#model_download_modal')[0].onclick = function (e) {
- $("#select_Model_download_modal").modal("open")
- }
- var modelsItems = document.getElementsByClassName("modelDownloadItemTitle");
- var modelsItemDescs = document.getElementsByClassName("modelDownloadItemDesc");
- for (var i = 0, len = modelsItems.length; i < len; i++) {
- modelsItems[i].title = modelsItems[i].innerHTML;
- }
- for (var i = 0, len = modelsItemDescs.length; i < len; i++) {
- modelsItemDescs[i].title = modelsItemDescs[i].innerHTML;
- }
- // var items = document.getElementById("list").getElementsByTagName("li");
- //获取5个内容盒子;
- var divs = document.getElementById("item").getElementsByTagName("div");
- var examples = document.getElementById("item").getElementsByTagName("li");
- var divs_type = document.getElementById("item_1").getElementsByTagName("div");
- var examples_type = document.getElementById("item_1").getElementsByTagName("li");
- var exampleList = document.getElementById("example").getElementsByClassName("con");
- // if (items.length != divs.length) {
- // return;
- // }
- for (var i = 0, len = examples.length; i < len; i++) {
- examples[i].id = i;
- examples[i].onclick = function () {
- for (var j = 0, len = examples.length; j < len; j++) {
- examples[j].className = "container-middle-noactive arrow";
- divs_type[j].style.display = "none";
- }
- for (var k = 0, len = examples_type.length; k < len; k++) {
- examples_type[k].className = "container-middle-1-noactive arrow";
- exampleList[k].style.display = "none";
- }
- this.className = "container-middle-active arrow_active";
- divs_type[this.id].getElementsByTagName("li")[0].className = "container-middle-1-active arrow_active";
- divs_type[this.id].style.display = "block";
- if (this.id == 0) {
- for (var k = 0, len = exampleList.length; k < len; k++) {
- exampleList[k].style.display = "none";
- }
- exampleList[0].style.display = "block";
- }
- else if (this.id == 1) {
- for (var k = 0, len = exampleList.length; k < len; k++) {
- exampleList[k].style.display = "none";
- }
- exampleList[6].style.display = "block";
- }
- else if (this.id == 2) {
- for (var k = 0, len = exampleList.length; k < len; k++) {
- exampleList[k].style.display = "none";
- }
- exampleList[9].style.display = "block";
- }
- else if (this.id == 3) {
- for (var k = 0, len = exampleList.length; k < len; k++) {
- exampleList[k].style.display = "none";
- }
- exampleList[11].style.display = "block";
- }
- else if (this.id == 4) {
- for (var k = 0, len = exampleList.length; k < len; k++) {
- exampleList[k].style.display = "none";
- }
- exampleList[13].style.display = "block";
- }
- else if (this.id == 5) {
- for (var k = 0, len = exampleList.length; k < len; k++) {
- exampleList[k].style.display = "none";
- }
- exampleList[20].style.display = "block";
- }
- else if (this.id == 6) {
- for (var k = 0, len = exampleList.length; k < len; k++) {
- exampleList[k].style.display = "none";
- }
- exampleList[25].style.display = "block";
- }
- else {
- for (var k = 0, len = exampleList.length; k < len; k++) {
- exampleList[k].style.display = "none";
- }
- exampleList[31].style.display = "block";
- }
- }
- }
- for (var i = 0, len = examples_type.length; i < len; i++) {
- examples_type[i].id = i;
- examples_type[i].onclick = function () {
- for (var k = 0, len = examples_type.length; k < len; k++) {
- examples_type[k].className = "container-middle-1-noactive arrow";
- exampleList[k].style.display = "none";
- }
- this.className = "container-middle-1-active arrow_active";
- exampleList[this.id].style.display = "block";
- }
- }
- likeclose($('.selectMode_input')[0].parentNode, $('.MouduleBox')[0], '', '');
- likeclose($('.ModeSelect')[0].children[0], $('.ModeSelect')[0], 1, 'ModeSelect');
- likeclose($('#bar_ai img')[0], $('.MouduleBox')[1], '', '');
- likeclose($('#bar_t img')[0], $('#ai_tt')[0], '', '');
- var MChild = $('.MouduleBox')[0].children;
- var tchild = $('.MouduleBox')[1].children;
- for (var i = 0; i < MChild.length; i++) {
- tchild[i].onclick = MChild[i].onclick = function (e) {
- window.event ? window.event.cancelBubble = true : e.stopPropagation()
- var e = e.target;
- if (e.parentElement.children[2] && e.parentElement.children[2].children.length > 0) { } else {
- if (e.innerHTML == Ardublockly.LOCALISED_TEXT.iot_module) {
- $("#mode")[0].selectedIndex = 0;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
- // document.getElementById("list").getElementsByTagName("li")[0].onclick();
- }
- else if (e.innerHTML == Ardublockly.LOCALISED_TEXT.ai_module) {
- $("#mode")[0].selectedIndex = 1;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
- // document.getElementById("list").getElementsByTagName("li")[1].onclick();
- }
- $('.MouduleBox')[0].style.display = 'none';
- $('.MouduleBox')[1].style.display = 'none';
- $('#ai_tt')[0].style.display = 'none';
- }
- }
- }
- for (var i = 0; i < $('.ModeBox')[0].children.length; i++) {
- $('.ModeBox')[0].children[i].onclick = function (e) {
- window.event ? window.event.cancelBubble = true : e.stopPropagation()
- }
- }
- for (var i = 0; i < $('.ModeBox1')[0].children.length; i++) {
- $('.ModeBox1')[0].children[i].onclick = function (e) {
- window.event ? window.event.cancelBubble = true : e.stopPropagation()
- }
- }
- $("#repl_delete")[0].onclick = function () {
- $("#repl_box_content")[0].innerHTML = "";
- }
- }
- function clickLoadingExample(name) {
- console.log(name)
- $('#select_Example_modal').modal('close');
- Ardublockly.alertExampleMessage(
- '',
- Ardublockly.getLocalStr('loadBlockBody'),
- true, {});
- readTxt("src/python/" + name, function (txt) {
- if (name.split(".")[1] == "xml") {
- var xmlfile = Blockly.Xml.textToDom(txt);
- blockpy.components.editor.setBlocksFromXml(xmlfile);
- } else {
- blockpy.components.editor.codeMirror.setValue(txt);
- }
- saveLocalStorageBlocks("pythonai-mode-blocks-xml");
- setTimeout(() => {
- $('#loading').css({ 'display': 'none' });
- $('#example_alert').modal('close');
- }, 300)
- });
- }
- function readTxt(url, fun) {
- var xhr = new XMLHttpRequest();
- xhr.open('get', url, true);
- xhr.send();
- xhr.onreadystatechange = function () {
- if (xhr.readyState == 4 && xhr.status == 200) {
- fun(xhr.responseText)
- }
- };
- }
- function serialSwich(type) {
- if (type == 'Serial_Interaction') {
- $('#python_box').addClass('hidden')
- $('#repl_box').removeClass('hidden')
- $('#serial_plotter_content').addClass('hidden')
- $('#repl_delete').addClass('hidden')
- document.getElementById('repl_delete').style.display = 'none';
- $('#python_SourceCode').removeClass('switch_select')
- $('#python_SourceCode').addClass('switch_box1')
- $('#Serial_Interaction').removeClass('switch_box1')
- $('#Serial_Interaction').addClass('switch_select')
- $('#serial_plotter').removeClass('switch_select')
- $('#serial_plotter').addClass('switch_box1')
- } else if (type == 'python_SourceCode') {
- $('#repl_box').addClass('hidden')
- $('#python_box').removeClass('hidden')
- $('#serial_plotter_content').addClass('hidden')
- $('#repl_delete').addClass('hidden')
- document.getElementById('repl_delete').style.display = 'none';
- $('#Serial_Interaction').removeClass('switch_select')
- $('#Serial_Interaction').addClass('switch_box1')
- $('#python_SourceCode').removeClass('switch_box1')
- $('#python_SourceCode').addClass('switch_select')
- $('#serial_plotter').removeClass('switch_select')
- $('#serial_plotter').addClass('switch_box1')
- saveLocalStorageBlocks('pythonai-mode-blocks-xml')
- setTimeout(function () {
- blockpy.components.editor.updateTextFromModel();
- blockpy.components.editor.updateText()
- blockpy.components.editor.unhighlightLines()
- var text = localStorage.getItem('pythonai-mode-blocks-xml')
- var xmlfile = Blockly.Xml.textToDom(text);
- blockpy.components.editor.setBlocksFromXml(xmlfile);
- }, 100)
- } else if (type == 'serial_plotter') {
- $('#repl_box').addClass('hidden')
- $('#python_box').addClass('hidden')
- $('#serial_plotter_content').removeClass('hidden')
- document.getElementById('repl_delete').style.display = 'inline-block';
- $('#Serial_Interaction').removeClass('switch_select')
- $('#Serial_Interaction').addClass('switch_box1')
- $('#python_SourceCode').removeClass('switch_select')
- $('#python_SourceCode').addClass('switch_box1')
- $('#serial_plotter').removeClass('switch_box1')
- $('#serial_plotter').addClass('switch_select')
- }
- }
- function qiehuanjjj(ele, _container) {
- $("body")[0].addEventListener('click', function (e) {
- if (ele != e.target) {
- _container.className = 'dropdown-content';
- }
- })
- }
- function likeclose(ele, _container, type, _className) {
- $("body")[0].addEventListener('click', function (e) {
- if (ele != e.target && e.target.parentNode != ele) {
- if (type == 1) {
- _container.className = _className;
- } else {
- _container.style.display = 'none'
- }
- }
- })
- }
- function export_data(data, postfix, is_firefox) {
- let url = new Blob([data], { type: 'text/plain' });
- let download_link = URL.createObjectURL(url);
- let a = document.createElement('a');
- a.style = "display:none";
- a.href = download_link;
- a.download = "user_latest_code" + postfix;
- if (is_firefox) {
- document.body.appendChild(a);
- a.click();
- setTimeout(() => document.body.removeChild(a), 100);
- } else
- a.click();
- // URL.revokeObjectURL(download_link);
- // IE edge need a short delay before revoke virtual download link
- setTimeout(() => URL.revokeObjectURL(download_link), 100);
- }
- // 积木生成
- function selectmode(sel, isload) {
- // var _type = 1;
- // if (sel.selectedIndex == 0 && (_type != 0 || isload === true)) {
- saveLocalStorageBlocks("pythonmc-mode-blocks-xml");
- saveLocalStorage("type", 1);
- // $("#changeRunCuploadFilesode").css("display", "inline-block");
- // $("#resetMainUIBtn").css("display", "inline-block");
- blockpy.setAssignment(
- // settings
- {},
- // assignment
- {
- modules: {
- added: ["Decisions", "Iteration", "Calculation", "Variables", "Values", "Lists", "Functions", "Logic", "Loops", "Math", "Text", "Dictionary", "Tuples", "Set", "Functionsa", "Files", "Time", "Serial Comm.", "A.I.Board", "ExtendedFunctions", "AI", "IOT", "system", "ExtendedFunction", "Third_party_Sensor"],
- removed: ['MainBoard']
- }
- },
- // programs
- {
- __main__: ""
- }
- );
- loadLocalStorageBlocks("pythonai-mode-blocks-xml")
- // }
- }
- function getQueryParams() {
- try {
- url = window.location.href;
- query_str = url.substr(url.indexOf("?") + 1, url.length - 1);
- r_params = query_str.split("&");
- params = {};
- for (i in r_params) {
- param = r_params[i].split("=");
- params[param[0]] = param[1];
- }
- return params;
- } catch (e) {
- return {};
- }
- }
- // onresize 多次执行解决办法
- var debounce = function (func, threshold, execAsap) {
- var timeout;
- return function debounced() {
- var obj = this, args = arguments;
- function delayed() {
- if (!execAsap)
- func.apply(obj, args);
- timeout = null;
- };
- if (timeout)
- clearTimeout(timeout);
- else if (execAsap)
- func.apply(obj, args);
- timeout = setTimeout(delayed, threshold || 100);
- };
- }
- // window.onresize = debounce(function () {
- // if (document.body.clientWidth < 1265) {
- // alert(CCB.str_group.alert)
- // }
- // }, 100, true);
- // 切换数据显示方式
- var myChart = "";
- function switchSerial(type) {
- if (type == 2) {
- document.getElementById('image_transmission').style.display = 'none';
- document.getElementById('repl_box_content').style.display = 'block';
- // document.getElementById('repl_box_content').innerHTML = ""
- document.getElementsByClassName('translatable_image_transmission')[0].classList.remove("serial-active")
- document.getElementsByClassName('translatable_serial_plotter')[1].classList.add("serial-active")
- } else {
- document.getElementById('image_transmission').style.display = 'block';
- document.getElementById('repl_box_content').style.display = 'none';
- document.getElementsByClassName('translatable_image_transmission')[0].classList.add("serial-active")
- document.getElementsByClassName('translatable_serial_plotter')[1].classList.remove("serial-active")
- // document.getElementById('repl_box_content').innerHTML = ""
- }
- }
- // 点击下载文件
- function fileDownload(url, name) {
- var nowA = document.createElement('a');
- nowA.setAttribute('href', url);
- nowA.setAttribute('download', name);
- nowA.style.display = 'none';
- document.body.appendChild(nowA);
- nowA.click();
- document.body.removeChild(nowA);
- }
- // 点击复制分享链接
- function copyShare() {
- $('#cloudBtn-shares').click(() => {
- if (CCB.userState) {
- let time = 10000
- var $toastContent = $(`<span id="abc">${CCB.str_group.share_loading}</span>`)
- Materialize.toast($toastContent, time, "shareUrl")
- let fileNmae = new Date().getTime()
- $.ajax(`${CCB.base_url}blockx/`, {
- type: "POST",
- xhrFields: {
- withCredentials: true
- },
- data: {
- filename: fileNmae,
- xml: Ardublockly.generateXml()
- },
- success: (res) => {
- let fileobject = {
- filenameId: res.filename,
- filename: fileNmae,
- time: getCurrentDate(),
- timestamp: (new Date()).valueOf()
- };
- CCB.cloudFileList.push(fileobject);
- CCB.selectCloudFile = filename;
- var id = U.UF.C.queryString("Qd");
- var url = window.location.href + '&Qd=' + res.filename;
- if (id) {
- url = window.location.href.replace(/Qd=[0-9a-zA-Z_]+/g, "Qd=" + res.filename);
- }
- let flag = copyText(url);
- // time = 3000;
- // document.getElementById('abc').innerHTML = flag ? CCB.str_group.share_success : CCB.str_group.share_fail
- // setTimeout(function () {
- Materialize.toast(flag ? CCB.str_group.share_success : CCB.str_group.share_fail, 3000, "shareUrl")
- //}, time)
- },
- error: () => {
- $("#cloud_modal_preload").css("display", "none");
- // time = 4000;
- // Materialize.toast(CCB.str_group.error_uploadFile, 4000);
- // document.getElementById('abc').style.display = CCB.str_group.error_uploadFile
- setTimeout(function () {
- Materialize.toast(CCB.str_group.error_uploadFile, 4000)
- }, time)
- }
- });
- } else {
- Materialize.toast(CCB.str_group.requestLogin, 3000);
- $("#login_modal").modal("open")
- }
- })
- }
- function enterNext(value) {
- $("#select_folder").html('')
- var path = getLocalStorage("path") + value;
- // 获取 sd 卡的路径
- saveLocalStorage("path", path + '/');
- saveLocalStorage("fileAndFolder", '');
- pythoncmdselect(getLocalStorage("path"), function (data) {
- if (data.responseText != null) {
- var arr = data.responseText.split("\n");
- saveLocalStorage("fileAndFolder", arr);
- var str = '<div style="display:flex;flex-wrap: wrap;align-content: space-around;justify-content:space-around;">';
- for (var i = 0; i < arr.length - 1; i++) {
- if (arr[i].indexOf(".") != -1) {
- var aa = arr[i].replace("\r", "").replace("\r", "");
- str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
- str += '<img src="blockly/media/fileManage/file.png" style="position: relative;"/>';
- str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 65px;margin-top: -5px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
- str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
- }
- else {
- var aa = arr[i].replace("\r", "").replace("\r", "");
- str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
- str += '<img src="blockly/media/fileManage/package.png" style="position: relative;" onclick="enterNext(\'' + aa + '\')">';
- str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 80px;margin-top: -10px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
- str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
- }
- }
- if ((arr.length - 1) % 4 == 1) {
- str += '<div class = "box-item"></div><div class = "box-item"></div><div class = "box-item"></div>';
- }
- else if ((arr.length - 1) % 4 == 2) {
- str += '<div class = "box-item"></div><div class = "box-item"></div>';
- }
- else if ((arr.length - 1) % 4 == 3) {
- str += '<div class = "box-item"></div>';
- }
- str += '</div>';
- $("#select_folder").html(str)
- }
- })
- $("#return_folder").css("display", "inline-block");
- }
- function deleteFile(value) {
- $("#select_folder").html('')
- $('#cancle_delete').css('display', 'none');
- $("#delete_folder").css('display', 'inline-block');
- var path = getLocalStorage("path") + value;
- saveLocalStorage("fileAndFolder", '');
- // 获取 sd 卡的路径
- pythoncmddel(path, function (data) {
- if (data.responseText != null) {
- var arr = data.responseText.split("\n");
- saveLocalStorage("fileAndFolder", arr);
- var str = '<div style="display:flex;flex-wrap: wrap;align-content: space-around;justify-content:space-around;">';
- for (var i = 0; i < arr.length - 1; i++) {
- if (arr[i].indexOf(".") != -1) {
- var aa = arr[i].replace("\r", "").replace("\r", "");
- str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
- str += '<img src="blockly/media/fileManage/file.png" style="position: relative;"/>';
- str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 65px;margin-top: -5px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
- str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
- }
- else {
- var aa = arr[i].replace("\r", "").replace("\r", "");
- str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
- str += '<img src="blockly/media/fileManage/package.png" style="position: relative;" onclick="enterNext(\'' + aa + '\')">';
- str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 80px;margin-top: -10px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
- str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
- }
- }
- if ((arr.length - 1) % 4 == 1) {
- str += '<div class = "box-item"></div><div class = "box-item"></div><div class = "box-item"></div>';
- }
- else if ((arr.length - 1) % 4 == 2) {
- str += '<div class = "box-item"></div><div class = "box-item"></div>';
- }
- else if ((arr.length - 1) % 4 == 3) {
- str += '<div class = "box-item"></div>';
- }
- str += '</div>';
- $("#select_folder").html(str)
- }
- })
- }
- String.prototype.isEmpty = function () {
- var s1 = this.replace(/[\r\n]/g, '').replace(/[ ]/g, ''),
- s2 = (s1 == '') ? true : false;
- return s2;
- };
- function isInArray(str, value) {
- var arr = str.split(",");
- for (var i = 0; i < arr.length; i++) {
- if (value === arr[i].replace("\r", "").replace("\r", "")) {
- return true;
- }
- }
- return false;
- }
- function deleteFileOrFolder() {
- if (!$("#select_folder").html().isEmpty()) {
- $('.deleteImg').css('display', 'block');
- $('#cancle_delete').css('display', 'inline-block');
- $("#delete_folder").css('display', 'none');
- }
- }
- function cancelDeleteFileOrFolder() {
- if (!$("#select_folder").html().isEmpty()) {
- $('.deleteImg').css('display', 'none');
- $('#cancle_delete').css('display', 'none');
- $("#delete_folder").css('display', 'inline-block');
- }
- }
- function return_pre_folder() {
- $("#select_folder").html('');
- var path = getLocalStorage("path").split("/").slice(0, -2).join("/") + '/';
- // 获取 sd 卡的路径
- saveLocalStorage("path", path);
- pythoncmdselect(path, function (data) {
- if (data.responseText != null) {
- var arr = data.responseText.split("\n");
- saveLocalStorage("fileAndFolder", arr);
- var str = '<div style="display:flex;flex-wrap: wrap;align-content: space-around;justify-content:space-around;">';
- for (var i = 0; i < arr.length - 1; i++) {
- if (arr[i].indexOf(".") != -1) {
- var aa = arr[i].replace("\r", "").replace("\r", "");
- str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
- str += '<img src="blockly/media/fileManage/file.png" style="position: relative;"/>';
- str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 65px;margin-top: -5px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
- str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
- }
- else {
- var aa = arr[i].replace("\r", "").replace("\r", "");
- str += '<div class = "box-item"><div class="all-box"><div class="img-box">';
- str += '<img src="blockly/media/fileManage/package.png" style="position: relative;" onclick="enterNext(\'' + aa + '\')">';
- str += '<img class="deleteImg" src="blockly/media/fileManage/delete.png" style="position: absolute;margin-left: 80px;margin-top: -10px;display:none;" onclick="deleteFile(\'' + aa + '\')"/>';
- str += '</div><div class="text-box"><div class="fileText">' + arr[i] + '</div></div></div></div>';
- }
- }
- if ((arr.length - 1) % 4 == 1) {
- str += '<div class = "box-item"></div><div class = "box-item"></div><div class = "box-item"></div>';
- }
- else if ((arr.length - 1) % 4 == 2) {
- str += '<div class = "box-item"></div><div class = "box-item"></div>';
- }
- else if ((arr.length - 1) % 4 == 3) {
- str += '<div class = "box-item"></div>';
- }
- str += '</div>';
- $("#select_folder").html(str)
- }
- })
- if (path == "/") {
- $("#return_folder").css("display", "none");
- }
- else {
- $("#return_folder").css("display", "inline-block");
- }
- }
- function uploadSuccess(data) {
- console.log(data);
- }
- function toHref_own(href) {
- window.open(href + "&lang=" + localStorage.getItem("handPyLanguage"), "_blank");
- }
- function toHref(href) {
- window.open(href + "/?lang=" + localStorage.getItem("handPyLanguage"), "_blank");
- }
- function select_Module(module) {
- if (module == 'AI_module') {
- $('#AI_module').addClass("moduleActive");
- $('#IoT_module').removeClass("moduleActive");
- }
- else {
- $('#IoT_module').addClass("moduleActive");
- $('#AI_module').removeClass("moduleActive");
- }
- }
- function selectModule_confirm() {
- if ($("#AI_module").attr('class') == "moduleActive") {
- $("#mode")[0].selectedIndex = 1;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.ai_module;
- // document.getElementById("list").getElementsByTagName("li")[1].onclick();
- $("#selectModule").modal('close');
- $('#IoT_module').removeClass("moduleActive");
- $('#AI_module').removeClass("moduleActive");
- }
- else if ($("#IoT_module").attr('class') == "moduleActive") {
- $("#mode")[0].selectedIndex = 0;
- $("#mode")[0].onchange();
- $('.selectMode_input')[0].value = Ardublockly.LOCALISED_TEXT.iot_module;
- // document.getElementById("list").getElementsByTagName("li")[0].onclick();
- $("#selectModule").modal('close');
- $('#IoT_module').removeClass("moduleActive");
- $('#AI_module').removeClass("moduleActive");
- }
- }
- function mouseMove() {
- // 拖拉改变右侧上下块的高度
- let PC = document.getElementById('mouseMove')
- let divA = document.getElementById('py-editor')
- let divB = document.getElementById('mouseMove-bottom')
- let midd = document.getElementById('left_move_right')
- let left_midd = document.getElementById('blocks_content')
- let right = document.getElementById('sss')
- // $('#mouseMove').click()
- // window.addEventListener('mousemove', function () {
- PC.onmousedown = function (ev) {
- $('#wabadb_iframe_model').removeClass('hidden')
- // 鼠标按下坐标
- let pX1 = ev.clientX
- let pY1 = ev.clientY
- // 得到两个 div 的高度
- let heightA = divA.clientHeight
- let heightB = divB.clientHeight
- // divB.style.height = '300px'
- document.onmousemove = function (ev) {
- // document.onmousedown = new Function("return false");
- // document.onmouseup = new Function("return true");
- // 鼠标移动是坐标
- let pX2 = ev.clientX
- let pY2 = ev.clientY
- // 计算出鼠标上下移动的距离
- let Y = pY2 - pY1
- if (heightB - Y > 5 && heightA + Y > 60) {
- divB.style.height = heightB - Y + 'px'
- divA.style.height = heightA + Y + 'px'
- }
- }
- //清除
- document.onmouseup = function (ev) {
- $('#wabadb_iframe_model').addClass('hidden')
- document.onmousemove = null;
- document.onmouseup = null;
- }
- }
- midd.onmousedown = function (ev) {
- $('#wabadb_iframe_model').removeClass('hidden')
- let pX1 = ev.clientX
- let pY1 = ev.clientY
- // 得到两个 div 的宽度
- let widthA = left_midd.clientWidth
- let widthB = right.clientWidth
- // divB.style.height = '300px'
- document.onmousemove = function (ev) {
- // 鼠标移动是坐标
- let pX2 = ev.clientX
- let pY2 = ev.clientY
- // 计算出鼠标左右移动的距离
- let Y = pX2 - pX1
- if (Number(widthB - Y) > 425 && widthA + Y > 135) {
- left_midd.style.width = widthA + Y + 'px'
- right.style.width = widthB - Y + 'px'
- // Ardublockly.toogleToolbox()
- setTimeout(function () {
- Blockly.svgResize(blockpy.components.editor.blockly);
- Blockly.svgResize(Blockly.mainWorkspace);
- }, 100)
- }
- }
- //清除
- document.onmouseup = function (ev) {
- $('#wabadb_iframe_model').addClass('hidden')
- document.onmousemove = null;
- document.onmouseup = null;
- }
- }
- // })
- }
- let isWebadb = ''
- let isDevice = ''
- let isConnect = ''
- function addWebadb() {
- if (isWifiContent) {
- // $("#webadb_connect")[0].disabled = false;
- if ($('#IP').val().length > 0) {
- $('#wifi_process').modal('open');
- console.log(`${$('#IP').val()}:5678`)
- if (window.location.href.split("://")[0] === "https") {
- $("#getIpLink").html(`https://${$('#IP').val()}:5678`)
- } else {
- $("#getIpLink").html(`http://${$('#IP').val()}:5678`)
- }
- } else {
- alert(CCB.str_group.ipAddress)
- }
- // console.log(window.location.origin.indexOf("https"))
- } else {
- document.getElementById("webadb_iframe").contentWindow.document.getElementById("usbadd").click();
- }
- // $("#webadb_connect")[0].disabled = false;
- // isDevice = document.getElementById("webadb_iframe").contentWindow.getdevice().device;
- }
- // webadb 连接
- function webadbConnect() {
- if (isWifiContent) {
- if ($('#webadb_connect')[0].innerHTML == Ardublockly.LOCALISED_TEXT.connectBtn) {
- connectWebsocket()
- } else {
- ws.close()
- }
- } else {
- if (!!isConnect) {
- document.getElementById("webadb_iframe").contentWindow.document.getElementById("usbdisconnect").click()
- $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn
- } else {
- // serialSwich('Serial_Interaction')
- document.getElementById("webadb_iframe").contentWindow.document.getElementById("usbconnect").click()
- $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.disConnect
- }
- }
- }
- function ac() {
- }
- function systemCommand(com) {
- if (isWifiContent) {
- sendWebsocket(`import os
- os.system("${com}")`, 'run')
- setTimeout(() => {
- ws.close()
- }, 200)
- } else {
- document.getElementById('webadb_iframe').contentWindow.getdevice().device.subprocess.shell(com).then(function (e) {
- e.stdout.reader.read().then(function (e) {
- // 重启或关机
- })
- }).catch(err => {
- })
- }
- }
- function backHome() {
- if (isWifiContent) {
- // ws.send(`import os
- // os.system("rm /tmp/disable")`,"run")
- } else {
- if (isRunCodeData) {
- isRunCodeData.kill().then(() => {
- document.getElementById('webadb_iframe').contentWindow.getdevice().device.subprocess.shell(`rm /tmp/disable`).then(function (e) {
- isRunCodeData = e;
- })
- })
- } else {
- document.getElementById('webadb_iframe').contentWindow.getdevice().device.subprocess.shell(`rm /tmp/disable`).then(function (e) {
- isRunCodeData = e;
- })
- }
- }
- $("#backHome").addClass('disabled')
- }
- // 点击切换更新记录
- function switchUpdate(type) {
- if (type == '1') {
- $('.update-old').css({ display: 'none' })
- $('.update-new').css({ display: 'block' })
- } else {
- $('.update-old').css({ display: 'block' })
- $('.update-new').css({ display: 'none' })
- }
- }
- function Uint8ArrayToString(fileData) {
- const Utf8Decoder = new TextDecoder();
- return Utf8Decoder.decode(fileData);
- // var dataString = "";
- // for (var i = 0; i < fileData.length; i++) {
- // dataString += String.fromCharCode(fileData[i]);
- // }
- // return dataString
- }
- function run_user_lastet_code() {
- canvasImg = $("#image_transmission_canvas")[0].getContext("2d")
- canImage = new Image()
- document.getElementById('webadb_iframe').contentWindow.getdevice().device.subprocess.shell(`ln -sf /root/user_latest_code.py /tmp/event && touch /tmp/disable && python -u /tmp/event`).then(function (e) {
- isRunCodeData = e;
- _data = "";
- _ti = "";
- serverPrint(e)
- RunInterval = setInterval(() => {
- serverPrint(e)
- }, 10);
- })
- }
- var _data = "";
- var _ti;
- var canvasImg = "";
- var canImage = "";
- function serverPrint(e) {
- if (e.stdout.readable._state != 'readable') {
- $('#backHome').addClass('disabled')
- clearInterval(RunInterval)
- backHome()
- }
- else {
- $('#backHome').removeClass('disabled')
- }
- e.stdout.reader.read().then(function (e) {
- if (e.value) {
- clearTimeout(_ti);
- _data += Uint8ArrayToString(e.value);
- //showServal(_data)
- _ti = setTimeout(function () {
- showServal(_data)
- _data = "";
- }, 50)
- }
- }).catch(err => {
- $('.progress > .determinate').css('width', 0);
- })
- }
- var newStr = ''
- var isScreenshot = false
- function showServal(_data) {
- if (!isScreenshot) {
- try {
- newStr = _data;
- canImage.src = _data;
- canImage.onload = () => {
- canvasImg.drawImage(canImage, 0, 0, 300, 150)
- $("#training_screenshot").css({
- "display": "block"
- })
- $("#training_upload").css({
- "display": "none"
- })
- $("#training_cancel").css({
- "display": "none"
- })
- }
- }
- catch (e) {
- }
- }
- else {
- try {
- canImage.src = newStr;
- canImage.onload = () => {
- canvasImg.drawImage(canImage, 0, 0, 300, 150)
- $("#training_screenshot").css({
- "display": "none"
- })
- $("#training_upload").css({
- "display": "block"
- })
- $("#training_cancel").css({
- "display": "block"
- })
- }
- }
- catch (e) {
- }
- }
- // }
- if (_data.indexOf(`File "/tmp/event", line`) > -1) {
- setTimeout(() => {
- $("#error-btn").css("display", "block")
- $('.card-reveal').css({ 'display': 'block', 'transform': 'translateY(-100%)', 'padding': '8px 13px' });
- }, 500)
- let errMsg = _data.slice(_data.indexOf(`File "/tmp/event", line`)).split('\r\n')
- $("#err-msg").text(`${errMsg[0]}\n${errMsg[1]}\n${errMsg[2]}\n${CCB.str_group.errSol}\n${Ardublockly.LOCALISED_TEXT.error_pv}`)
- } else if (_data.indexOf("IndentationError") > -1 || _data.indexOf("SyntaxError") > -1) {
- setTimeout(() => {
- $("#error-btn").css("display", "block")
- $('.card-reveal').css({ 'display': 'block', 'transform': 'translateY(-100%)', 'padding': '8px 13px' });
- }, 500)
- $("#err-msg").text(`_data\n${CCB.str_group.errSol}\n${Ardublockly.LOCALISED_TEXT.error_unindent}`)
- } else if (_data.indexOf("fopen") > -1) {
- setTimeout(() => {
- $("#error-btn").css("display", "block")
- $('.card-reveal').css({ 'display': 'block', 'transform': 'translateY(-100%)', 'padding': '8px 13px' });
- }, 500)
- $("#err-msg").text(`${_data.slice(_data.indexOf("fopen"), _data.indexOf("failed"))}\n${Ardublockly.LOCALISED_TEXT.ENOEN}`)
- } else {
- let c = ''
- let m = _data.indexOf("DEBUG") > -1 || _data.indexOf("debug") > -1 || _data.indexOf("modName") > -1 || _data.indexOf("tag") > -1 || _data.indexOf("branch") > -1 || _data.indexOf("commit") > -1 || _data.indexOf("author") > -1 || _data.indexOf("WARNING") > -1
- if (!m) {
- let b = _data.split('\r\n')
- for (let i = 0; i <= b.length - 1; i++) {
- c += `<div>${b[i]}</div>`
- }
- }
- $('#repl_box_content').append(c);
- }
- }
- function getQrCode() {
- document.getElementById("codeImg").innerHTML = ""
- let browserWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- let qrCode = ""
- if (browserWidth < 500) {
- qrCode = new QRCode(document.getElementById("codeImg"), {
- width: 150,
- height: 150
- })
- } else {
- qrCode = new QRCode(document.getElementById("codeImg"), {
- width: 200,
- height: 200
- })
- }
- let SSID = $('#SSID').val()
- let PASS = $('#PAS').val()
- if (SSID == "" && PASS == "") {
- alert(Ardublockly.LOCALISED_TEXT.SSIDPWD)
- return
- }
- console.log(`SSID:${SSID};PASS:${PASS}`)
- qrCode.makeCode(`SSID:${SSID};PASS:${PASS}`)
- }
- var isWifiContent = false
- var ws = ''
- var WifiContent = 'close';
- let ifconfig = "wifi_get_connection_info_test 1 > /root/event.log &";
- // let ifconfig = `import os
- // cmd = "wifi_get_connection_info_test 1"
- // res = os.popen(cmd).read()
- // print("res",res)
- // `
- function connectWebsocket(type) {
- ws = new WebSocket(`wss://${$('#IP').val()}:5678`);
- WifiContent = type
- ws.onopen = () => {
- // console.log('连接服务端WebSocket成功');
- $('#repl_box_content').append(`<div>${CCB.str_group.connection_success}</div>`);
- serialSwich('serial_plotter')
- $("#runCode").removeClass('disabled')
- $("#uploadpy").removeClass('disabled')
- $("#resetDevice").removeClass('disabled')
- $("#poweroff").removeClass('disabled')
- $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.disConnect
- $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusbar
- $('#cnt_icon').css('display', 'inline-block')
- $('#discnt_icon').css('display', 'none')
- $('#select-connected').attr("disabled", true)
- setTimeout(() => {
- //sendWebsocket(ifconfig,"run")
- ws.send(ifconfig)
- }, 1000)
- };
- // 监听服务端消息(接收消息)
- ws.onmessage = (msg) => {
- $('#repl_box_content').append(`<div>${msg.data}</div>`);
- };
- // 监听连接失败
- ws.onerror = () => {
- // console.log('连接失败,正在重连...');
- $('.progress > .determinate').css('width', '0');
- $('#repl_box_content').append(`<div>${CCB.str_group.connection}</div>`);
- // connectWebsocket();
- };
- // 监听连接关闭
- ws.onclose = () => {
- $('#repl_box_content').append(`<div>${CCB.str_group.disconnect}</div>`);
- // console.log('连接关闭');
- $('#cnt_icon').css('display', 'none')
- $('#discnt_icon').css('display', 'inline-block')
- $('#select-connected').attr("disabled", false)
- setTimeout(() => {
- $("#webadb_connect")[0].disabled = false;
- $("#webadb_add")[0].disabled = false;
- $("#status_txt")[0].innerHTML = Ardublockly.LOCALISED_TEXT.statusNotConn
- $("#runCode").addClass('disabled')
- $("#uploadpy").addClass('disabled')
- $("#resetDevice").addClass('disabled')
- $("#backHome").addClass('disabled')
- $("#poweroff").addClass('disabled')
- $('#message_file').css({ display: 'none' })
- $('#webadb_connect')[0].innerHTML = Ardublockly.LOCALISED_TEXT.connectBtn;
- $('.progress > .determinate').css('width', 0);
- }, 500)
- };
- };
- function sendWebsocket(file, type) {
- canvasImg = $("#image_transmission_canvas")[0].getContext("2d")
- canImage = new Image()
- // console.log(file)
- // ws.send('ls')
- // ws.send(`echo '${file}' > user_latest_code.py && ln -sf /root/user_latest_code.py /tmp/event && touch /tmp/disable && python /tmp/event`)
- if (type == "run") {
- ws.send(`echo '${file}' > /root/user_latest_code.py && ln -sf /root/user_latest_code.py /tmp/event && touch /tmp/disable && python -u /tmp/event > /root/event.log`)
- } else {
- ws.send(`echo '${file}' > /root/user_latest_code.py`)
- }
- ws.onmessage = (msg) => {
- if (msg.data.indexOf('data:image/jpg;base64') > -1) {
- try {
- canImage.src = msg.data;
- canImage.onload = () => {
- canvasImg.drawImage(canImage, 0, 0, 300, 150)
- }
- }
- catch (e) {
- }
- } else {
- // modName ,tag,branch,commit,author
- let a = msg.data.indexOf("DEBUG") > -1 || msg.data.indexOf("debug") > -1 || msg.data.indexOf("modName") > -1 || msg.data.indexOf("tag") > -1 || msg.data.indexOf("branch") > -1 || msg.data.indexOf("commit") > -1 || msg.data.indexOf("author") > -1
- if (!a) {
- $('#repl_box_content').append(`<div>${msg.data}</div>`);
- }
- // $('.progress > .determinate').css('width', '100%');
- }
- // $("#backHome").removeClass('disabled')
- $('.progress > .determinate').css('width', '100%');
- };
- // setTimeout(function () {
- $('.progress > .determinate').css('width', '100%');
- $("#runCode").removeClass('disabled')
- $("#uploadpy").removeClass('disabled')
- $("#resetDevice").removeClass('disabled')
- $("#poweroff").removeClass('disabled')
- // }, 2000);
- }
- function mobileSwitchMode(type) {
- if (type == 'python') {
- $('.mobileSwitch')[0].style.display = "block"
- $('.mobileSwitch')[1].style.display = "none"
- $('#blocks_content')[0].style.display = "block"
- $('#py-editor')[0].style.display = "none"
- $('#sss')[0].style.height = 'fit-content'
- } else {
- $('.mobileSwitch')[1].style.display = "block"
- $('.mobileSwitch')[0].style.display = "none"
- $('#blocks_content')[0].style.display = "none"
- $('#py-editor')[0].style.display = "block"
- $('#sss')[0].style.height = '100%'
- }
- setTimeout(function () {
- blockpy.components.editor.updateTextFromModel();
- blockpy.components.editor.updateText()
- blockpy.components.editor.unhighlightLines()
- var text = localStorage.getItem('pythonai-mode-blocks-xml')
- var xmlfile = Blockly.Xml.textToDom(text);
- blockpy.components.editor.setBlocksFromXml(xmlfile);
- }, 100)
- }
- function linkOkay() {
- $("#webadb_connect")[0].disabled = false;
- console.log(`https://${$('#IP').val()}:5678`)
- if (window.location.href.split("://")[0] === "https") {
- window.open(`https://${$('#IP').val()}:5678`, '_blank');
- } else {
- window.open(`http://${$('#IP').val()}:5678`, '_blank');
- }
- $('#wifi_process').modal('close');
- }
- // 跨网页复制
- document.addEventListener("paste", function (event) {
- if ((event.clipboardData || event.originalEvent)) {
- var clipboardData = (event.clipboardData || window.clipboardData);
- var val = clipboardData.getData('text');
- // console.log(Blockly.Xml.workspaceToDom(blockpy.components.editor.blockly))
- // let a = val.substr(0,7)+val.substr(44,val.length)
- let c = Blockly.Xml.textToDom(val)
- Blockly.clipboardSource_ = blockpy.components.editor.blockly
- Blockly.clipboardSource_.paste(c)
- // event.preventDefault();
- }
- });
- function loadingXml(result_xml) {
- var success = Ardublockly.replaceBlocksfromXml(result_xml);
- if (!success) {
- Ardublockly.alertMessage(Ardublockly.getLocalStr('ErrorBlockTitle'), Ardublockly.getLocalStr('ErrorBlockBody'), false);
- }
- }
- function getLoadXmlStr() {
- var xml = Blockly.Xml.workspaceToDom(blockpy.components.editor.blockly);
- var XmlStr = Blockly.Xml.domToText(xml);
- return XmlStr
- }
- var trainImg = ""
- function getTrainImg() {
- isScreenshot = true
- screenIndex = screenIndex + 1
- }
- function convertBase64UrlToBlob(urlData) {
- var bytes = window.atob(urlData.split(',')[1]); //如果包含data:image/png;base64,串,需要去掉url的头,并转换为byte
- // var bytes = window.atob(urlData); //去掉url的头,并转换为byte
- //处理异常,将ascii码小于0的转换为大于0
- var ab = new ArrayBuffer(bytes.length);
- var ia = new Uint8Array(ab);
- for (var i = 0; i < bytes.length; i++) {
- ia[i] = bytes.charCodeAt(i);
- }
- var blob = new Blob([ab], { type: 'image/jpg' })
- var newFile = new File([blob], "image" + screenIndex + ".jpg", { type: 'image/jpg', lastModified: Date.now() });
- return newFile;
- }
- function uploadImg() {
- var formData = new FormData();
- // console.log(newStr)
- formData.append("file", convertBase64UrlToBlob(newStr));
- formData.append("name", datasetName);
- $.ajax(`//traininguser-api.cocorobo.cn/v831_upload_image`, {
- type: "POST",
- data: formData,
- dataType: "json",
- processData: false, // 重要!!告诉jQuery不要去处理发送的数据
- contentType: false, // 重要!!告诉jQuery不要去设置Content-Type请求头
- cache: false, //关闭缓存
- success: (res) => {
- console.log(res)
- }
- });
- isScreenshot = false
- }
- function cancelImg() {
- isScreenshot = false
- }
|