diff options
| author | mayx <mayx@outlook.com> | 2026-06-30 16:00:55 +0000 |
|---|---|---|
| committer | mayx <mayx@outlook.com> | 2026-06-30 16:00:55 +0000 |
| commit | 7943cc7d6ae9214ba9e70a141bbe27fbd98a923a (patch) | |
| tree | 934b13ae191b00bc74ad33ee2c42490f591ae308 /assets/js/main.js | |
| parent | 772e3ed0b70dffe303ebacb5680ee9650efe3c76 (diff) | |
- /_data/other_repo_list.csv
- /index.html
- /_posts/2026-07-01-vibe-coding.md
- /assets/js/main_new.js
- /assets/js/main.js
Diffstat (limited to 'assets/js/main.js')
| -rw-r--r-- | assets/js/main.js | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/assets/js/main.js b/assets/js/main.js index e926618..ed21874 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -17,6 +17,25 @@ function initVisitors() { } } +function highlightKeyword() { + var match = location.search.match(/[?&]kw=([^&]+)/); + var kw = match ? $.trim(decodeURIComponent(match[1].replace(/\+/g, ' '))) : ''; + if (!kw) return; + + var reg = new RegExp('(' + kw.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', 'gi'); + var escapeMap = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }; + + $('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); + } + }); +} + $(function () { (function () { var $backToTopTxt = "返回顶部", $backToTopEle = $('<div class="backToTop"></div>').appendTo($("body")) @@ -42,6 +61,7 @@ $(function () { }); console.warn("Mayx may already be Dead"); } + highlightKeyword(); }); function getSearchJSON(callback) { |
