|
159 | 159 | </el-button>
|
160 | 160 | <el-dropdown-menu slot="dropdown">
|
161 | 161 | <el-dropdown-item @click.native="handleCopySub()">复制订阅链接</el-dropdown-item>
|
| 162 | + <el-dropdown-item v-if="!loading && result.length" @click.native="handleCopyAvailable()">复制可用节点</el-dropdown-item> |
162 | 163 | <el-dropdown-item v-if="multipleSelection.length" @click.native="handleCopy()">复制节点</el-dropdown-item>
|
163 | 164 | <el-dropdown-item v-if="multipleSelection.length" @click.native="handleSave()">导出节点</el-dropdown-item>
|
164 | 165 | <!-- <el-dropdown-item @click.native="handleRetest()">重新测试</el-dropdown-item> -->
|
|
463 | 464 | }
|
464 | 465 | }
|
465 | 466 | },
|
| 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 | + }, |
466 | 484 | handleCopySub: async function () {
|
467 | 485 | // url
|
468 | 486 | if (this.subscription.trim().startsWith("http") && !this.subscription.trim().endsWith("yaml")) {
|
|
492 | 510 | handleCopy: async function () {
|
493 | 511 | try {
|
494 | 512 | 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) |
510 | 514 | this.$message.success("Copy link succeed!");
|
511 | 515 | } catch (err) {
|
512 | 516 | this.$message.error("Copy link failed!");
|
513 | 517 | }
|
514 | 518 | },
|
| 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 | + }, |
515 | 528 | qrCodeHandleClose() {
|
516 | 529 | this.qrCodeDialogVisible = false;
|
517 | 530 | this.multipleSelection.forEach(item => {
|
|
0 commit comments