From f50e2c10583f6ff43fed2ea2ce6b9be5c7f74d76 Mon Sep 17 00:00:00 2001 From: jason5ng32 Date: Thu, 14 Dec 2023 10:37:32 +0800 Subject: [PATCH] Add copy to clipboard --- public/index.html | 8 +++----- public/res/app.js | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/public/index.html b/public/index.html index 1b50ddfc..12f17484 100644 --- a/public/index.html +++ b/public/index.html @@ -136,11 +136,6 @@

🕵️ - - - Map
@@ -148,6 +143,9 @@

🕵️
  • 🖥️ {{currentTexts.ipInfos.IP}}: {{ card.ip }} +
  • diff --git a/public/res/app.js b/public/res/app.js index 57051004..32621253 100644 --- a/public/res/app.js +++ b/public/res/app.js @@ -52,6 +52,7 @@ new Vue({ infoMaskLevel: 0, ipDataCache: new Map(), speedTestStatus: "idle", + copiedStatus: {}, // from contents connectivityTests, @@ -193,10 +194,10 @@ new Vue({ const asnlink = data.asn ? `https://radar.cloudflare.com/traffic/${data.asn}` : false; - const mapUrl = + const mapUrl = data.latitude && data.longitude ? `/api/map?latitude=${data.latitude}&longitude=${data.longitude}&language=${this.bingMapLanguage}` - : ""; + : ""; // 更新卡片数据 const cardData = { @@ -807,7 +808,7 @@ new Vue({ this.isMapShown = false; }); }, - + // PWA 颜色 PWAColor() { if (this.isDarkMode) { @@ -1021,6 +1022,21 @@ new Vue({ this.startSpeedTest(); } }, + // 复制 IP 地址 + copyToClipboard(ip, id) { + navigator.clipboard.writeText(ip).then(() => { + this.$set(this.copiedStatus, id, true); + // 设置定时器在 5 秒后重置状态 + setTimeout(() => { + this.$set(this.copiedStatus, id, false); + }, 5000); + }).catch(err => { + console.error('Copy error', err); + }); + }, + isValidIP(ip) { + return /^[a-zA-Z0-9:.\/]+$/.test(ip); + }, }, created() {