diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index ae3b52fc..7b0903fc 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -462,6 +462,9 @@ "settingsAddServerButton": { "message": "Add Server" }, + "settingsAddActiveSubscriptionProxyServerButton": { + "message": "Add to My Servers" + }, "settingsRemoveMultipleServerButton": { "message": "Delete Multiple" }, diff --git a/src/ui/code/settingsPage.ts b/src/ui/code/settingsPage.ts index af3707c8..7a6917c5 100644 --- a/src/ui/code/settingsPage.ts +++ b/src/ui/code/settingsPage.ts @@ -207,6 +207,8 @@ export class settingsPage { jq("#btnAddProxyServer").click(settingsPage.uiEvents.onClickAddProxyServer); + jq("#btnAddActiveSubscriptionProxyServerToMyServers").click(settingsPage.uiEvents.onClickAddActiveSubscriptionProxyServerToMyServers); + jq("#btnRemoveMultipleProxyServer").click(settingsPage.uiEvents.onClickRemoveMultipleProxyServer); jq("#cmdServerProtocol").on("change", settingsPage.uiEvents.onChangeServerProtocol); @@ -1201,6 +1203,7 @@ export class settingsPage { // populate this.populateProxyServersToComboBox(cmbActiveProxyServer, defaultProxyServerId, proxyServers, serverSubscriptions); + this.updateActiveSubscriptionProxyServerAction(); } private static readServers(): ProxyServer[] { @@ -1318,6 +1321,35 @@ export class settingsPage { return null; } + private static findProxyServerSubscriptionByProxyServerId(proxyServerId: string): ProxyServerSubscription | null { + if (!proxyServerId) + return null; + + let serverSubscriptions = settingsPage.readServerSubscriptions(); + for (let subscription of serverSubscriptions) { + if (!subscription.enabled || !subscription.proxies) + continue; + + let proxy = subscription.proxies.find(item => item.id === proxyServerId); + if (proxy !== undefined) + return subscription; + } + return null; + } + + private static updateActiveSubscriptionProxyServerAction() { + let proxyServerId = jq("#cmbActiveProxyServer").val() as string; + let subscription = settingsPage.findProxyServerSubscriptionByProxyServerId(proxyServerId); + let button = jq("#btnAddActiveSubscriptionProxyServerToMyServers"); + + if (subscription) { + button.removeClass("d-none"); + } + else { + button.addClass("d-none"); + } + } + private static exportServersListFormatted(): string { let proxyList = settingsPage.readServers(); let result = `[SmartProxy Servers]\r\n`; @@ -2640,6 +2672,7 @@ export class settingsPage { else { Debug.warn("Settings> Selected ActiveProxyServer ID not found!"); } + settingsPage.updateActiveSubscriptionProxyServerAction(); }, onClickAddProxyServer() { @@ -2651,6 +2684,29 @@ export class settingsPage { modal.modal("show"); modal.find("#txtServerAddress").focus(); }, + onClickAddActiveSubscriptionProxyServerToMyServers() { + let proxyServerId = jq("#cmbActiveProxyServer").val() as string; + let subscription = settingsPage.findProxyServerSubscriptionByProxyServerId(proxyServerId); + if (!subscription || !subscription.proxies) + return; + + let server = subscription.proxies.find(item => item.id === proxyServerId); + if (!server) + return; + + let modal = jq("#modalModifyProxyServer"); + modal.data("editing", null); + + let serverToAdd = new ProxyServer(); + jQuery.extend(serverToAdd, server); + serverToAdd.order = settingsPage.readServers().reduce((order, item) => Math.max(order, item.order || 0), 0) + 1; + serverToAdd.name = settingsPage.generateNewServerName(subscription.name); + + settingsPage.populateServerModal(modal, serverToAdd); + + modal.modal("show"); + modal.find("#txtServerAddress").focus(); + }, onClickRemoveMultipleProxyServer() { var rows = settingsPage.grdServers.rows({ selected: true }); if (!rows) @@ -4367,17 +4423,17 @@ export class settingsPage { //#endregion //#region Common functions --------------- - private static generateNewServerName(): string { + private static generateNewServerName(prefix: string = "Server"): string { // generates a unique name for proxy server let servers = this.readServers(); let serverNo = 1; - let result = `Server ${serverNo}`; + let result = `${prefix} ${serverNo}`; if (servers && servers.length > 0) { let exist; serverNo = servers.length + 1; - result = `Server ${serverNo}`; + result = `${prefix} ${serverNo}`; do { exist = false; @@ -4385,7 +4441,7 @@ export class settingsPage { if (servers[i].name === result) { exist = true; serverNo++; - result = `Server ${serverNo}`; + result = `${prefix} ${serverNo}`; break; } } diff --git a/src/ui/settings.html b/src/ui/settings.html index ac18f691..403b1827 100644 --- a/src/ui/settings.html +++ b/src/ui/settings.html @@ -599,6 +599,10 @@