mirror of
https://github.com/obsqrbtz/goose-highlighter.git
synced 2026-04-09 04:29:09 +03:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ef21d0975 | ||
| ae1cf48c53 | |||
| bca37e690f |
@@ -1,3 +1,10 @@
|
||||
## [1.7.1](https://github.com/obsqrbtz/goose-highlighter/compare/v1.7.0...v1.7.1) (2025-06-27)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* unicode support in regex ([ae1cf48](https://github.com/obsqrbtz/goose-highlighter/commit/ae1cf48c53cd42e65279cf2acde1a2860d8a31ee))
|
||||
|
||||
# [1.7.0](https://github.com/obsqrbtz/goose-highlighter/compare/v1.6.0...v1.7.0) (2025-06-26)
|
||||
|
||||
|
||||
|
||||
27
main.js
27
main.js
@@ -60,29 +60,38 @@ function processNodes() {
|
||||
}
|
||||
}
|
||||
|
||||
if (activeWords.length > 0) {
|
||||
if (activeWords.length > 0) {
|
||||
const wordMap = new Map();
|
||||
for (const word of activeWords) wordMap.set(word.text.toLowerCase(), word);
|
||||
|
||||
let flags = matchCase ? 'g' : 'gi';
|
||||
let wordsPattern = Array.from(wordMap.keys()).map(escapeRegex).join('|');
|
||||
if (matchWhole) {
|
||||
wordsPattern = `\\b(?:${wordsPattern})\\b`;
|
||||
for (const word of activeWords) {
|
||||
wordMap.set(matchCase ? word.text : word.text.toLowerCase(), word);
|
||||
}
|
||||
|
||||
let flags = matchCase ? 'gu' : 'giu';
|
||||
let wordsPattern = Array.from(wordMap.keys()).map(escapeRegex).join('|');
|
||||
|
||||
if (matchWhole) {
|
||||
wordsPattern = `(?:(?<!\\p{L})|^)(${wordsPattern})(?:(?!\\p{L})|$)`;
|
||||
}
|
||||
|
||||
try {
|
||||
const pattern = new RegExp(`(${wordsPattern})`, flags);
|
||||
|
||||
for (const node of textNodes) {
|
||||
if (!pattern.test(node.nodeValue)) continue;
|
||||
if (!node.nodeValue || !pattern.test(node.nodeValue)) continue;
|
||||
|
||||
const span = document.createElement('span');
|
||||
span.innerHTML = node.nodeValue.replace(pattern, match => {
|
||||
const word = wordMap.get(match.toLowerCase()) || { background: '#ffff00', foreground: '#000000' };
|
||||
const lookup = matchCase ? match : match.toLowerCase();
|
||||
const word = wordMap.get(lookup) || { background: '#ffff00', foreground: '#000000' };
|
||||
return `<mark data-gh style="background:${word.background};color:${word.foreground};padding:0 2px;">${match}</mark>`;
|
||||
});
|
||||
|
||||
node.parentNode.replaceChild(span, node);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Regex error:", e);
|
||||
}
|
||||
}
|
||||
|
||||
observer.observe(document.body, {
|
||||
childList: true,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"manifest_version": 3,
|
||||
"name": "__MSG_extension_name__",
|
||||
"description": "__MSG_extension_description__",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.1",
|
||||
"default_locale": "en",
|
||||
"permissions": [
|
||||
"scripting",
|
||||
|
||||
Reference in New Issue
Block a user