summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormayx <mayx@outlook.com>2025-06-19 10:51:38 +0200
committermayx <mayx@outlook.com>2025-06-19 10:51:38 +0200
commitd10e960a8d6d1b7dd122e713fa53fa190ce8498c (patch)
treec52e760dd39688275e22fb8c4a462aa79d064cd8
parent00ed1a9b506eb8bdbdfd5e2d6eb925ca492ef8bb (diff)
Update 2 files
- /assets/js/main_new.js - /_layouts/post.html
-rw-r--r--_layouts/post.html2
-rw-r--r--assets/js/main_new.js44
2 files changed, 25 insertions, 21 deletions
diff --git a/_layouts/post.html b/_layouts/post.html
index d598c2f..4769a36 100644
--- a/_layouts/post.html
+++ b/_layouts/post.html
@@ -102,7 +102,7 @@ $.get(BlogAPI + "/suggest?id={{ page.url }}&update=" + lastUpdated.valueOf(), fu
var item = searchMap[data[j].id];
if (item) {
var link = $('<a href="' + item.url + '">' + item.title + '</a>');
- var contentPreview = item.content.replace(/<[^>]+>/g, "").substring(0, 100);
+ var contentPreview = item.content.substring(0, 100);
if (item.content.length > 100) {
contentPreview += "……";
}
diff --git a/assets/js/main_new.js b/assets/js/main_new.js
index fbb6926..deb0927 100644
--- a/assets/js/main_new.js
+++ b/assets/js/main_new.js
@@ -43,31 +43,35 @@ $(function () {
});
});
-$(function () {
- var codeBlocks = document.querySelectorAll('div.highlight');
+$(function() {
+ var $codeBlocks = $('div.highlight');
- codeBlocks.forEach(function (codeBlock) {
- var copyButton = document.createElement('button');
- copyButton.className = 'copy';
- copyButton.type = 'button';
- copyButton.innerText = '📋';
+ $codeBlocks.each(function() {
+ var $copyButton = $('<button>', {
+ class: 'copy',
+ type: 'button',
+ text: '📋'
+ });
- codeBlock.append(copyButton);
+ $(this).append($copyButton);
- copyButton.addEventListener('click', function () {
- var code = codeBlock.querySelector('pre code').innerText.trim();
- window.navigator.clipboard.writeText(code)
- .then(() => {
- copyButton.innerText = '✅';
+ $copyButton.on('click', function() {
+ var code = $(this).siblings('pre').find('code').text().trim();
+ var $button = $(this);
+
+ navigator.clipboard.writeText(code)
+ .then(function() {
+ $button.text('✅');
})
- .catch(err => {
- copyButton.innerText = '❌';
- console.error('Failed to copy:', err);
+ .catch(function(err) {
+ $button.text('❌');
+ console.error('复制失败:', err);
+ })
+ .finally(function() {
+ setTimeout(function() {
+ $button.text('📋');
+ }, 1500);
});
-
- setTimeout(function () {
- copyButton.innerText = '📋';
- }, 1500);
});
});
}); \ No newline at end of file