mirror of
https://github.com/Mabbs/mabbs.github.io
synced 2025-07-21 11:42:02 +00:00
Update 2 files
- /assets/css/style.scss - /assets/js/main.js
This commit is contained in:
parent
8f440b43dd
commit
8211f6d1a2
@ -77,3 +77,26 @@ h6:hover .octicon {
|
|||||||
margin-left: -16px;
|
margin-left: -16px;
|
||||||
vertical-align: middle;
|
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 urlParams = new URLSearchParams(window.location.search);
|
||||||
const keyword = urlParams.get('kw')?.trim();
|
const keyword = urlParams.get('kw')?.trim();
|
||||||
|
|
||||||
@ -54,7 +54,7 @@ $(function() {
|
|||||||
|
|
||||||
// 递归遍历并高亮文本节点
|
// 递归遍历并高亮文本节点
|
||||||
function highlightTextNodes(element) {
|
function highlightTextNodes(element) {
|
||||||
$(element).contents().each(function() {
|
$(element).contents().each(function () {
|
||||||
if (this.nodeType === Node.TEXT_NODE) {
|
if (this.nodeType === Node.TEXT_NODE) {
|
||||||
const $this = $(this);
|
const $this = $(this);
|
||||||
const text = $this.text();
|
const text = $this.text();
|
||||||
@ -72,11 +72,38 @@ $(function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$('section').each(function() {
|
$('section').each(function () {
|
||||||
highlightTextNodes(this);
|
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();
|
today = new Date();
|
||||||
timeold = (today.getTime() - lastUpdated.getTime());
|
timeold = (today.getTime() - lastUpdated.getTime());
|
||||||
secondsold = Math.floor(timeold / 1000);
|
secondsold = Math.floor(timeold / 1000);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user