webssh

Web based ssh client https://github.com/huashengdun/webssh webssh.huashengdun.org/
git clone http://git.hanabi.in/repos/webssh.git
Log | Files | Refs | README | LICENSE

commit 5d1d5e9250c4d2d955db4ab3258f7eb077e731f6
parent 2b57122925fd491c5894e54987ce5de4f3c422eb
Author: Sheng <webmaster0115@gmail.com>
Date:   Thu, 13 Sep 2018 16:29:44 +0800

Support browser edge

Diffstat:
Mwebssh/static/js/main.js | 81++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 74 insertions(+), 7 deletions(-)

diff --git a/webssh/static/js/main.js b/webssh/static/js/main.js @@ -4,6 +4,37 @@ var jQuery; var wssh = {}; +(function() { + // For FormData without getter and setter + var proto = FormData.prototype; + proto.data = {}; + + if (!proto.get) { + proto.get = function (name) { + if (!proto.data[name]) { + var input = document.querySelector('input[name="' + name + '"]'), + value; + if (input) { + if (input.type === 'file') { + value = input.files[0]; + } else { + value = input.value; + } + proto.data[name] = value; + } + } + return proto.data[name]; + }; + } + + if (!proto.set) { + proto.set = function (name, value) { + proto.data[name] = value; + }; + } +}()); + + jQuery(function($){ var status = $('#status'), btn = $('.btn-primary'), @@ -73,7 +104,7 @@ jQuery(function($){ } - function read_file_as_text(file, callback, decoder) { + function read_as_text_with_decoder(file, callback, decoder) { var reader = new window.FileReader(); if (decoder === undefined) { @@ -101,6 +132,36 @@ jQuery(function($){ } + function read_as_text_with_encoding(file, callback, encoding) { + var reader = new window.FileReader(); + + if (encoding === undefined) { + encoding = 'utf-8'; + } + + reader.onload = function() { + if (callback) { + callback(reader.result); + } + }; + + reader.onerror = function (e) { + console.error(e); + }; + + reader.readAsText(file, encoding); + } + + + function read_file_as_text(file, callback, decoder) { + if (!window.TextDecoder) { + read_as_text_with_encoding(file, callback, decoder); + } else { + read_as_text_with_decoder(file, callback, decoder); + } + } + + function reset_wssh() { var name; @@ -139,7 +200,7 @@ jQuery(function($){ url = ws_url + join + 'ws?id=' + msg.id, sock = new window.WebSocket(url), encoding = 'utf-8', - decoder = new window.TextDecoder('utf-8'), + decoder = window.TextDecoder ? new window.TextDecoder(encoding) : encoding, terminal = document.getElementById('#terminal'), term = new window.Terminal({ cursorBlink: true, @@ -175,12 +236,18 @@ jQuery(function($){ return; } - try { - decoder = new window.TextDecoder(new_encoding); - encoding = decoder.encoding; + if (!window.TextDecoder) { + decoder = new_encoding; + encoding = decoder; console.log('Set encoding to ' + encoding); - } catch (RangeError) { - console.log('Unknown encoding ' + new_encoding); + } else { + try { + decoder = new window.TextDecoder(new_encoding); + encoding = decoder.encoding; + console.log('Set encoding to ' + encoding); + } catch (RangeError) { + console.log('Unknown encoding ' + new_encoding); + } } }