From a1137d659e7aa756b6e4f83a6c36f9e04653ce14 Mon Sep 17 00:00:00 2001 From: "Shishkevich D." <135337715+shishkevichd@users.noreply.github.com> Date: Thu, 6 Mar 2025 13:34:05 +0000 Subject: [PATCH] refactor: delete `clipboardjs` text copying can be done without using additional libraries --- web/assets/clipboard/clipboard.min.js | 7 ------- web/assets/js/util/common.js | 18 ++++++++++++++++++ web/html/common/qrcode_modal.html | 17 ++++++----------- web/html/common/text_modal.html | 20 +++++++------------- web/html/xui/inbound_info_modal.html | 23 +++++++++-------------- web/html/xui/inbounds.html | 1 - web/html/xui/index.html | 1 - 7 files changed, 40 insertions(+), 47 deletions(-) delete mode 100644 web/assets/clipboard/clipboard.min.js diff --git a/web/assets/clipboard/clipboard.min.js b/web/assets/clipboard/clipboard.min.js deleted file mode 100644 index 1103f811..00000000 --- a/web/assets/clipboard/clipboard.min.js +++ /dev/null @@ -1,7 +0,0 @@ -/*! - * clipboard.js v2.0.11 - * https://clipboardjs.com/ - * - * Licensed MIT © Zeno Rocha - */ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return n={686:function(t,e,n){"use strict";n.d(e,{default:function(){return b}});var e=n(279),i=n.n(e),e=n(370),u=n.n(e),e=n(817),r=n.n(e);function c(t){try{return document.execCommand(t)}catch(t){return}}var a=function(t){t=r()(t);return c("cut"),t};function o(t,e){var n,o,t=(n=t,o="rtl"===document.documentElement.getAttribute("dir"),(t=document.createElement("textarea")).style.fontSize="12pt",t.style.border="0",t.style.padding="0",t.style.margin="0",t.style.position="absolute",t.style[o?"right":"left"]="-9999px",o=window.pageYOffset||document.documentElement.scrollTop,t.style.top="".concat(o,"px"),t.setAttribute("readonly",""),t.value=n,t);return e.container.appendChild(t),e=r()(t),c("copy"),t.remove(),e}var f=function(t){var e=1 { + const textarea = document.createElement("textarea"); + + textarea.value = text; + + document.body.appendChild(textarea); + + textarea.select(); + document.execCommand("copy"); + + document.body.removeChild(textarea); + + resolve(text) + }) +} + function addZero(num) { if (num < 10) { return "0" + num; diff --git a/web/html/common/qrcode_modal.html b/web/html/common/qrcode_modal.html index 94e750c7..117dd640 100644 --- a/web/html/common/qrcode_modal.html +++ b/web/html/common/qrcode_modal.html @@ -10,7 +10,7 @@ {{ i18n "pages.settings.subSettings"}} - + @@ -18,7 +18,7 @@ {{ i18n "pages.settings.subSettings"}} Json - + @@ -27,7 +27,7 @@ [[ row.remark ]] - + @@ -41,7 +41,6 @@ dbInbound: new DBInbound(), client: null, qrcodes: [], - clipboard: null, visible: false, subId: '', show: function(title = '', dbInbound, client) { @@ -79,14 +78,10 @@ qrModal: qrModal, }, methods: { - copyToClipboard(elementId, content) { - this.qrModal.clipboard = new ClipboardJS('#' + elementId, { - text: () => content, - }); - this.qrModal.clipboard.on('success', () => { + copyToClipboard(content) { + return copyToClipboard(content).then(() => { app.$message.success('{{ i18n "copied" }}') - this.qrModal.clipboard.destroy(); - }); + }) }, setQrCode(elementId, content) { new QRious({ diff --git a/web/html/common/text_modal.html b/web/html/common/text_modal.html index d668c792..36589199 100644 --- a/web/html/common/text_modal.html +++ b/web/html/common/text_modal.html @@ -7,7 +7,7 @@ :href="'data:application/text;charset=utf-8,' + encodeURIComponent(txtModal.content)" :download="txtModal.fileName">[[ txtModal.fileName ]] - {{ i18n "copy" }} + {{ i18n "copy" }} @@ -20,24 +20,18 @@ content: '', fileName: '', qrcode: null, - clipboard: null, visible: false, show: function (title = '', content = '', fileName = '') { this.title = title; this.content = content; this.fileName = fileName; this.visible = true; - textModalApp.$nextTick(() => { - if (this.clipboard === null) { - this.clipboard = new ClipboardJS('#copy-btn', { - text: () => this.content, - }); - this.clipboard.on('success', () => { - app.$message.success('{{ i18n "copied" }}') - this.close(); - }); - } - }); + }, + copy: function (content = '') { + copyToClipboard(content).then(() => { + app.$message.success('{{ i18n "copied" }}') + this.close(); + }) }, close: function () { this.visible = false; diff --git a/web/html/xui/inbound_info_modal.html b/web/html/xui/inbound_info_modal.html index d9913f32..f95461e2 100644 --- a/web/html/xui/inbound_info_modal.html +++ b/web/html/xui/inbound_info_modal.html @@ -258,7 +258,7 @@ Subscription Link - + [[ infoModal.subLink ]] @@ -267,7 +267,7 @@ Json Link - + [[ infoModal.subJsonLink ]] @@ -279,7 +279,7 @@ [[ infoModal.clientSettings.tgId ]] - + @@ -290,7 +290,7 @@ [[ link.remark ]] - + [[ link.link ]] @@ -304,7 +304,7 @@ [[ link.remark ]] - + [[ link.link ]] @@ -431,7 +431,7 @@ Config - +
@@ -464,7 +464,6 @@ clientStats: [], upStats: 0, downStats: 0, - clipboard: null, links: [], index: null, isExpired: false, @@ -533,14 +532,10 @@ }, }, methods: { - copyToClipboard(elementId, content) { - this.infoModal.clipboard = new ClipboardJS('#' + elementId, { - text: () => content, - }); - this.infoModal.clipboard.on('success', () => { + copyToClipboard(content) { + return copyToClipboard(content).then(() => { app.$message.success('{{ i18n "copied" }}') - this.infoModal.clipboard.destroy(); - }); + }) }, statsColor(stats) { return usageColor(stats.up + stats.down, app.trafficDiff, stats.total); diff --git a/web/html/xui/inbounds.html b/web/html/xui/inbounds.html index 89a37a29..86890926 100644 --- a/web/html/xui/inbounds.html +++ b/web/html/xui/inbounds.html @@ -546,7 +546,6 @@ {{template "js" .}} - diff --git a/web/html/xui/index.html b/web/html/xui/index.html index 2e57277a..8f89da90 100644 --- a/web/html/xui/index.html +++ b/web/html/xui/index.html @@ -332,7 +332,6 @@ {{template "js" .}} - {{template "component/themeSwitcher" .}} {{template "textModal"}}