summaryrefslogtreecommitdiffhomepage
path: root/applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/view/shadowsocks-libev/servers.js
diff options
context:
space:
mode:
authorRichard Yu <yurichard3839@gmail.com>2019-11-09 23:43:00 +0800
committerYousong Zhou <yszhou4tech@gmail.com>2019-11-15 19:03:34 +0800
commitdc26e2d037504f3fcd3ce1947770fbce92d48241 (patch)
tree8bbb861df4c7191e97a7308829e6b028fa081eba /applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/view/shadowsocks-libev/servers.js
parentc1f41f2919f079b82782c2ef282c834b60106621 (diff)
luci-app-shadowsocks-libev: add server links import feature
Signed-off-by: Richard Yu <yurichard3839@gmail.com>
Diffstat (limited to 'applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/view/shadowsocks-libev/servers.js')
-rw-r--r--applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/view/shadowsocks-libev/servers.js54
1 files changed, 49 insertions, 5 deletions
diff --git a/applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/view/shadowsocks-libev/servers.js b/applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/view/shadowsocks-libev/servers.js
index d46bfb0aa7..5951e92e51 100644
--- a/applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/view/shadowsocks-libev/servers.js
+++ b/applications/luci-app-shadowsocks-libev/htdocs/luci-static/resources/view/shadowsocks-libev/servers.js
@@ -1,21 +1,65 @@
'use strict';
'require form';
+'require uci';
+'require ui';
'require shadowsocks-libev as ss';
-function startsWith(str, search) {
- return str.substring(0, search.length) === search;
-}
+var conf = 'shadowsocks-libev';
return L.view.extend({
render: function() {
var m, s, o;
- m = new form.Map('shadowsocks-libev', _('Remote Servers'),
+ m = new form.Map(conf, _('Remote Servers'),
_('Definition of remote shadowsocks servers. \
Disable any of them will also disable instances referring to it.'));
s = m.section(form.GridSection, 'server');
s.addremove = true;
+ s.handleLinkImport = function() {
+ var textarea = new ui.Textarea();
+ ui.showModal(_('Import Links'), [
+ textarea.render(),
+ E('div', { class: 'right' }, [
+ E('button', {
+ class: 'btn',
+ click: ui.hideModal
+ }, [ _('Cancel') ]),
+ ' ',
+ E('button', {
+ class: 'btn cbi-button-action',
+ click: ui.createHandlerFn(this, function() {
+ textarea.getValue().split('\n').forEach(function(s) {
+ var config = ss.parse_uri(s);
+ if (config) {
+ var tag = config[1];
+ if (tag && !tag.match(/^[a-zA-Z0-9_]+$/)) tag = null;
+ var sid = uci.add(conf, 'server', tag);
+ config = config[0];
+ Object.keys(config).forEach(function(k) {
+ uci.set(conf, sid, k, config[k]);
+ });
+ }
+ });
+ return uci.save()
+ .then(L.bind(this.map.load, this.map))
+ .then(L.bind(this.map.reset, this.map))
+ .then(L.ui.hideModal)
+ .catch(function() {});
+ })
+ }, [ _('Import') ])
+ ])
+ ]);
+ };
+ s.renderSectionAdd = function(extra_class) {
+ var el = form.GridSection.prototype.renderSectionAdd.apply(this, arguments);
+ el.appendChild(E('button', {
+ 'class': 'cbi-button cbi-button-add',
+ 'title': _('Import Links'),
+ 'click': ui.createHandlerFn(this, 'handleLinkImport')
+ }, [ _('Import Links') ]));
+ return el;
+ };
o = s.option(form.Flag, 'disabled', _('Disable'));
o.editable = true;
@@ -26,7 +70,7 @@ return L.view.extend({
},
addFooter: function() {
var p = '#edit=';
- if (startsWith(location.hash, p)) {
+ if (location.hash.indexOf(p) === 0) {
var section_id = location.hash.substring(p.length);
var editBtn = document.querySelector('#cbi-shadowsocks-libev-' + section_id + ' button.cbi-button-edit');
if (editBtn)