// KaiOS 2.x specific part to connect and retrieve raw data from Gopher servers // Requires "tcp-socket" permission in the manifest // and the "privileged" or "certified" app permission level // resource format: [type, selector, host, port] // type is autotrimmed, so you don't have to manually strip the description // input is optional and only considered for resource type 7 function gopherRequest(resource, input, successCb, errorCb) { var xsock = navigator.mozTCPSocket.open(resource[2], (resource[3]||70) | 0, {binaryType: 'string'}), type = resource[0][0], databuf = '' xsock.ondata = function(data) { databuf += data.data } xsock.onclose = function() { successCb(databuf, type) } xsock.onerror = errorCb xsock.onopen = function() { var selpath = resource[1] if(type == '7' && input) selpath += '\t' + input xsock.send(selpath + '\r\n') // send CRLF-terminated selector path and optionally the search string } }