kopia lustrzana https://github.com/backface/turtlestitch
1 wiersz
5.1 KiB
XML
1 wiersz
5.1 KiB
XML
<blocks app="Snap! 6, https://snap.berkeley.edu" version="1"><block-definition s="listify %'jsonString'" type="reporter" category="operators"><header></header><code></code><translations>pt:os dados JSON _ em formato de lista
</translations><inputs><input type="%mlt"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>jsonString</l></list><l>return listify(JSON.parse(jsonString));

function listify(jsonObject) {
 if (jsonObject instanceof Array) {
 return new List(jsonObject.map(function(eachElement) { return listify(eachElement)}));
 } else if (jsonObject instanceof Object) {
 return new List(Object.keys(jsonObject).map(function(eachKey) { return new List([eachKey,listify(jsonObject[eachKey])])} ))
 } else {
 return jsonObject
 }
}</l></block><list><block var="jsonString"/></list></block></block></script></block-definition><block-definition s="value at key %'key' of %'lst'" type="reporter" category="operators"><header></header><code></code><translations>pt:o valor com chave _ em _
</translations><inputs><input type="%s"></input><input type="%l"></input></inputs><script><block s="doWarp"><script><block s="doForEach"><l>each item</l><block var="lst"/><script><block s="doIf"><block s="reportEquals"><block s="reportListItem"><l>1</l><block var="each item"/></block><block var="key"/></block><script><block s="doReport"><block s="reportListItem"><l>2</l><block var="each item"/></block></block></script></block></script></block></script></block><block s="doReport"><l></l></block></script></block-definition><block-definition s="%'method' url: %'url' send: %'payload' headers: %'headers'" type="reporter" category="sensing"><header></header><code></code><translations>pt:a resposta a _ de _ enviando _ e cabeçalhos _
</translations><inputs><input type="%s" readonly="true">GET<options>GET
POST
PUT
DELETE</options></input><input type="%s">https://snap.berkeley.edu</input><input type="%s"></input><input type="%mult%l" readonly="true"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>method</l><l>url</l><l>data</l><l>headers</l><l>proc</l></list><l>var response, i, header;
if (!proc.httpRequest) {
 proc.httpRequest = new XMLHttpRequest();
 proc.httpRequest.open(method, url, true);
 proc.assertType(headers, 'list');
 for (i = 1; i <= headers.length(); i += 1) {
 header = headers.at(i);
 proc.assertType(header, 'list');
 proc.httpRequest.setRequestHeader(
 header.at(1),
 header.at(2)
 );
 }
 proc.httpRequest.send(data || null);
} else if (proc.httpRequest.readyState === 4) {
 response = proc.httpRequest.responseText;
 proc.httpRequest = null;
 return response;
}
proc.pushContext('doYield');
proc.pushContext();</l></block><list><block var="method"/><block var="url"/><block var="payload"/><block var="headers"/></list></block></block></script></block-definition><block-definition s="key: %'key' value: %'value'" type="reporter" category="operators"><header></header><code></code><translations>pt:um par (chave: _ , valor: _ )
</translations><inputs><input type="%s"></input><input type="%s"></input></inputs><script><block s="doReport"><block s="reportNewList"><list><block var="key"/><block var="value"/></list></block></block></script></block-definition><block-definition s="current location" type="reporter" category="sensing"><comment x="0" y="0" w="200" collapsed="false">Reports a three-item list containing the latitude and longitude of the user, and the precision of the measurements. Works only if the user allows snap.berkeley.edu access to location data. Some browsers also require an HTTPS connection to Snap!.</comment><header></header><code></code><translations>pt:a localização actual do dispositivo
</translations><inputs></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>proc</l></list><l>if (!proc.geostarted) {
 var geo = navigator.geolocation;
 var cords = [];
 var options = {
 enableHighAccuracy: false,
 };

 function success(pos) {
 console.log(pos);
 proc.geocords = [pos.coords.latitude,
 pos.coords.longitude,
 pos.coords.accuracy];
 }

 function error(err) {
 alert("ERROR " + err.code + ": " + err.message);
 }
 proc.geostarted = true;
 proc.geocords = null;
 console.log("starting geolocation")
 geo.getCurrentPosition(success, error, options);
} else if (proc.geocords) {
 var cords = proc.geocords;
 proc.geostarted = null;
 proc.geocords = null;
 console.log("returning");
 return new List(cords);
} else {
 console.log("yielding");
 proc.pushContext('doYield');
 proc.pushContext();
}</l></block><list></list></block></block></script></block-definition></blocks> |