mirror of
https://github.com/Mabbs/mabbs.github.io
synced 2025-07-19 18:42:02 +00:00
Update 2 files
- /assets/css/style.scss - /assets/js/main.js
This commit is contained in:
parent
8f440b43dd
commit
8211f6d1a2
@ -1,5 +1,5 @@
|
||||
---
|
||||
---
|
||||
---
|
||||
|
||||
@import "{{ site.theme }}";
|
||||
|
||||
@ -76,4 +76,27 @@ h6:hover .octicon {
|
||||
padding: 0;
|
||||
margin-left: -16px;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
div.highlight {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
div.highlight:hover button {
|
||||
opacity: 1
|
||||
}
|
||||
|
||||
div.highlight button {
|
||||
opacity: 0;
|
||||
position: absolute;
|
||||
top: 0.5rem;
|
||||
right: 1rem;
|
||||
height: 2em;
|
||||
transition: all 0.2s ease-out
|
||||
}
|
||||
|
||||
div.highlight button:active,
|
||||
div.highlight button:focus,
|
||||
div.highlight button:hover {
|
||||
opacity: 1
|
||||
}
|
@ -41,7 +41,7 @@ $(function () {
|
||||
}
|
||||
});
|
||||
|
||||
$(function() {
|
||||
$(function () {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const keyword = urlParams.get('kw')?.trim();
|
||||
|
||||
@ -54,7 +54,7 @@ $(function() {
|
||||
|
||||
// 递归遍历并高亮文本节点
|
||||
function highlightTextNodes(element) {
|
||||
$(element).contents().each(function() {
|
||||
$(element).contents().each(function () {
|
||||
if (this.nodeType === Node.TEXT_NODE) {
|
||||
const $this = $(this);
|
||||
const text = $this.text();
|
||||
@ -72,11 +72,38 @@ $(function() {
|
||||
});
|
||||
}
|
||||
|
||||
$('section').each(function() {
|
||||
$('section').each(function () {
|
||||
highlightTextNodes(this);
|
||||
});
|
||||
});
|
||||
|
||||
var codeBlocks = document.querySelectorAll('div.highlight');
|
||||
|
||||
codeBlocks.forEach(function (codeBlock) {
|
||||
var copyButton = document.createElement('button');
|
||||
copyButton.className = 'copy';
|
||||
copyButton.type = 'button';
|
||||
copyButton.innerText = '📋';
|
||||
|
||||
codeBlock.append(copyButton);
|
||||
|
||||
copyButton.addEventListener('click', function () {
|
||||
var code = codeBlock.querySelector('pre code').innerText.trim();
|
||||
window.navigator.clipboard.writeText(code)
|
||||
.then(() => {
|
||||
copyButton.innerText = '✅';
|
||||
})
|
||||
.catch(err => {
|
||||
copyButton.innerText = '❌';
|
||||
console.error('Failed to copy:', err);
|
||||
});
|
||||
|
||||
setTimeout(function () {
|
||||
copyButton.innerText = '📋';
|
||||
}, 1500);
|
||||
});
|
||||
});
|
||||
|
||||
today = new Date();
|
||||
timeold = (today.getTime() - lastUpdated.getTime());
|
||||
secondsold = Math.floor(timeold / 1000);
|
||||
|
Loading…
x
Reference in New Issue
Block a user