diff options
| author | mayx <mayx@outlook.com> | 2026-05-23 10:06:55 +0000 |
|---|---|---|
| committer | mayx <mayx@outlook.com> | 2026-05-23 10:06:55 +0000 |
| commit | 481df19596b14612a5b1bc358d9514c8d4b490bb (patch) | |
| tree | 125869a62f96c41edd8a0e7f6892ac7abb8e6edd /assets/js/main_new.js | |
| parent | 1a529143a833b22fb2e2600498f6703c2edd9a84 (diff) | |
- /_layouts/default.html
- /_data/proxylist.yml
- /assets/js/main.js
- /assets/js/pjax.js
- /assets/js/main_new.js
Diffstat (limited to 'assets/js/main_new.js')
| -rw-r--r-- | assets/js/main_new.js | 42 |
1 files changed, 14 insertions, 28 deletions
diff --git a/assets/js/main_new.js b/assets/js/main_new.js index deb0927..22f2552 100644 --- a/assets/js/main_new.js +++ b/assets/js/main_new.js @@ -43,35 +43,21 @@ $(function () { }); }); -$(function() { - var $codeBlocks = $('div.highlight'); - - $codeBlocks.each(function() { - var $copyButton = $('<button>', { - class: 'copy', - type: 'button', - text: '📋' - }); - - $(this).append($copyButton); - - $copyButton.on('click', function() { - var code = $(this).siblings('pre').find('code').text().trim(); - var $button = $(this); - +function initCopyButtons() { + $('.copy').remove(); + $('div.highlight').each(function () { + var $btn = $('<button>', { class: 'copy', type: 'button', text: '📋' }); + $(this).append($btn); + $btn.on('click', function () { + var code = $btn.siblings('pre').find('code').text().trim(); navigator.clipboard.writeText(code) - .then(function() { - $button.text('✅'); - }) - .catch(function(err) { - $button.text('❌'); - console.error('复制失败:', err); - }) - .finally(function() { - setTimeout(function() { - $button.text('📋'); - }, 1500); - }); + .then(function () { $btn.text('✅'); }) + .catch(function () { $btn.text('❌'); }) + .finally(function () { setTimeout(function () { $btn.text('📋'); }, 1500); }); }); }); +} + +$(function() { + initCopyButtons(); });
\ No newline at end of file |
