(markdown)
| 575 | } |
| 576 | // 预览 |
| 577 | function showMarkdownModal(markdown) { |
| 578 | var $modal = $(` |
| 579 | <div class="h2m-modal-overlay"> |
| 580 | <div class="h2m-modal"> |
| 581 | <textarea>${markdown}</textarea> |
| 582 | <div class="h2m-preview">${marked.parse(markdown)}</div> |
| 583 | <div class="h2m-buttons"> |
| 584 | <button class="h2m-copy">${translate.copy}</button> |
| 585 | <button class="h2m-download">${translate.download_md}</button> |
| 586 | <button class="h2m-github">${translate.send_to_github}</button> |
| 587 | <select class="h2m-obsidian-select">${translate.send_to_obsidian}</select> |
| 588 | </div> |
| 589 | <button class="h2m-close">X</button> |
| 590 | </div> |
| 591 | </div> |
| 592 | `) |
| 593 | |
| 594 | $modal.find('.h2m-obsidian-select').append($('<option>').val('').text(`${translate.send_to_obsidian}`)) |
| 595 | for (const vault in obsidianConfig) { |
| 596 | for (const path of obsidianConfig[vault]) { |
| 597 | // 插入元素 |
| 598 | const $option = $('<option>') |
| 599 | .val(`obsidian://advanced-uri?vault=${vault}&filepath=${path}`) |
| 600 | .text(`${vault}: ${path}`) |
| 601 | $modal.find('.h2m-obsidian-select').append($option) |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | $modal.find('textarea').on('input', function () { |
| 606 | // console.log("Input event triggered"); |
| 607 | var markdown = $(this).val() |
| 608 | var html = marked.parse(markdown) |
| 609 | // console.log("Markdown:", markdown); |
| 610 | // console.log("HTML:", html); |
| 611 | $modal.find('.h2m-preview').html(html) |
| 612 | }) |
| 613 | |
| 614 | $modal.on('keydown', function (e) { |
| 615 | if (e.key === 'Escape') { |
| 616 | $modal.remove() |
| 617 | } |
| 618 | }) |
| 619 | |
| 620 | $modal.find('.h2m-copy').on('click', function () { // 复制到剪贴板 |
| 621 | GM_setClipboard($modal.find('textarea').val()) |
| 622 | $modal.find('.h2m-copy').text(`${translate.copied}`) |
| 623 | setTimeout(() => { |
| 624 | $modal.find('.h2m-copy').text(`${translate.copy}`) |
| 625 | }, 1000) |
| 626 | }) |
| 627 | $modal.find('.h2m-github').on('click', function () { |
| 628 | const github_token = GM_getValue('github_token', '') |
| 629 | const github_owner = GM_getValue('OWNER', '') |
| 630 | const github_repo = GM_getValue('REPO', '') |
| 631 | |
| 632 | if (!github_token || !github_owner || !github_repo) { |
| 633 | showConfig() |
| 634 | return |
no test coverage detected