Skip to content

Commit 25dd154

Browse files
committed
复制可用节点
1 parent 0a6b988 commit 25dd154

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

web/index.html

+28-15
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
</el-button>
160160
<el-dropdown-menu slot="dropdown">
161161
<el-dropdown-item @click.native="handleCopySub()">复制订阅链接</el-dropdown-item>
162+
<el-dropdown-item v-if="!loading && result.length" @click.native="handleCopyAvailable()">复制可用节点</el-dropdown-item>
162163
<el-dropdown-item v-if="multipleSelection.length" @click.native="handleCopy()">复制节点</el-dropdown-item>
163164
<el-dropdown-item v-if="multipleSelection.length" @click.native="handleSave()">导出节点</el-dropdown-item>
164165
<!-- <el-dropdown-item @click.native="handleRetest()">重新测试</el-dropdown-item> -->
@@ -463,6 +464,23 @@
463464
}
464465
}
465466
},
467+
copyToClipboard: async function (data) {
468+
if (navigator.clipboard) {
469+
await navigator.clipboard.writeText(data)
470+
} else {
471+
let textArea = document.createElement("textarea");
472+
textArea.value = data;
473+
// make the textarea out of viewport
474+
textArea.style.position = "fixed";
475+
textArea.style.left = "-999999px";
476+
textArea.style.top = "-999999px";
477+
document.body.appendChild(textArea);
478+
textArea.focus();
479+
textArea.select();
480+
document.execCommand('copy');
481+
textArea.remove();
482+
}
483+
},
466484
handleCopySub: async function () {
467485
// url
468486
if (this.subscription.trim().startsWith("http") && !this.subscription.trim().endsWith("yaml")) {
@@ -492,26 +510,21 @@
492510
handleCopy: async function () {
493511
try {
494512
links = this.multipleSelection.map(elem => elem.link).join("\n")
495-
if (navigator.clipboard) {
496-
await navigator.clipboard.writeText(links)
497-
} else {
498-
let textArea = document.createElement("textarea");
499-
textArea.value = links;
500-
// make the textarea out of viewport
501-
textArea.style.position = "fixed";
502-
textArea.style.left = "-999999px";
503-
textArea.style.top = "-999999px";
504-
document.body.appendChild(textArea);
505-
textArea.focus();
506-
textArea.select();
507-
document.execCommand('copy');
508-
textArea.remove();
509-
}
513+
await this.copyToClipboard(links)
510514
this.$message.success("Copy link succeed!");
511515
} catch (err) {
512516
this.$message.error("Copy link failed!");
513517
}
514518
},
519+
handleCopyAvailable: async function () {
520+
try {
521+
links = this.result.filter(elem => elem.ping > 0).map(elem => elem.link)
522+
await this.copyToClipboard(links.join("\n"))
523+
this.$message.success(`Copy ${links.length} link${links.length>1 ? "s" : ""} succeed!`);
524+
} catch (err) {
525+
this.$message.error("Copy link failed!");
526+
}
527+
},
515528
qrCodeHandleClose() {
516529
this.qrCodeDialogVisible = false;
517530
this.multipleSelection.forEach(item => {

0 commit comments

Comments
 (0)