2026-05-27 02:37:23 +00:00
|
|
|
function highlightKeyword() {
|
2026-06-01 05:36:14 +00:00
|
|
|
var match = location.search.match(/[?&]kw=([^&]+)/);
|
|
|
|
|
var kw = match ? $.trim(decodeURIComponent(match[1].replace(/\+/g, ' '))) : '';
|
|
|
|
|
if (!kw) return;
|
2025-05-11 16:12:22 +00:00
|
|
|
|
2026-06-01 05:36:14 +00:00
|
|
|
var reg = new RegExp('(' + kw.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', 'gi');
|
|
|
|
|
var escapeMap = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
2025-05-11 16:12:22 +00:00
|
|
|
|
2026-06-01 05:36:14 +00:00
|
|
|
$('section, section *').not('script, style, textarea').contents().filter(function() {
|
|
|
|
|
return this.nodeType === 3;
|
|
|
|
|
}).each(function() {
|
|
|
|
|
var escapedText = this.nodeValue.replace(/[&<>"']/g, function(m) { return escapeMap[m]; });
|
|
|
|
|
var highlighted = escapedText.replace(reg, '<mark>$1</mark>');
|
|
|
|
|
if (escapedText !== highlighted) {
|
|
|
|
|
$(this).replaceWith(highlighted);
|
|
|
|
|
}
|
2025-05-11 16:12:22 +00:00
|
|
|
});
|
2026-06-01 05:36:14 +00:00
|
|
|
}
|
2025-05-11 16:12:22 +00:00
|
|
|
|
2026-05-23 10:06:55 +00:00
|
|
|
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();
|
2025-06-19 08:51:38 +00:00
|
|
|
navigator.clipboard.writeText(code)
|
2026-05-23 10:06:55 +00:00
|
|
|
.then(function () { $btn.text('✅'); })
|
|
|
|
|
.catch(function () { $btn.text('❌'); })
|
|
|
|
|
.finally(function () { setTimeout(function () { $btn.text('📋'); }, 1500); });
|
2025-05-11 16:12:22 +00:00
|
|
|
});
|
|
|
|
|
});
|
2026-05-23 10:06:55 +00:00
|
|
|
}
|
|
|
|
|
|
2026-05-27 02:37:23 +00:00
|
|
|
$(function () {
|
|
|
|
|
highlightKeyword();
|
2026-05-23 10:06:55 +00:00
|
|
|
initCopyButtons();
|
2025-05-11 16:12:22 +00:00
|
|
|
});
|